Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Danger.location() function #2968

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/pink-humans-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@quri/squiggle-lang": patch
---

Added `Danger.location()` function
44 changes: 43 additions & 1 deletion packages/squiggle-lang/src/fr/danger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
frAny,
frArray,
frDate,
frDict,
frLambda,
frNamed,
frNumber,
Expand Down Expand Up @@ -554,17 +555,58 @@ Note: The Poisson distribution is a discrete distribution. When representing thi
],
}),
];
const otherLibrary: FRFunction[] = [
maker.make({
name: "location",
displaySection: "Other",
description:
"Returns a dictionary describing the location in source code where this function was called.",
definitions: [
makeDefinition(
[],
frDict(
["source", frString],
[
"start",
frDict(
["line", frNumber],
["column", frNumber],
["offset", frNumber]
),
],
[
"end",
frDict(
["line", frNumber],
["column", frNumber],
["offset", frNumber]
),
]
),
(_, { frameStack }) => {
const location = frameStack.getTopFrame()?.location;
if (!location) {
throw new REOther("Location is missing in call stack");
}
return location;
}
),
],
}),
];

export const library = [
// Combinatorics
...combinatoricsLibrary,

// // Integration
// Integration
...integrationLibrary,

// Diminishing marginal return functions
...diminishingReturnsLibrary,

// previously called `scaleLog`/`scaleExp`/...
...mapYLibrary,

...otherLibrary,
];
Loading