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

Re: C# is not Dylan (was: Re: C# : The new language from M$)



* Colin Walters wrote:
> Speaking of loops, I have started using Common Lisp for some of my
> programs instead of Scheme because of its standardization of important
> things like packages, but one thing I really miss from Scheme is the
> "named let" syntax for function calls.  I think this syntax beats both
> Common Lisp's `do' and `labels', as well as C's `for (;;) {}'
> construction, in terms of terseness and clarity.  I suppose it
> wouldn't be hard to write a `letf' macro or something, though.

named let is almost trivial to write in a CL, and if you have TRO it's
efficient.  Like this in fact:

    (defmacro iterate (name bindings &body body)
      "Scheme style named LET for common lisp: (ITERATE name bindings . body)
       bindings is a CL-style LET-bindings spec (ie you can have isolated
       symbols which are bound to NIL.  This will be horrible if your CL doesn't
       optimise local functions properly."
      ;; note that this is like LET* not LET
      (let ((argnames ())
	    (argvals ()))
	(labels ((grind-bindings (tail)
		   (if (not (null tail))
		       (etypecase (car tail)
			 (symbol
			  (grind-bindings (cdr tail))
			  (push (car tail) argnames)
			  (push nil argvals))
			 (list
			  (grind-bindings (cdr tail))
			  (push (car (car tail)) argnames)
			  (push (cadr (car tail)) argvals))))))
	  (grind-bindings bindings)
	  `(labels ((,name ,argnames
		     ,@body))
	    (,name ,@argvals)))))

It's possible to write seriously obscure code with named let I found,
because it's basically GOTO in slight disguise.  So I tend to use
explicit loops now as I have a tendancy to write maximally obscure
code if the language lets me.

LETF is traditionally used to mean something else -- a LET which can
bind places in the SETF sense.

--tim



References: