[e-lang] Proposed grammar simplifications

Dean Tribble tribble at e-dean.com
Wed Jun 1 00:11:01 EDT 2005


Mark Miller wrote:

> David Hopwood wrote:
>
>> [...] "foo with= (3)" is hardly enough shorter than "foo := foo.with(3)"
>> to justify this sugar at all.
>
>
> Assuming Dean can make it work in the Antlr grammar, it looks like we 
> will preserve the current ability to leave off these parens. 

Right now, it looks for a paren.  It needs to look ahead for a full 
expression in order to correctly deal with interesting expressions on 
the right hand side.

> But for the record...

I expect the verb= stuff to die eventually once we improve the 
collection syntax, but also just for the record....

I happen to agree with David, and was rather hoping that the end result 
would be to make the syntax go away :-)  I just don't have a problem with:

    vec := vec.with(0, 3)

because it's just so clear. and for example, the following is trivial 
and obvious.

    vec := vec.with(0, 3).with(1, "hello")

If we really want syntactic support, here's a quick suggestion that I 
think is a better approach than the verb= stuff, because it helps in 
more situations than mere assignment (which one should generally be 
avoiding anyway):

    vec := vec[0 => 3]

and

    vec := vec[0 => 3, 1 => "hello"]

This syntax would then help support many other scenarios:

newMsg := msg["Subject" => "Please review"]

return params["cookie" => computedCookie]

>> How frequent are cases like "bar with= (key, value)"?
>
> We hope to encourage a style of programming with mutable variables 
> holding immutable collections, rather than immutable variables holding 
> mutable collections. Should this style actually catch on, the above 
> case would be quite common. In fact, the desire to support the 
> immutable-collection style was exactly the motivating case for 
> introducing the verb= syntax in the first place.

Without real examples (and I mean substantial chunks of code), 
motivating any syntax is hard.  My expectation is that once we compare 
interesting chunks of code written with no syntax enhancements, "verb=", 
and a TBD syntax for expressing modified collections, the latter will 
win, and the no-syntax style will be generally better than the verb= 
style.  I'm happy to wait for such an example before spending too much 
time on this :-)


More information about the e-lang mailing list