• Subject: Re: Lightweight function syntax (again)
• From: Tony Finch <dot@...>
• Date: Tue, 23 Nov 2010 20:26:11 +0000

```I've been playing around with a Haskell-ish syntax.

function ::= function `(´ [parlist] `)´ <block> end
| `\´ [parlist] `->´ <exp>
| `\´ [parlist] do <block> end

This isn't entirely great. I think it works better if there is a right
delimiter on the body of the lambda. For example:

each = \ f -> \ t do
for k,v in pairs(t) do
f(k,v)
end
end

r = {}

each \ k,v do r[k] = v+1 end {1,2,3} --> r = {2,3,4}

each \ k,v -> print(k,v) (r) -- fail

each(\ k,v -> print(k,v)) (r) -- ok

(I'm not saying that this each() function is a great idea, mind you!)

So I'm leaning towards a syntax like

function ::= function `(´ [parlist] `)´ <block> end
| `\´ [parlist] `(´ [explist] `)´
| `\´ [parlist] <funbody>

funbody  ::= <function> | <dostat> | <ifstat> | <loopstat>

which would allow

each = \ f \ t for k,v in pairs(t) do
f(k,v)
end
r = {}

each \ k,v do r[k] = v+1 end {1,2,3}

each \ k,v (print(k,v)) (r) -- win

each \...(print(...)) (r) -- heh

Tony.
--
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
HUMBER THAMES DOVER WIGHT PORTLAND: NORTH BACKING WEST OR NORTHWEST, 5 TO 7,
DECREASING 4 OR 5, OCCASIONALLY 6 LATER IN HUMBER AND THAMES. MODERATE OR
ROUGH. RAIN THEN FAIR. GOOD.```