lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 09/05/2018 21:44, Sean Conner wrote:
It was thus said that the Great Lorenzo Donati once stated:

I wouldn't mind if Lua allowed an optional syntax for specifying what
"end" ends; optional but enforced if used, i.e. an error would be issued
if (say) "end for" didn't end a for structure.

I can't say if it would be too heavy for the compiler or if a nice
syntax could be devised that didn't render the grammar too complicated

For example:

end for         (ambiguous)
vs.
end for;
vs.
end ---for      (semantic comments?)
vs.
end ::for::     (fake label? ambiguous)
vs.
<choose your poison!>

  Here are some other options:

	function() ... endfunction
	if ... then ... endif
	while ... do ... endwhile
	for ... do ... endfor
	do ... enddo -- hmm ...

Okay ...

	function() ... noitcnuf
	if ... then ... fi
	while ... do ... elihw
	for ... do ... rof
	do ... od --- hmm ...

  The do keyword is problematic.  Several constructs use it, but it can be
used on its own to intruduce a new lexical scope.

  In my own code, I don't think I've ever used a semicolon.

  -spc



Interesting POVs.

I've never been a fan of languages that use reversing the keywords. They make my "internal linguistic processor" go poof! and slow me down to a crawl ( "'fi'?!? What the heck is 'fi'?!?" :-).

Although new keywords would fit the bill, I'd prefer something optional and more "minimalist". In throwaway script I rarely bother to mark end of scopes (even if quite lengthy), since I know I wouldn't be maintaining that code beyond its initial purpose. So a plain "end" to end all scopes is good and short (and in general you will have that verbose "LaTeX environment feeling" with begin{myenv}/end{myenv} which is tedious).

The headaches begin when I have an "old" (maybe 5 years) 1kLOC script or, worse still, a 1kLOC+ library module where I put some "clever" algorithm which once in a while needs some polishing or fixing (in the last couple of years I did very little Lua coding, although I run Lua scripts almost daily, since I have automated many common tasks using scripts).

In this case having a way to mark scope ends that is enforced by the compiler could be very nice.

Cheers!

-- Lorenzo