From: ········@gmail.com
Subject: Learning lisp by doing, but stuck on something simple...
Date: 
Message-ID: <1156910722.322788.123160@i42g2000cwa.googlegroups.com>
Hi all,

Sorry to bother you - if you hate n00b stuff don't read further.

I'm writing a simple application that must read/modify/write
s-expressions, the obvious technology is Lisp (although a version was
written in Python).

At the moment I have reading/writing completed, but I'm stuck on
modifying a value from a p-list.  My current function looks like:

;;; modify a value
(defun modify-value (field value)
  (setf *config*
	(mapcar
	 #'(lambda (x) (if (equal field x)
			   (setf (getf x field) value) <-- this is the problem
			   x))
	 *config*)))

Now I can simply overwrite any value by using (setf x value), but that
means that I overwrite the key from my p-list, not the value pointed to
by the key (ie (setf (:stuff) :test) - not what I'm after)

(getf :stuff *config*) is currently breaking with 'GETF: A proper list
must not end with :STUFF'

Any help would be appreciated.

Thanks,
Kev

envirnoment :lispbox 0.7

From: Jack Unrue
Subject: Re: Learning lisp by doing, but stuck on something simple...
Date: 
Message-ID: <ij5af21cui5ql6nopous8g05h8gpo66qmb@4ax.com>
On 29 Aug 2006 21:05:22 -0700, ·········@gmail.com" <········@gmail.com> wrote:
>
> At the moment I have reading/writing completed, but I'm stuck on
> modifying a value from a p-list.  My current function looks like:

The following illustrates what you are trying to do,
but directly using SETF of GETF

[1]> (defvar *config* '(a 1 b 2))
*CONFIG*
[2]> *config*
(A 1 B 2)
[3]> (setf (getf *config* 'a) 100)
100
[4]> *config*
(A 100 B 2)

See http://www.lispworks.com/reference/HyperSpec/Body/f_getf.htm

and http://gigamonkeys.com/book/beyond-lists-other-uses-for-cons-cells.html

-- 
Jack Unrue
From: Jack Unrue
Subject: Re: Learning lisp by doing, but stuck on something simple...
Date: 
Message-ID: <1h7bf2p347ni25gvhtdveb7fnd6i487nkr@4ax.com>
On Wed, 30 Aug 2006 04:46:37 GMT, Jack Unrue <·······@example.tld> wrote:

> On 29 Aug 2006 21:05:22 -0700, ·········@gmail.com" <········@gmail.com> wrote:
> >
> > At the moment I have reading/writing completed, but I'm stuck on
> > modifying a value from a p-list.  My current function looks like:
> 
> The following illustrates what you are trying to do,
> but directly using SETF of GETF
> 
> [1]> (defvar *config* '(a 1 b 2))

Bad programmer, no cookie! I shouldn't have used a
literal value.

-- 
Jack Unrue