From: jtdubs on 7 Feb 2005 00:27 David Sletten wrote: > fix wrote: > > > >> (defun deriv-eval (expr var val) > >> (let ((derivans (deriv expr var))) > >> (setf (symbol-value var) val) > >> (eval derivans))) > >> > > This could be even simpler: > (defun deriv-eval (expr var val) > (setf (symbol-value var) val) > (eval (deriv expr val))) Or even: (defun deriv-eval (expr var val) (set var val) (eval (deriv expr var))) However, I don't know what the community consensus is on #'set. Is it's usage frowned upon? I never seem to see it used. Same with #'setq. I've heard people say that you should always just use #'setf. Justin Dubs
From: David Sletten on 7 Feb 2005 01:45 jtdubs(a)gmail.com wrote: > > (defun deriv-eval (expr var val) > (set var val) > (eval (deriv expr var))) > > However, I don't know what the community consensus is on #'set. Is > it's usage frowned upon? I never seem to see it used. Same with > #'setq. I've heard people say that you should always just use #'setf. > > Justin Dubs > According to CLHS, SET is deprecated: http://www.lispworks.com/documentation/HyperSpec/Body/f_set.htm You'll have to ask one of the gurus about why. David Sletten
From: Pascal Costanza on 7 Feb 2005 04:56 David Sletten wrote: > jtdubs(a)gmail.com wrote: >> >> (defun deriv-eval (expr var val) >> (set var val) >> (eval (deriv expr var))) >> >> However, I don't know what the community consensus is on #'set. Is >> it's usage frowned upon? I never seem to see it used. Same with >> #'setq. I've heard people say that you should always just use #'setf. >> >> Justin Dubs >> > > According to CLHS, SET is deprecated: > http://www.lispworks.com/documentation/HyperSpec/Body/f_set.htm > > You'll have to ask one of the gurus about why. SET evaluates its first argument, SETQ doesn't (the Q stands for "quoted"). The first argument to SET must evaluate to a symbol whose global symbol-value will be changed. The first argument to SETQ must be a symbol that refers to a possibly local variable. It's not possible to make SET refer to local variables. The first Lisps that were dynamically scoped didn't make a distinction between (SETQ var value) and (SET (QUOTE var) value), because there is none. In a lexically scoped Lisp (like Common Lisp) these are two very different operations. SET was deprecated in order to avoid confusion and be more explicit what is actually meant. Pascal
From: fix on 7 Feb 2005 06:44 David Sletten wrote: > fix wrote: > > >>> (defun deriv-eval (expr var val) >>> (let ((derivans (deriv expr var))) >>> (setf (symbol-value var) val) >>> (eval derivans))) >>> > > This could be even simpler: > (defun deriv-eval (expr var val) > (setf (symbol-value var) val) > (eval (deriv expr val))) > But I am not too sure how it works. The setf is giving a value to the variable, and the second line is differentiating expr with respect to a number? .... [snip] ...
From: jtdubs on 7 Feb 2005 09:59
Pascal Costanza wrote: > David Sletten wrote: > > > jtdubs(a)gmail.com wrote: > >> > >> (defun deriv-eval (expr var val) > >> (set var val) > >> (eval (deriv expr var))) > >> > >> However, I don't know what the community consensus is on #'set. Is > >> it's usage frowned upon? I never seem to see it used. Same with > >> #'setq. I've heard people say that you should always just use #'setf. > >> > >> Justin Dubs > >> > > > > According to CLHS, SET is deprecated: > > http://www.lispworks.com/documentation/HyperSpec/Body/f_set.htm > > > > You'll have to ask one of the gurus about why. > > SET evaluates its first argument, SETQ doesn't (the Q stands for > "quoted"). The first argument to SET must evaluate to a symbol whose > global symbol-value will be changed. The first argument to SETQ must be > a symbol that refers to a possibly local variable. It's not possible to > make SET refer to local variables. Hey, thanks. Great point. I had just explained a similar thing with respect to #'funcall in another thread, but for some reason this didn't occur to me. :-( > The first Lisps that were dynamically scoped didn't make a distinction > between (SETQ var value) and (SET (QUOTE var) value), because there is > none. In a lexically scoped Lisp (like Common Lisp) these are two very > different operations. SET was deprecated in order to avoid confusion and > be more explicit what is actually meant. Gotcha. Thanks again. Justin Dubs |