Does anyone ever use slot-value with a non-constant second argument?

  • Follow


Subject line says it all.  Does anyone have an example of real code that 
calls slot-value with a non-constant second argument?

Thanks,
rg
0
Reply rNOSPAMon (1855) 9/24/2009 6:12:49 AM

Ron Garret <rNOSPAMon@flownet.com> writes:

> Subject line says it all.  Does anyone have an example of real code that 
> calls slot-value with a non-constant second argument?

Yes.  Quite a lot.  You can find them with:
find /lisp/sources -name  \*.lisp -exec grep -ni 'slot-value[^'\'']*$'  {} /dev/null \;

For example:

mcclim-0.9.3/Doc/Guided-Tour/color-editor.lisp:48:    (setf (slot-value *application-frame* (gadget-id slider)) new-value)
postmodern/postmodern/table.lisp:152:             (loop :for slot :in (apply 'append slots) :collect (slot-value object slot))))
acla/lisp/clos.lisp:402:                    (setf (slot-value instance name) value)
slime-peer/swank.lisp:4099:             collect `(:value ,(slot-value object (swank-mop:slot-definition-name slot-def)))
web.archive.org/web/20050609081454/http:/www.csd.abdn.ac.uk/~tnordlan/PhD_Timetable/Programs/LISP/more+Lisp/screamer+.lisp:3235:      (slot-value (value-of objvar) (value-of slotname))
....

;; private examples:
wac/ac-access.lisp:302:                                 (slot-value object slot-name) 
wac/webapp-compiler.lisp:787:        (values (slot-value self attribute) t)
sexp/simple-sexp/read.lisp:920:                    (slot-value object (clos:slot-definition-name slot))) out))
....

-- 
__Pascal Bourguignon__
0
Reply pjb (7644) 9/24/2009 7:06:13 AM


Ron Garret <rNOSPAMon@flownet.com> writes:

> Subject line says it all.  Does anyone have an example of real code that 
> calls slot-value with a non-constant second argument?

Sure. We e.g. use it for a parser which parses a tcp stream line for
line and creates objects of different classes depending on the initial
part of text parsed. The objects are created without any initialization,
and then the slots are filled with (setf slot-value) as the parsing
proceeds. Or maybe (setf slot-value) doesn't count? But... hmm... the
corresponding writer does use slot-value itself. 
However, instead of code a la
(dolist (slot-name slots) ... (slot-value transaction slot-name) ...)
we could probably have used
(dolist (f accessors) ... (funcall f transaction) ...).
-- 
  (espen)
0
Reply espen1 (438) 9/24/2009 7:11:06 AM

Ron Garret <rNOSPAMon@flownet.com> writes:

> Subject line says it all.  Does anyone have an example of real code that 
> calls slot-value with a non-constant second argument?

I've used it quite a lot where I have objects (clsql:def-view-class)
where the slots correspond to fields in forms being filled out in a
web applicatio. The forms can then be built dynamically from the
object. Here's a simple example just to dump the object in html,
mostly for debugging purposes:

(defun object-to-table (obj slots)
  "generate a table from the object"
  (html 
   ((:table)
    (dolist (slot slots)
      (html 
       (:tr
        (:td (:princ slot))
        (:td (:princ (slot-value obj slot)))))))))

Petter
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
0
Reply newsmailcomp6 (330) 9/24/2009 7:26:10 AM

On Sep 24, 8:12=A0am, Ron Garret <rNOSPA...@flownet.com> wrote:
> Subject line says it all. =A0Does anyone have an example of real code tha=
t
> calls slot-value with a non-constant second argument?
>
> Thanks,
> rg

The first thing to pop to mind is some code that uses a serializable
sexp-based data structure to communicate with another piece of
software -- naturally I use the sexp for external communication and
build a graph of objects for the application's internal
representation. Converting between the two involves lots use of
getting and setting slots, along with getting and setting plist
values, all of which have non-constant keys.
0
Reply tburdick (336) 9/24/2009 11:17:12 AM

On Sep 24, 8:12=A0am, Ron Garret <rNOSPA...@flownet.com> wrote:
> Subject line says it all. =A0Does anyone have an example of real code tha=
t
> calls slot-value with a non-constant second argument?
>
> Thanks,
> rg

Out of curiosity, why do you ask?
0
Reply tburdick (336) 9/24/2009 11:18:49 AM

In article <m1iqf8yfzp.fsf@gazonk.netfonds.no>,
 Espen Vestre <espen@vestre.net> wrote:

> Ron Garret <rNOSPAMon@flownet.com> writes:
> 
> > Subject line says it all.  Does anyone have an example of real code that 
> > calls slot-value with a non-constant second argument?
> 
> Sure. We e.g. use it for a parser which parses a tcp stream line for
> line and creates objects of different classes depending on the initial
> part of text parsed. The objects are created without any initialization,
> and then the slots are filled with (setf slot-value) as the parsing
> proceeds. Or maybe (setf slot-value) doesn't count? But... hmm... the
> corresponding writer does use slot-value itself. 
> However, instead of code a la
> (dolist (slot-name slots) ... (slot-value transaction slot-name) ...)
> we could probably have used
> (dolist (f accessors) ... (funcall f transaction) ...).

Nope, (setf slot-value) "counts" for my purpose here.  Thanks.

rg
0
Reply rNOSPAMon (1855) 9/24/2009 11:56:23 AM

In article <87fxacbz4q.fsf@galatea.local>,
 pjb@informatimago.com (Pascal J. Bourguignon) wrote:

> Ron Garret <rNOSPAMon@flownet.com> writes:
> 
> > Subject line says it all.  Does anyone have an example of real code that 
> > calls slot-value with a non-constant second argument?
> 
> Yes.  Quite a lot.  You can find them with:
> find /lisp/sources -name  \*.lisp -exec grep -ni 'slot-value[^'\'']*$'  {} 
> /dev/null \;
> 

I think that incantation only works on certain machines ;-)

rg
0
Reply rNOSPAMon (1855) 9/24/2009 11:58:27 AM

In article 
<fa06d131-a0fb-42f5-974b-b5d5dfb3ceff@d23g2000vbm.googlegroups.com>,
 "Thomas F. Burdick" <tburdick@gmail.com> wrote:

> On Sep 24, 8:12 am, Ron Garret <rNOSPA...@flownet.com> wrote:
> > Subject line says it all.  Does anyone have an example of real code that
> > calls slot-value with a non-constant second argument?
> >
> > Thanks,
> > rg
> 
> Out of curiosity, why do you ask?

I have this project called Lexicons that I work on when time permits.  
Lexicons are an implementation of a lexically scoped module system for 
Common Lisp.  Lexicons are intended to be an alternative to packages, 
which I personally find annoying, and many beginners find confusing.  
One of the few things that packages can do which lexicons until recently 
could not was allow one to multiply-inherit from classes with slots that 
have the names with the same symbol-name without having those slots 
clobber each other.  The straightforward translation of defclass to 
lexicons did not allow this, but now it does.  It requires the use of a 
lexical version of slot-value in order to work, since slot-references 
now must be resolved at macroexpand time rather than read time.  
Supporting dynamic slot access is somewhat expensive in this case, and I 
was just wondering whether it was worth implementing.  Apparently it is.

rg
0
Reply rNOSPAMon (1855) 9/24/2009 12:03:16 PM

Ron Garret <rNOSPAMon@flownet.com> writes:

> In article <87fxacbz4q.fsf@galatea.local>,
>  pjb@informatimago.com (Pascal J. Bourguignon) wrote:
>
>> Ron Garret <rNOSPAMon@flownet.com> writes:
>> 
>> > Subject line says it all.  Does anyone have an example of real code that 
>> > calls slot-value with a non-constant second argument?
>> 
>> Yes.  Quite a lot.  You can find them with:
>> find /lisp/sources -name  \*.lisp -exec grep -ni 'slot-value[^'\'']*$'  {} 
>> /dev/null \;
>> 
>
> I think that incantation only works on certain machines ;-)

Yes, POSIX machines.  Sorry not to provide the incantation for Lisp machines.

-- 
__Pascal Bourguignon__
0
Reply pjb (7644) 9/24/2009 12:20:19 PM

Ron Garret <rNOSPAMon@flownet.com> writes:

> Subject line says it all.  Does anyone have an example of real code that 
> calls slot-value with a non-constant second argument?

Yes.  We used this in several places in our Loom knowledge
representation system.  It was used in a number of places where we
needed to manipulate values of slots but didn't necessarily know them
except at run time.  This was often the case for handling the assertions
and retractions of values at run time, since Loom was an interactive
system.

One interesting example had to do with our implementation of dynamnic
slots.  We had additional slots that were seldom used (and thus often
NIL), so to save space we used a single dynamic-values alist to store
these values.  And then we had code in
UPDATE-INSTANCE-FOR-REDEFINED-CLASS that would be able to move values
from real slots to dynamic slots and vice versa if slots were added or
removed in a class redefinition at run time.  [Take that, C++ and Java!]


-- 
Thomas A. Russ,  USC/Information Sciences Institute
0
Reply tar (1630) 9/24/2009 6:33:32 PM

In article <7c4oqso7p8.fsf@pbourguignon.lefevre.anevia.com>,
 pjb@informatimago.com (Pascal J. Bourguignon) wrote:

> Ron Garret <rNOSPAMon@flownet.com> writes:
> 
> > In article <87fxacbz4q.fsf@galatea.local>,
> >  pjb@informatimago.com (Pascal J. Bourguignon) wrote:
> >
> >> Ron Garret <rNOSPAMon@flownet.com> writes:
> >> 
> >> > Subject line says it all.  Does anyone have an example of real code that 
> >> > calls slot-value with a non-constant second argument?
> >> 
> >> Yes.  Quite a lot.  You can find them with:
> >> find /lisp/sources -name  \*.lisp -exec grep -ni 'slot-value[^'\'']*$'  {} 
> >> /dev/null \;
> >> 
> >
> > I think that incantation only works on certain machines ;-)
> 
> Yes, POSIX machines.  Sorry not to provide the incantation for Lisp machines.

Doesn't work on my POSIX machine:

[ron@mickey:~]$ find /lisp/sources -name  \*.lisp -exec grep -ni 
'slot-value[^'\'']*$'  {} /dev/null \;
find: /lisp/sources: No such file or directory

rg
0
Reply rNOSPAMon (1855) 9/24/2009 9:52:28 PM

11 Replies
28 Views

(page loaded in 0.175 seconds)


Reply: