View Single Post
Old 25 August 2015, 12:54   #311
Registered User

Megol's Avatar
Join Date: May 2014
Location: inside the emulator
Posts: 209
Originally Posted by Mrs Beanbag View Post
I like how you use the same keyword for all the end statements. But i would swap round the syntax of the short and long versions, so that "do" is a universal block beginning. Then you can always see that there is a block even when confronted with an unfamiliar statement, which maybe also eases expansion of the language.
I had it like that before but didn't like it - more typing without any advantages (well for some implementations the parser could be simpler). It would be better if short statements had a common keyword, "do" could be used but for some reason I don't like it.
An earlier iteration used colon to indicate a short statement but it was easy to misread. I consider that a problem in Python too.

OTOH in this language short statements should be relatively uncommon due to guarded execution:

-- guarded variant
factorial: (n: nat)^nat
  ^1 if n=0 -- read: return 1 if n is equal to 0

-- select variant, not really a guard but sharing similar syntax
-- here the return isn't conditional and the if selects between two values
factorial2: (n: nat)^nat
  ^1 if n=0 else n*factorial2(n-1)
Megol is offline  
Page generated in 0.05085 seconds with 9 queries