Subject: Re: Why is Scheme not a Lisp? From: Erik Naggum <erik@naggum.net> Date: Thu, 14 Mar 2002 04:33:21 GMT Newsgroups: comp.lang.lisp Message-ID: <3225069211869395@naggum.net> * Thomas Bushnell, BSG | (define (sum term a next b) | (if (> a b) | 0 | (+ (term a) | (sum term (next a) next b)))) | | People have barely begun the course when they get to this. In CL, | you'd do the same thing if you wanted, by passing in functions and | using APPLY to call them. apply? Scheme and Common Lisp both need apply for exactly the same reason. Scheme and Common Lisp differ in the use of _funcall_. I have such pity on you poor Scheme victims that I wrote the following little macro just to prove that Common Lisp is able to accomodate your needs painlessly: at the very least it removes the funcall allergen. (defmacro with-functions (functions &body body) `(macrolet ,(mapcar (lambda (function) `(,function (&rest args) `(funcall ,',function ,@args))) functions) (locally (declare (function ,@functions)) ,@body))) | So in one sense, it's trivial to translate. However, it would totally | defeat the pedagogic purpose to have to talk about APPLY at such an early | stage. But would you talk about apply in a Scheme text unless you had a list of variables? Something tells me you are reaching, not just mistaken. Anyway, you can now write (defun sum (term a next b) (with-functions (term next) (if (> a b) 0 (+ (term a) (sum term (next a) next b))))) instead of the supposedly horribly inelegant (defun sum (term a next b) (if (> a b) 0 (+ (funcall term a) (sum term (funcall next a) next b))))) I frankly do not see how this minor problem turns into this major deal for Schemers. Common Lispers change their language if something bothers them too much. In an educational setting, it is not unusual for the teacher/master to set up a more pedagogical environment than programmers usually use. If one uses or teaches the use of functions in variables a lot, I think it even makes sense to adopt a style like the above, since funcall may indeed make the code less readable. with-functions also provides the lexically evident clues that these names are special. The programmer does not have to check every function call to be certain that it has a different lexical than global meaning, as one must do in Scheme. There is no accidental "overwriting" global function definitions: You may call a variable "list" as long as you do not hand it to with-functions. /// -- In a fight against something, the fight has value, victory has none. In a fight for something, the fight is a loss, victory merely relief.