[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: special forms, take two (was Re: A lua version of "amb")
- From: steve donovan <steve.j.donovan@...>
- Date: Tue, 28 Feb 2012 13:45:55 +0200
On Mon, Feb 27, 2012 at 6:36 PM, Fabien <fleutot+lua@gmail.com> wrote:
> If a short lambda syntax would significantly reduce your programs' verbosity, you're probably not being hampered by silly language limitations, you're writing bad code in a language you don't understand. It might be almost decent Scheme code, but it's bad Lua code.
There is this idea that 'functional' means a whole different way of
doing things from 'imperative', and since we need to agree on words,
that's fine. But limited use of 'functional idioms' can make
mostly-imperative programs easier to read and write.
-- sort in the wrong order
table.sort(T,|x,y|(x > y))
-- apply a method of an object to an array of values
map(|x| (obj:f(x)), values)
-- call a function a little time later (useful idiom for synchronizing
with GUI thread)
doLater(||(obj:something()))
(that's the 'easier quoting' point of Jay)
Now, to be Devil's Advocate: because the quoting in the last statement
has become so terse, it becomes harder to read. You now have to
become sensitive to the ||(...) idiom for quoting expressions. So I
am not a 100% advocate of this proposal.
(BTW, making obj:something mean exactly the same as
|...|(obj:something(...)) would be a nice bit of sugar. Not a new
idea, either, of course.)
steve d.