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

Adds Calculator.make(fn) call #2660

Merged
merged 4 commits into from Dec 6, 2023
Merged

Adds Calculator.make(fn) call #2660

merged 4 commits into from Dec 6, 2023

Conversation

OAGr
Copy link
Contributor

@OAGr OAGr commented Dec 5, 2023

A quick way to turn functions into calculators, for testing. Will be more useful with Tags, soon.

@OAGr OAGr requested a review from berekuk as a code owner December 5, 2023 03:23
Copy link

changeset-bot bot commented Dec 5, 2023

🦋 Changeset detected

Latest commit: 0963778

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@quri/squiggle-lang Patch
@quri/squiggle-components Patch
@quri/prettier-plugin-squiggle Patch
vscode-squiggle Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Dec 5, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
quri-hub ✅ Ready (Inspect) Visit Preview Dec 6, 2023 4:37am
squiggle-components ✅ Ready (Inspect) Visit Preview Dec 6, 2023 4:37am
squiggle-website ✅ Ready (Inspect) Visit Preview Dec 6, 2023 4:37am
1 Ignored Deployment
Name Status Preview Updated (UTC)
quri-ui ⬜️ Ignored (Inspect) Visit Preview Dec 6, 2023 4:37am

Copy link
Contributor

sweep-ai bot commented Dec 5, 2023

Apply Sweep Rules to your PR?

  • Apply: All docstrings and comments should be up to date.
  • Apply: Ensure that all variables and functions have descriptive names.
  • Apply: Avoid using unnecessary separators or extra characters in code.
  • Apply: Use consistent indentation and spacing throughout the code.
  • Apply: Ensure that all code is properly formatted and follows the style guide.
  • Apply: Avoid using magic numbers or hard-coded values in the code.

Copy link

codecov bot commented Dec 5, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (7054a1c) 71.77% compared to head (0963778) 71.65%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2660      +/-   ##
==========================================
- Coverage   71.77%   71.65%   -0.13%     
==========================================
  Files         115      115              
  Lines        6207     6219      +12     
  Branches     1220     1222       +2     
==========================================
+ Hits         4455     4456       +1     
- Misses       1744     1755      +11     
  Partials        8        8              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

name: `Input ${i + 1}`,
type: sig.getName() === "Bool" ? "checkbox" : "text",
})),
sampleCount: 10000,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, why? Shouldn't this be inherited from environment, like in user-defined lambdas?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted this to be a bit higher than normal, because these are probably fairly small (just one function).

That said, as I think about it, maybe it could be a very expensive function. Can change.

@@ -193,6 +207,20 @@ export class BuiltinLambda extends BaseLambda {
}
throw new REOther(showNameMatchDefinitions());
}

toCalculator(): Calculator {
const longestSignature = maxBy(this.signatures(), (s) => s.length) || [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reasonable heuristic, but it could cause some frustration if the longest signature is not the most natural one.

Brainstorming other, more general approaches:

  1. Calculator.make(fn) -> Calculator[] (return all possible versions)
  2. Calculator.make(fn.definitions[i]) -> Calculator, where fn.definitions[i] returns a specialized function with a single signature (but this is awkward because it means that fn.definitions[3][0][0][0][0][0] should be allowed)
  3. Calculator.make(fn, 3) -> Calculator (same as Calculator.make(fn)[3] in (1) above)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the ideas, but I don't think I'm a fan of those.

  1. This could be messy, especially if there are many definitions (you'll get 3-10 on some items). I'd expect it to surprise users.
  2. Agreed it's awkward. Slow to type out.
  3. Also seems weird, especially as the order of definitions might be a bit chaotic.

One nice thing is that this issue should only come into play for builtin functions - users functions only have one definition.

My guess is that we should leave for now. However, here are some options for later:

  1. Maybe, if there are multiple definitions, then if you try Calculator.make() without any definitions, it shows you an error, but gives you a list of definitions as strings. You then can plug them in as, Calculator.make(defString).

  2. We output a Dict, where keys have to do with the definitions somehow.

  3. We output a small dropdown menu of definitions, after which the correct form will appear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

2 participants