lua-users home
lua-l archive

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


Grr. What key did I just hit that means "send without prompting"?

On Tue, Feb 28, 2012 at 1:32 PM, Fabien <fleutot+lua@gmail.com> wrote:
> On Tue, Feb 28, 2012 at 2:41 AM, Jay Carlson <nop@nop.com> wrote:

>> I don't think anybody's been talking about a functional programming style.

> Fair enough. However, I believe that if you introduce terse and tempting
> lambdas in the language, then you're going to entice people into writing bad
> functional-ish code.

Smalltalk-80 blocks resembled closures but were not first class
values; they were stack-allocated. (I remember bumping my shins on
this before implementations fixed it.) Ruby syntax wants you to use
blocks a particular way. So I guess both of those languages threw
stumbling blocks in front of a functional style.

> One of Lua's goal is to be beginner-friendly; it
> doesn't only mean its grammar must be easy to grasp, it also means it
> shouldn't tempt beginners into writing unnecessarily awful code.

Greg Hudson made assignment a statement in one language; this
predictably enraged the C-heads, who really wanted to write

   while ( (c = getchar()) != EOF) {...}

and IIRC he also made some functional style harder, which annoyed the
other half of the user base. He described his philosophy as:

  "Write code vertically, not horizontally."

and I think that's present in Lua's style, and I appreciate it.

But as a design goal, keeping beginners from writing awful code also
means things they want to do should not involve syntactic atrocities.
This would be less of a problem without metaprogrammers like me who
would really like to build domain-specific control flow and so on in
ways that mesh well with the rest of the language.

I wonder if there's a vertical variant of list comprehensions.

>> Given you went to the trouble of building the pattern match syntax, you
>> should consider how verbose anything like it would be in base Lua.

> I wouldn't call the result "beginner-friendly", and I certainly wouldn't
> advocate back-porting it into plain Lua :)

Well, I'm not sure it couldn't be made beginner-friendly with a few
cuts of the knife, but I agree it seems out of place. Destructuring
assignment (in this case from pattern matches) probably needs to be
its own thing if it's to happen at all.

> I realize that delayed execution
> is a desirable feature, and if there's a beginner-friendly way to introduce
> it in the language, I'm all for it. But I'm afraid that terse lambdas would
> have unintended side effects in many hands.

Yeah, I need to think about that. (This is why we have mailing lists:
other people see stuff we don't.)

> PS: Thunks, in an imperative context, are probably more akin to
> continuations than to lambdas; but I don't know what to make out of this
> remark.

I agree, and as building blocks for control they're just the kind of
nice cuddly continuations compilers like to see: do not escape,
notionally stack-allocated. Call-once in the case of pure delay.
Smalltalk-80 blocks are not reentrant, which is just fine for
iterators. So maybe I should be looking at something more second-class
like "...".

Jay