4 ms·
Why do you say LET and LET* have very different uses? I just use LET* if I need to reference a preceding variable in the same declaration (it happens). Actually
by gruseom 16y ago
Why do you say LET and LET* have very different uses? I just use LET* if I need to reference a preceding variable in the same declaration (it happens). Actually I vaguely remember PG in one of his Lisp books saying LET* indicates bad code, something I never understood, though empirically I've noticed some evidence for it.
- jpr 16y ago> LET* indicates bad code, something I never understood Neither did I, until I encountered something along the lines of: (let* ((foo ...) (foo ...) (foo ...) (foo ...) (foo ...) (foo ...) (foo ...)) ...)
- gruseom 16y agoThat's strangely unidiomatic. I wonder why that person didn't just write: (let ((foo ...)) (setf foo ...) (setf foo ...) ...) On a tangential note, while I try to avoid multiple assignment as much as possible, I also enjoy availing myself of CL's imperativeness whenever doing so makes my code smaller or more efficient. I really like CL's multiparadigm approach. The sweet spot seems to be: allow side-effects in the small (i.e. within functions or small scopes) and be as strict as you can in composing larger pieces.
- yewweitan 16y agoWell, maybe 'very different' was an overstatement =). One way to look at it is that we should use single-use functions as far as possible to keep code straightforward. And as jpr said, LET* can potentially promote bad style, giving one the inclination to mix functional and imperative styles in a potentially troublesome fashion. I think it was in 'On Lisp' that PG said that use of LET* should be minimised for the reasons above. But if not, you're right. Use LET* just as you mentioned, but don't use LET* for all cases. Some discussion available @ Stack Overflow: http://stackoverflow.com/questions/554949/let-versus-let-in-common-lisp http://stackoverflow.com/questions/554949/let-versus-let-in-...