3.1.5.1 Why is 'let' allowed to float around?
Marco G. Antoniotti
The 'let' *is* allowed to float around in Dylan programs. As minor as it is, this really bothers me.
The point of having 'let' as syntactic sugar for a functional binding is somewhat lost in Dylan. A syntax like ML
let <bindings>
 in
   <ops>
 end
would have made more sense.
Paul Haahr
Which, in Dylan, would probably be transliterated as something like
let (bindings) body ... end
given the rest of the syntax.)
I have to admit that this bothered me, too, at first.  Until I started using it.  All of a sudden, I discovered the joy of not needing a new level of indentation just to introduce a new local variable.
(C++ programmers probably feel the same way:  C requires that local declarations appear at the beginning of a {} enclosed block, where C++ allows them in any statement position.  Very convenient.)
But, if you really don't like that bit of Dylan syntax after trying it, here's a ``bind'' macro which behaves like a Lisp/Scheme let*. The word ``let'' is one of the eight or so truly reserved words in Dylan that can't be renamed, so I had to use a different name.
  define macro bind
    { bind (?bindings) ?:body end }
    => { ?bindings; ?body }
   bindings:
    { ?binding:*, ... }
    => { let ?binding; ... }
    { }
    => { }
  end macro;
So, for example,
  bind (a = 1, b = 2)
    a + b
  end
  => 3
  bind (a = 1, b = a + 1)
    b
  end
  => 2
  bind (a = 13, a = 42)
    a
  end
  => 42
Marco G. Antoniotti
The problem with the choice made by the Dylan designers is that we'll see a lot of code written like
<statements>*
let newvar = 33;
<statements>*
let anothervar = 44;
<statements>*
Paul Haahr
I expect so, too. I've written lots of code like that myself. I think it's perfectly readable, maintainable code. I like it. What about it do you find problematic
Marco G. Antoniotti
Not Lispish enough :)
Enrico Colombini
> From: Paul Haahr: 
> I expect so, too. I've written lots of code like that
> myself. I think it's perfectly readable, maintainable code.
> I like it.
I like it too, and consider it a major readability improvement from Lisp (no holy wars, please).
Jeff Dalton
Look at it like this: Dylan-style "let" can more naturally replace assignment in more cases. And Dylan is trying to attract people away from languages where they'd be using assignment all over the place.
(I know there are arguments that point the other way. E.g. better attract them to a more functional style so that it's less likely that bad habits will be carried over. But, on balance, I think Dylan's "let" is at least a reasonable idea and probably a good one.)
>  <statements>*
>  let newvar = 33;
>  <statements>*
>  let anothervar = 44;
>  <statements>*
FWIF, I prefer code like that above to code w/ a single "let" at the top but with the other "lets" replaced by assignments.