Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The let construct in Common Lisp and Scheme supports imperative programming, meaning that you have this:

  (let variable-bindings statment1 statement2 ... statementN)
If statementN is reached and evaluates to completion, then its value(s) will be the result value(s) of let.

The variable-bindings occupy one argument position in let. This argument position has to be a list, so we can have multiple variables:

  (let (...) ...)
Within the list we have about two design choices: just interleave the variables and their initializing expressions:

  (let (var1 value1
        var2 value2
        var3 value3)
    ...)

Or pair them together:

  (let ((var1 value1)
        (var2 value2)
        (var3 value3)
    ...)
There is some value in pairing them together in that if something is missing, you know what. Like where is the error here?

  (let (a b c d e) ...)
we can't tell at a glance which variable is missing its initializer.

Another aspect to this is that Common Lisp allows a variable binding to be expressed in three ways:

  var
  (var)
  (var init-form)
For instance

  (let (i j k (l) (m 9)) ...)
binds i, j and k to an initial value of nil, and m to 9.

Interleaved vars and initforms would make initforms mandatory. Which is not a bad thing.

Now suppose we have a form of let which evaluates only one expression (let variable-bindings expr), which is mandatory. Then there is no ambiguity; we know that the last item is the expr, and everything before that is variables. We can contemplate the following syntax:

  (let a 2 b 3 (+ a b)) -> 5
This is doable with a macro. If you would prefer to write your Lisp code like this, you can have that today and never look back. (Just don't call it let; pick another name like le!)

If I have to work with your code, I will grok that instantly and not have any problems.

In the wild, I've seen a let1 macro which binds one variable:

  (let1 var init-form statement1 statement2 ... statementn)


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: