setf v defparameter

98 views
Skip to first unread message

Old-RPGer

unread,
Dec 18, 2010, 8:12:42 PM12/18/10
to Land of Lisp
Page 27 introduced setf (smaller) & (bigger). Page 28 (start-over)
reverts to defparameter. What's the virtue of using setf v
defparameter?

Conrad

unread,
Dec 20, 2010, 1:35:48 PM12/20/10
to Land of Lisp
Hi Old-RPGer:

Actually, defparameter is introduced on page 22. You use defparameter
to define new "global" variables (can also be done with defvar) and
use setf to set existing variables.

There's a lot of history as to why these two operations are treated
separately in Common Lisp. The basic gist of it is that it's useful to
know if you're accidentally redefining variables. See the discussions
of defvar and "generic setters" in the book for more detail (though my
book doesn't cover 100% of the esoteric details of this issue.)

Dan Brooking

unread,
Jun 30, 2012, 5:46:52 PM6/30/12
to land-o...@googlegroups.com
So basically there would not be anything wrong semantically with using defparameter instead of setf?  It's just a design choice to use setf to explicitly state what your intentions are with the command?

Purity Control

unread,
Jul 1, 2012, 1:09:59 AM7/1/12
to land-o...@googlegroups.com
HI Dan,

These two links should give you all the juicy details.



That will explain the semantic issues for you. 
What I would say though is that the vast majority of code is written seldom and read lots so intentions mean a lot. Its nice to be kind to anyone who may have to read your code (including yourself). :-)

Hope that helps.
Reply all
Reply to author
Forward
0 new messages