I have some code where I want to save some state information in order
to speed up a setf method. Basically, I'm searching a table, and I
don't want to have to re-search it when I'm setting the value if I
already searched it when getting the value.
The code I have is as follows:
(define-setf-expander table-get (table key)
(let (($table (gensym "TABLE-"))
($key (gensym "KEY-"))
($store (gensym "STORE-"))
($result (gensym "RESULT-"))
($foundp (gensym "FOUNDP-"))
($state (gensym "STATE-")))
(values
(list $table $key $result $foundp $state)
(list table key)
(list $store)
`(table-set/saved-state ,$store ,$table ,$foundp ,$state ,$key)
`(progn
(multiple-value-setq (,$result ,$foundp ,$state)
(table-get/saved-state ,$table ,$key))
(values ,$result ,$foundp)))))
macros that use the getter work fine, but direct setf doesn't, since
the foundp and state variables are not bound in that case. The setter
is called directly. How can I modify my code or my design in order to
achieve the results I want?
--
-> -/- - Rahul Jain - -\- <-
-> -\- http://linux.rice.edu/~rahul -=- ············@techie.com -/- <-
-> -/- "I never could get the hang of Thursdays." - HHGTTG by DNA -\- <-
|--|--------|--------------|----|-------------|------|---------|-----|-|
Version 11.423.999.221020101.23.50110101.042
(c)1996-2002, All rights reserved. Disclaimer available upon request.
From: Raymond Wiker
Subject: Re: setf-expanders which save state between the getter and the setter
Date:
Message-ID: <86wuyghthc.fsf@raw.grenland.fast.no>
Rahul Jain <·····@sid-1129.sid.rice.edu> writes:
> I have some code where I want to save some state information in order
> to speed up a setf method. Basically, I'm searching a table, and I
> don't want to have to re-search it when I'm setting the value if I
> already searched it when getting the value.
>
> The code I have is as follows:
>
> (define-setf-expander table-get (table key)
I'm not sure, but I think define-modify-macro may be what you
want... Paul Graham's "On Lisp" deals with this in detail, but I'm a
bit hazy on the particulars (probably time for me to re-read this
*fine* book :-)
--
Raymond Wiker Mail: ·············@fast.no
Senior Software Engineer Web: http://www.fast.no/
Fast Search & Transfer ASA Phone: +47 23 01 11 60
P.O. Box 1677 Vika Fax: +47 35 54 87 99
NO-0120 Oslo, NORWAY Mob: +47 48 01 11 60
Try FAST Search: http://alltheweb.com/
From: Rahul Jain
Subject: Re: setf-expanders which save state between the getter and the setter
Date:
Message-ID: <87sn934cid.fsf@photino.sid.rice.edu>
Rahul Jain <·····@sid-1129.sid.rice.edu> writes:
Seems all I needed to do was replace
> (list table key)
with (list table key nil nil nil)
thanks to Tim Moore for telling me such an obvious solution :)
--
-> -/- - Rahul Jain - -\- <-
-> -\- http://linux.rice.edu/~rahul -=- ············@techie.com -/- <-
-> -/- "I never could get the hang of Thursdays." - HHGTTG by DNA -\- <-
|--|--------|--------------|----|-------------|------|---------|-----|-|
Version 11.423.999.221020101.23.50110101.042
(c)1996-2002, All rights reserved. Disclaimer available upon request.
From: Tim Moore
Subject: Re: setf-expanders which save state between the getter and the setter
Date:
Message-ID: <a29rdc$19c$0@216.39.145.192>
In article <··············@photino.sid.rice.edu>, "Rahul Jain"
<·····@sid-1129.sid.rice.edu> wrote:
> I have some code where I want to save some state information in order to
> speed up a setf method. Basically, I'm searching a table, and I don't
> want to have to re-search it when I'm setting the value if I already
> searched it when getting the value. The code I have is as follows:
> (define-setf-expander table-get (table key)
> (let (($table (gensym "TABLE-"))
> ($key (gensym "KEY-"))
> ($store (gensym "STORE-"))
> ($result (gensym "RESULT-"))
> ($foundp (gensym "FOUNDP-"))
> ($state (gensym "STATE-")))
> (values
> (list $table $key $result $foundp $state) (list table key)
> (list $store)
> `(table-set/saved-state ,$store ,$table ,$foundp ,$state ,$key)
> `(progn
> (multiple-value-setq (,$result ,$foundp ,$state)
> (table-get/saved-state ,$table ,$key))
> (values ,$result ,$foundp)))))
> macros that use the getter work fine, but direct setf doesn't, since the
> foundp and state variables are not bound in that case. The setter is
> called directly. How can I modify my code or my design in order to
> achieve the results I want?
There needs to be a value form for each temp form. So, you need to
change your design a bit to have individual accessors for foundp and
state, or cheat and use multiple-value-setq in the values list (gross),
or have state be an optional argument to the setter form.
Tim