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

get,getf



    Date: Tue, 5 Mar 91 08:24 MST
    From: paul@taos.intel.com (Paul Collier)


    While looking through some of the system code that performs backups, I
    came across the following:

	    (dolist (elt (backup-dump-get-dir-list wildpath))
	(if (dumper-prefilter elt)
	    (if (get elt :directory)
		(push (car elt) dirs)
		(push elt files))))

    According to CLtL p. 164, and the Symbolics debugger, this shouldn't
    work. GET is defined as returning a value from the property list of a
    symbol and sure enough, if I try to run this as a function unto itself,
    it blows up because elt is bound to an element of a list. Not to mention
    that the value of elt is such that it won't work as a plist. 

Much of Genera was written in Zetalisp, well before the advent of Common
Lisp, and has never been updated.  You've been fooled by the difference
between CL:GET and ZL:GET.  The latter takes either a symbol or a
"disembodied property list" as its first argument.  A disembodied
property list is one on which you use CDR to get to the first key.  This
is so

  (ZL:PUTPROP the-plist-owner the-key the-new-value)

could be expected to know what to do if the property list didn't already
contain the property (it needs to store into the cell in which the
property list is stored, and Lisp doesn't have "Call by value", or
whatever it's called).

A disembodied property list can be represented as a cons whose CAR is
ignored (or used for something else) or as a locative; the CDR operation
on locatives dereferences them.  Lots of old Genera interfaces return or
use disembodied property lists.  For example, FS:DIRECTORY-LIST returns
objects disembodied property lists; the CAR is the truename and the rest
is the property list sequence.  More modern code (e.g, the Namespace
system) tends to use Common Lisp property lists instead; for example, if
you send a namespace object the :NAMESPACE-VIEW message, you get back
two values, one of which is the name of the object within the namespace
in question, and the other is a CL:GETF-able property list.

ZL:GET can be defined as:

 (defun ZL:GET (plist-owner key)
   (if (symbolp plist-owner)
       (cl:get plist-owner key)
       (cl:getf (cdr plist-owner) key)))

[paul:]								 It seems
    like it should be written:

	    (dolist (elt (backup-dump-get-dir-list wildpath))
	(if (dumper-prefilter elt)
	    (if (getf (cdr elt) :directory)
		(push (car elt) dirs)
		(push elt files))))


    My question is, why does the previous work? It obviously does, since
    I've been doing backups for years and it's never blown up. I'm also
    curious as to why the original coder used 'elt' as the variable name in
    the form. It seems strange to use a function name as a variable name
    (although admittedly harmless.)

The function named ELT is newer than this code.  It clearly had the same
basic connotations ("Element of a series") to the author of this
function as it did to the designers of Common Lisp.