squiggle icon indicating copy to clipboard operation
squiggle copied to clipboard

Interpret result-less blocks as dicts

Open berekuk opened this issue 11 months ago • 1 comments

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 avatar Jan 07 '25 19:01 berekuk

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

OAGr avatar Jan 07 '25 19:01 OAGr