proposed syntax changes

25 views
Skip to first unread message

Dhanji R. Prasanna

unread,
Aug 9, 2012, 10:09:40 PM8/9/12
to loop...@googlegroups.com
I have been giving some thought to some syntax changes of late. In particular, I want to get rid of variable assignments in where blocks, I thought this was elegant initially, but it leads to not great looking code IMO. And the reading order is disrupted as you have to jump to the where block and back to see what variables are assigned to.

So this:

write_yaml() ->
  yaml.write(file)
  where
    yaml:   new Yaml()
    file:   file('xxx.yml')

becomes:


write_yaml() ->
  yaml = new Yaml(),
  file = file('xxx.yaml'),
  yaml.write(file)


And where blocks are reserved for private functions only. I am also thinking of getting rid of the requirement for a ',' to separate expressions in a do block, so again:


write_yaml() ->
  yaml = new Yaml()
  file = file('xxx.yaml')
  yaml.write(file)


That's what things would look like at the end. The reasoning is that commas aren't all that useful an aid for reading (just like ';') and they dont have the consistency either as you leave out a comma for the last (or "return") expression.

An alternative to this proposal is to use the "let" keyword for declarations:


write_yaml() ->
  let
    yaml = new Yaml()
    file = file('xxx.yaml')
  in
    yaml.write(file)


This has the advantage of a nice separation between declaring vars and using them. But otherwise I think it may be a bit too noisy. An alternative may be to inline the let keyword:



write_yaml() ->
  let yaml = new Yaml()
  let file = file('xxx.yaml')
  yaml.write(file)


This might look a bit better in a syntax highlighter. And prevent confusion and "re-assignment", etc.


Any thoughts or feedback?

Dhanji.

Dave Newton

unread,
Aug 9, 2012, 10:16:30 PM8/9/12
to loop...@googlegroups.com
I'd prefer the proposed new syntax (IIRC the `where` block for locals tripped me up originally anyway :)

Would the declarations be allowed in arbitrary locations, or only at the beginning of a function?

Having locals in a block seems nice from a documentation standpoint, either in-code or to generate browseable docs. The `in` seems redundant; we already know what we're in--the function. Unless they're nestable, I guess.

I'm not a big fan of multiple inline `let`s, though; that seems noisy to me.

Dave

Dhanji R. Prasanna

unread,
Aug 9, 2012, 10:55:32 PM8/9/12
to loop...@googlegroups.com
On Fri, Aug 10, 2012 at 12:16 PM, Dave Newton <davel...@gmail.com> wrote:
I'd prefer the proposed new syntax (IIRC the `where` block for locals tripped me up originally anyway :)


Hehe, sounds good.
 
Would the declarations be allowed in arbitrary locations, or only at the beginning of a function?

They would be allowed arbitrarily unless using the let...in scheme. Would you still prefer the plain syntax or let/in?


Having locals in a block seems nice from a documentation standpoint, either in-code or to generate browseable docs. The `in` seems redundant; we already know what we're in--the function. Unless they're nestable, I guess.

Nesting is useful, that's what haskell allows, but I'm not sure it's worth it. You can use a private (where block) function to achieve a similar effect, anyway.

Dhanji.

Dhanji R. Prasanna

unread,
Aug 11, 2012, 2:17:05 AM8/11/12
to loop...@googlegroups.com
These changes are now live in trunk.
Reply all
Reply to author
Forward
0 new messages