loop with different variables

6 views
Skip to first unread message

ole

unread,
Oct 4, 2013, 4:30:46 AM10/4/13
to symbolic...@googlegroups.com
Hi,

I just discovered that I can use setf to place an element inside a list:

(setq numbers '(1 2 3 4 5 6))
(setf (nth 5 numbers) 99)
numbers
-->(1 2 3 4 5 99)
(setf (nth 1 numbers) 55)
numbers
-->(1 55 3 4 5 99)

So I need to write a function who is working through two lists in parallel (place of the new item (nth number) and value of the new item). How can I do that?

thanks!

ole



pstone imap

unread,
Oct 4, 2013, 9:43:46 AM10/4/13
to symbolic...@googlegroups.com
Try this:

(setq numbers '(1 2 3 4 5 6))

(mapcar #'(lambda (x y)
            (setf (nth x numbers) y))
        '(5 1)
        '(99 55))


numbers
--> (1 55 3 4 5 99)


Peter
--
You received this message because you are subscribed to the Google Groups "Symbolic Composer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to symboliccompos...@googlegroups.com.
To post to this group, send email to symbolic...@googlegroups.com.
Visit this group at http://groups.google.com/group/symboliccomposer.
For more options, visit https://groups.google.com/groups/opt_out.

ole

unread,
Oct 4, 2013, 2:41:32 PM10/4/13
to symbolic...@googlegroups.com
Thanks! That is very very close to what I figured out myself- I'am still looking for sources to become better in lisp, so if you have any recommandations- I would also buy a book or following a course..

ole
Reply all
Reply to author
Forward
0 new messages