I was just reading the very enjoyable paper by Stefik and Siebert, "An
Empirical Investigation into Programming Language Syntax," *ACM T. Comp.
Ed.,* 13(4):19, 2013, (http://web.cs.unlv.edu/stefika/Papers.php), and I
noticed that Julia already follows one of their recommendations: On page
19:32 they point out that in languages with "if ... then ... else ... end"
type syntax, programmers have a large tendency to forget to type the "then"
token. So when they designed the Quorum programming language they
specified that "if ... else .. end" doesn't have a "then" token. The only
other languages that I've found that make a similar decision are Ruby
(where the "then" is optional,) and Julia.
Unfortunately in Ruby this leads to an ambiguity:
if x < y - x
println("true")
else
println("false")
endif
I believe Ruby gives a warning for this.
By experiment I have discovered that Julia seems to handle the ambiguity
by, I think, taking line-ends into account.
That is:
x = 1
y = 2
if x < y - x
println("true")
else
println("false")
end
prints "false" while
if x < y
-x
println("true")
else
println("false")
end
prints "true."
Similarly
begin
x - y
end
returns -1
while
begin
x
- y
end
returns -2
Is there a grammar for Julia somewhere that I can read to understand how
line-ends (or other whitespace) impact parsing?
Thanks,
-Matt