hi there
newbie question: in emacs lisp i want to append a list to another one and
store the result in the list it self. at the moment i use:
(setq list-a (append list-b list-a))
is theer a more convinient way dropping the rementioning of list-a? for
elements "push" excatly does the job:
(push 'my-element list-a)
i'm looking for somthing like "push a list on a list".
does anybody know an emacs-lisp macro/from/function for that?
thanks a lot, leo
"leo" <········@noospaam.myrealbox.com> wrote in message
··················@otis.netspace.net.au...
> hi there
>
> newbie question: in emacs lisp i want to append a list to another one and
> store the result in the list it self. at the moment i use:
> (setq list-a (append list-b list-a))
>
> is theer a more convinient way dropping the rementioning of list-a? for
> elements "push" excatly does the job:
> (push 'my-element list-a)
> i'm looking for somthing like "push a list on a list".
>
> does anybody know an emacs-lisp macro/from/function for that?
>
> thanks a lot, leo
>
A:
(defmacro setf-append (x &rest lists)
`(setf ,x (append ,x ,@lists)))
setf-append
(let ((x '(1 2 3))
(y '(4 5 6)))
(setf-append x y)
x)
(1 2 3 4 5 6)
B:NCONC but be very, very careful.
(defun foo (x)
(nconc '(1 2 3) x)) ;this list is going to be altered!
foo
(foo '(4 5 6))
(1 2 3 4 5 6)
(foo '(4 5 6))
(1 2 3 4 5 6 4 5 6) ; whoops!
(defun foo(x)
(nconc (list 1 2 3) x)) ;so's this, but it is freshly created every time
foo
(foo '(4 5 6))
(1 2 3 4 5 6)
(foo '(4 5 6))
(1 2 3 4 5 6)
--
Geoff
"Geoffrey Summerhayes" <·············@hotmail.com> writes:
> (defmacro setf-append (x &rest lists)
> `(setf ,x (append ,x ,@lists)))
You should use GET-SETF-EXPANSION to evaluate the subforms of x just
once. And perhaps DEFINE-MODIFY-MACRO is useful?
--
Lars Brinkhoff, Services for Unix, Linux, GCC, HTTP
Brinkhoff Consulting http://www.brinkhoff.se/
Lars Brinkhoff <·········@nocrew.org> writes:
> "Geoffrey Summerhayes" <·············@hotmail.com> writes:
> > (defmacro setf-append (x &rest lists)
> > `(setf ,x (append ,x ,@lists)))
>
> You should use GET-SETF-EXPANSION to evaluate the subforms of x just
> once. And perhaps DEFINE-MODIFY-MACRO is useful?
This precise example (under the name APPENDF) is offered in CLHS.
http://www.lispworks.com/reference/HyperSpec/Body/m_defi_2.htm
[If you're using LispWorks in the CL-USER package, don't be faked out by
the fact that their CL-USER package inherits from the LW package, which
already defines APPENDF. You'll want to do (SHADOW 'APPENDF) or use
another name if you're in the LW CL-USER package.]
[I gotta say I don't understand why implementations that want to impress
people with their own stuff don't start in a proprietary package, e.g.,
LW-USER or HCL-USER or XANALYS-USER or some such, and leave CL-USER just
using CL. It's certainly conforming to do what LW does, so maybe LW is
doing what they think CL intended them to do, because some in the CL
committee wanted this kind of confusion, but it makes CL-USER a no man's
land that is massively unportable and often not even good for learning
purposes and does the community a huge disservice.]
Kent M Pitman <······@nhplace.com> writes:
> [I gotta say I don't understand why implementations that want to impress
> people with their own stuff don't start in a proprietary package, e.g.,
> LW-USER or HCL-USER or XANALYS-USER or some such, and leave CL-USER just
> using CL. It's certainly conforming to do what LW does, so maybe LW is
> doing what they think CL intended them to do, because some in the CL
> committee wanted this kind of confusion, but it makes CL-USER a no man's
> land that is massively unportable and often not even good for learning
> purposes and does the community a huge disservice.]
Hear, hear! I've run into this several times already in working on my
book.
-Peter
--
Peter Seibel ·····@javamonkey.com
Lisp is the red pill. -- John Fraser, comp.lang.lisp
"Lars Brinkhoff" <·········@nocrew.org> wrote in message
···················@junk.nocrew.org...
> "Geoffrey Summerhayes" <·············@hotmail.com> writes:
> > (defmacro setf-append (x &rest lists)
> > `(setf ,x (append ,x ,@lists)))
>
> You should use GET-SETF-EXPANSION to evaluate the subforms of x just
> once. And perhaps DEFINE-MODIFY-MACRO is useful?
>
(apropos "GET-SETF-EXPANSION")
"No apropos matches for `GET-SETF-EXPANSION'"
(apropos "DEFINE-MODIFY-MACRO")
"No apropos matches for `DEFINE-MODIFY-MACRO'"
Emacs Lisp, eh?
--
Geoff
"Thomas F. Burdick" <···@famine.OCF.Berkeley.EDU> wrote in message
····················@famine.OCF.Berkeley.EDU...
> "Geoffrey Summerhayes" <·············@hotmail.com> writes:
>
> > "Lars Brinkhoff" <·········@nocrew.org> wrote in message
> > ···················@junk.nocrew.org...
> > > "Geoffrey Summerhayes" <·············@hotmail.com> writes:
> > > > (defmacro setf-append (x &rest lists)
> > > > `(setf ,x (append ,x ,@lists)))
> > >
> > > You should use GET-SETF-EXPANSION to evaluate the subforms of x just
> > > once. And perhaps DEFINE-MODIFY-MACRO is useful?
> >
> > (apropos "GET-SETF-EXPANSION")
> > "No apropos matches for `GET-SETF-EXPANSION'"
> > (apropos "DEFINE-MODIFY-MACRO")
> > "No apropos matches for `DEFINE-MODIFY-MACRO'"
> >
> > Emacs Lisp, eh?
>
> What is this, a bad joke? Emacs Lisp uses lowercase:
>
> ELISP> (apropos "get-setf")
> ((get-setf-method "Return a list of five values describing the setf-method
for PLACE." nil "autoload" nil nil nil))
>
> ELISP> (apropos "define-modify")
> ((define-modify-macro "(define-modify-macro NAME ARGLIST FUNC): define a
`setf'-like modify macro." nil "autoload common-lisp-indent-function" nil
nil nil))
>
Oh, damn. Came home from work on lunch, checked group, went to check for
get-setf,
cut-and-pasted it, case never even occured to me. Arrrgh. My bad. I'll go
and sit
quietly in the corner now...
--
Geoff
"Thomas F. Burdick" <···@famine.OCF.Berkeley.EDU> wrote in message
····················@famine.OCF.Berkeley.EDU...
> "Geoffrey Summerhayes" <·············@hotmail.com> writes:
>
> > "Lars Brinkhoff" <·········@nocrew.org> wrote in message
> > ···················@junk.nocrew.org...
> > > "Geoffrey Summerhayes" <·············@hotmail.com> writes:
> > > > (defmacro setf-append (x &rest lists)
> > > > `(setf ,x (append ,x ,@lists)))
> > >
> > > You should use GET-SETF-EXPANSION to evaluate the subforms of x just
> > > once. And perhaps DEFINE-MODIFY-MACRO is useful?
> >
> > (apropos "DEFINE-MODIFY-MACRO")
> > "No apropos matches for `DEFINE-MODIFY-MACRO'"
> >
> > Emacs Lisp, eh?
>
> What is this, a bad joke? Emacs Lisp uses lowercase:
>
> ELISP> (apropos "define-modify")
> ((define-modify-macro "(define-modify-macro NAME ARGLIST FUNC): define a
`setf'-like modify macro." nil "autoload common-lisp-indent-function" nil
nil nil))
mmmh, in emacs 21.3 when i evaluate
(apropos "define-modify-macro")
i get the message
((define-modify-macro "(not documented)" nil nil nil nil nil))
where do you get the little doc-string from?
cheers, leo
"leo" <········@noospaam.myrealbox.com> writes:
> "Thomas F. Burdick" <···@famine.OCF.Berkeley.EDU> wrote in message
> ····················@famine.OCF.Berkeley.EDU...
> > "Geoffrey Summerhayes" <·············@hotmail.com> writes:
> >
> > > "Lars Brinkhoff" <·········@nocrew.org> wrote in message
> > > ···················@junk.nocrew.org...
> > > > "Geoffrey Summerhayes" <·············@hotmail.com> writes:
> > > > > (defmacro setf-append (x &rest lists)
> > > > > `(setf ,x (append ,x ,@lists)))
> > > >
> > > > You should use GET-SETF-EXPANSION to evaluate the subforms of x just
> > > > once. And perhaps DEFINE-MODIFY-MACRO is useful?
> > >
> > > (apropos "DEFINE-MODIFY-MACRO")
> > > "No apropos matches for `DEFINE-MODIFY-MACRO'"
> > >
> > > Emacs Lisp, eh?
> >
> > What is this, a bad joke? Emacs Lisp uses lowercase:
> >
> > ELISP> (apropos "define-modify")
> > ((define-modify-macro "(define-modify-macro NAME ARGLIST FUNC): define a
> `setf'-like modify macro." nil "autoload common-lisp-indent-function" nil
> nil nil))
>
> mmmh, in emacs 21.3 when i evaluate
>
> (apropos "define-modify-macro")
>
> i get the message
>
> ((define-modify-macro "(not documented)" nil nil nil nil nil))
>
> where do you get the little doc-string from?
(Emacs 20.7 on Solaris and Emacs pre-20.3 on Mac OS X)
Do a (require 'cl), then if you M-x apropos define-modify-macro, do
you get a docstring? If not, go ask on gnu.emacs.help, being sure to
mention what platform you're running on, where you got the binaries,
etc., because it sounds like a packaging problem.
--
/|_ .-----------------------.
,' .\ / | No to Imperialist war |
,--' _,' | Wage class war! |
/ / `-----------------------'
( -. |
| ) |
(`-. '--.)
`. )----'