Google Groups Home
Help | Sign in
Message from discussion Beginner question
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Andreas Thiele  
View profile
 More options Jan 31 2005, 9:48 am
Newsgroups: comp.lang.lisp
From: "Andreas Thiele" <nos...@nospam.com>
Date: Mon, 31 Jan 2005 15:48:45 +0100
Local: Mon, Jan 31 2005 9:48 am
Subject: Re: Beginner question

"Yoel Jacobsen" <y...@emet.co.il> schrieb im Newsbeitrag
news:ctl89r$mr5$1@news2.netvision.net.il...

> Andreas,

> Thanks! Yet, I still would like to know what went wrong so I wouldn't
> repeat it in the future.

Yoel,

you can define the following macro to see what is going on:

(defmacro test1 (x) `(identity ,x))

Now my lisp answers:

CL-USER 43 > (macroexpand '(test1 '(1 2)))
(IDENTITY (QUOTE (1 2)))
T

You might also write:

(defmacro test2 (x)
  `(format t "~s" ,(format nil "~s" x)))

to see what x contains within a comma expression:

CL-USER 46 : 1 > (test2 '(1 2))
"(QUOTE (1 2))"
NIL

Thus you have (at least) two possible solutions:

(defmacro list-to-plist (plist pos-list id-list field-list)
  `(progn ,@(map 'list
                 #'(lambda (id pos)
                     `(setf (getf ,id-list ,id) (elt ,field-list ,pos)))
                 `(,@(cadr plist))
                 `(,@(cadr pos-list))
                 )))

Notice: argument to getf changed. Your function pline-to-plist remains
unchanged.

Second possiblity:

(defmacro list-to-plist (plist pos-list id-list field-list)
  `(progn ,@(map 'list
                 #'(lambda (id pos)
                     `(setf (getf ,id-list ,id) (elt ,field-list ,pos)))
                 plist
                 pos-list)))

(defun pline-to-plist (line)
   "convert a passwd line to a plist"
   (let ((fields (split-sequence:split-sequence #\: line))
                 (entry nil))
     (list-to-plist
       (:login :passwd :uid :gid :group :home :shell)
       (0 1 2 3 4 5 6 7)
       entry fields)
     entry))

Notice: the quotes in pline-to-plist are gone.

I'd utterly agree to Kenny. Lisp is different! At least for me. For most
other languages I roughly browsed a nice book.  To explore its strength Lisp
needs studying literature. Here are some suggestions:

http://www.alu.org is a good starting point.
http://www.gigamonkeys.com/book is great compact and easy to read (my
opinion)
http://www.paulgraham.com/onlisp.html is a standard

Hope this helps a bit further.

Andreas


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google