From: Cecil Westerhof on
I made a function to set a property in a list. My definition is that
when the property not already exists that it is an error. (I have to
make also a function create-property-in-list.) There needs to be more
error checking: are property-1 and property-2 really keywords, and it
has to be made more general (now it works only for dept 2, it should
work for every -reasonable- dept). But before I continue I would like to
know if I am on the right track, or should better it implement
differently?

The function:
(defun set-property-in-list(this-list value property-1 property-2)
(let ((sub-list)
(property-value))
(setq sub-list (getf this-list property-1)
property-value (getf sub-list property-2))
(if (not property-value)
(format nil "Tried to change a non-existing property")
(progn (setf (getf sub-list property-2) value)
nil))))

When successful I return nil, so it can be checked if everything went
alright.

Setting a variable to test it:
(setq dummy (list :expire (list :idle 3
:wait 1438)
:get-news (list :idle 2
:wait 29)))

Changing an existing property:
(format t "~a~%" (set-property-in-list dummy 'testing :expire :idle))

And changing a non existing property (gives a error message back):
(format t "~a~%" (set-property-in-list dummy 'testing :expire
:idle))

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
From: Kyle M on
On Dec 21, 7:56 am, Cecil Westerhof <Ce...(a)decebal.nl> wrote:
> I made a function to set a property in a list. My definition is that
> when the property not already exists that it is an error. (I have to
> make also a function create-property-in-list.) There needs to be more
> error checking: are property-1 and property-2 really keywords, and it
> has to be made more general (now it works only for dept 2, it should
> work for every -reasonable- dept). But before I continue I would like to
> know if I am on the right track, or should better it implement
> differently?
>
> The function:
>     (defun set-property-in-list(this-list value property-1 property-2)
>       (let ((sub-list)
>             (property-value))
>         (setq sub-list       (getf this-list  property-1)
>               property-value (getf sub-list property-2))
>         (if (not property-value)
>             (format nil "Tried to change a non-existing property")
>             (progn (setf (getf sub-list property-2) value)
>                    nil))))
>
> When successful I return nil, so it can be checked if everything went
> alright.
>
> Setting a variable to test it:
>     (setq dummy (list :expire   (list :idle 3
>                                       :wait 1438)
>                       :get-news (list :idle 2
>                                       :wait 29)))
>
> Changing an existing property:
>     (format t "~a~%" (set-property-in-list dummy 'testing :expire :idle))
>
> And changing a non existing property (gives a error message back):
>     (format t "~a~%" (set-property-in-list dummy 'testing :expire
>     :idle))
>
> --
> Cecil Westerhof
> Senior Software Engineer
> LinkedIn:http://www.linkedin.com/in/cecilwesterhof


>(set-property-in-list dummy nil :expire :idle)
nil
>(set-property-in-list dummy t :expire :idle)
"Tried to change a non-existing property"

Hmm... The spec says: "There is no way (using getf) to distinguish an
absent property from one whose value is default; but see get-
properties."

http://www.franz.com/support/documentation/current/ansicl/dictentr/getf.htm
From: Pascal Costanza on
On 21/12/2009 13:56, Cecil Westerhof wrote:
> I made a function to set a property in a list. My definition is that
> when the property not already exists that it is an error.

Why do you want it to behave like that? What problem does this solve?
What do you want to do with this?


Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
From: Cecil Westerhof on
Kyle M <kylemcg(a)gmail.com> writes:

> Hmm... The spec says: "There is no way (using getf) to distinguish an
> absent property from one whose value is default; but see get-
> properties."

When a property does not exist, nil is returned. My assumption is that
every property has a non nil value. When I want to check for real
because nil values are allowed, then after getting nil the getf has to
be done with a non nil value. If it is still nil, the property
exist. ;-]

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof
From: Cecil Westerhof on
Pascal Costanza <pc(a)p-cos.net> writes:

> On 21/12/2009 13:56, Cecil Westerhof wrote:
>> I made a function to set a property in a list. My definition is that
>> when the property not already exists that it is an error.
>
> Why do you want it to behave like that? What problem does this solve?
> What do you want to do with this?

Twofold. I want to learn Lisp, and I want some useful functionality.

I am working with Emacs (that is how I came to lisp) and in Emacs I also
use GNUS. I made a daemon function to expire articles and fetch articles
in idle time. For this I have defined:
(defvar gnus-wait-times
(list :expire (list :idle 3
:wait (- (/ +seconds-in-day+ +seconds-in-minute+) 2))
:get-news (list :idle 2
:wait 29))
"Values for check in the idle daemon")

I want to expire articles once a day and only when Emacs has been idle
for at least 3 minutes. Getting news (newsgroup messages and e-mail) I
want every 30 minutes and only when Emacs has been idle for at least two
minutes. (Getting news takes a lot less time as expiring articles. I use
29 minutes, because fetching articles takes some time, but less as a
minute.)

But say for example that I expect an important message. Then maybe I
want the getting of the news done every ten minutes, and find do I find
an idle time of one minute enough before checking the news. So I need to
change the values. But when I make an input error and use :wiat instead
of :wait, then the value is not changed, but a new value created. That
is what I do not want. Also I think in general you can better have a
check to much, then a check to less. That is why I want another function
for creating properties. Another possibility would be of-course an extra
parameter that signals that the not existing of the property is not an
error.

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof