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

Interpret result-less blocks as dicts #3490

Open
berekuk opened this issue Jan 7, 2025 · 1 comment
Open

Interpret result-less blocks as dicts #3490

berekuk opened this issue Jan 7, 2025 · 1 comment
Labels
Language Regarding Squiggle language semantics, distributions and function registry stage:proposal A proposal that warrants discussion whether we want to implement it

Comments

@berekuk
Copy link
Collaborator

berekuk commented Jan 7, 2025

This is my old proposal that I want to raise again; we could interpret this code:

d = {
  foo = 5
  bar = 6
}

As this:

d = {
  foo = 5
  bar = 6
  { foo, bar, }
}

Rationale

AI

Squiggle AI has the tendency to write code like this:
Image

Probably because of our own style guide.

Tagging dict entries

We can implement decorators on dict entries in their original form, but there might be possible negative consequences.

When parsing, we should attempt to resolve ambiguity as quickly as possible, and the situation like this:

d = {
  @name(...)
  @showAs(...)
  key

is ambiguous until the parser encounters the next symbols and sees if it's : or =.

This is probably not a big issue, but I'm not 100% sure.

Supporting tags only for block-style dicts, on the other hand, doesn't require any new syntactic features.

Debugging

Imagine you're working on this function:

f(x) = {
  foo = x
  bar = x * 2
  foo to bar
}

But it doesn't do what you expect it to do.

With this feature, you could comment the last line, and get the version of the function that exposes all its variables. (This would be especially convenient combined with auto-calculators, which we still don't have, but even without that, you could write something like debugF = f(1) immediately below.)

Convenience

Commas are annoying :)

If all your keys are valid identifiers, then this new syntax might be easier to write.

@berekuk berekuk added Language Regarding Squiggle language semantics, distributions and function registry stage:proposal A proposal that warrants discussion whether we want to implement it labels Jan 7, 2025
@github-project-automation github-project-automation bot moved this to 🆕 To prioritize in Overview Jan 7, 2025
@OAGr
Copy link
Contributor

OAGr commented Jan 7, 2025

I think this would be nice, as long as it doesn't wind up being too difficult to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Regarding Squiggle language semantics, distributions and function registry stage:proposal A proposal that warrants discussion whether we want to implement it
Projects
Status: 🆕 To prioritize
Development

No branches or pull requests

2 participants