lua-users home
lua-l archive

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


On Apr 27, 2014 2:32 AM, "steve donovan" <steve.j.donovan@gmail.com> wrote:
>
> On Sun, Apr 27, 2014 at 2:13 AM, Jay Carlson <nop@nop.com> wrote:
> > I think what we *can* get is a view of a particular 1990 aesthetic.

> Maybe so, but the need for $ for each variable escapes me.

That's pretty easy: it's by analogy to the shell. You need to use $ everywhere in the shell. Actually you don't, since setting variables is like "set!"/"setq". So the shell is inconsistent! Perl says, "Let's fix it!"

With a modern eye, this is just broken. The way you refer to variables in /bin/sh is: 

  rm "$src"

since rm $src means something rather different involving list splicing... well, no, it is not clear what it means.[1]

So my guess is that bad shell programming habits and the accompanying naive mental model are the basis for seeing a false inconsistency in the existing Unix tools. And then they used "sigil" to explain this choice. Really, it's much simpler to understand Perl if you just consider all of the linguistics fancy talk to be after-the-fact rationalization for some aesthetic judgments they did not necessarily consciously understand. Natural language is like that: full of random choices nobody knew they were making, and now lost in time.

I think perl4 barewords then fell out of the sigil decision (and isn't the word "sigil" an anachronism in this case?)

In an attempt to draw fewer flames, I'll repeat that having a post-hoc explanation is way better than having no explanation. 

There is a different design problem here too: optimizing for string interpolation. I just saw my nth "SELECT * FROM t WHERE id=$id" in PHP, and I'm still furious about it. It's a bad when it ends up being much easier to do the wrong thing than to do the correct thing. It is many more keystrokes to type out the Drupal

  db_query('SELECT * FROM t WHERE group=:group and id<>:id', 
        array(':group' => $group, ':id' => $id));

when the compiler should be able to just read "WHERE group=$group" as a placeholder expression--which is what you actually *meant* most of the time!

This is why you can't have $ for identifiers in Lua. I need it for sugar.

  $"SELECT * FROM t WHERE group=$group AND id<>$id" 

is sugar for the list constructor

  {"SELECT * FROM t WHERE group=$group AND id<>$id", 
        id=id, group=group}

and sql$"..." does exactly what you think it would from all the other Lua function call shorthand.

For true speed freaks, sql:$"abc $group $id" could sugar something else: sql("abc $group $id", group, id), which does not allocate on the heap. Anyway, this all works because sql() et al can memoize the parsed form of the body.

Jay

[1]: And you probably wanted to write rm -- "$src", but welcome to Unix, here's your accordion. 

Intriguingly, bash 2.00 flagged which filenames were expanded from wildcards ("touch ./-f" is fun) and glibc getopt() picked up this information. The feature was backed out in bash 2.01. So much for "GNU's Not Unix".