[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: defining a setter function with gv.el
From: |
Ivan Kanis |
Subject: |
Re: defining a setter function with gv.el |
Date: |
Thu, 30 Aug 2012 18:05:07 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) |
Hi Stefan,
As I was trying to make sense of it I tried the following in my
*scratch* buffer:
(setq lexical-binding t)
(defun alist-get (key alist)
"Get the value associated to KEY in ALIST."
(declare
(gv-expander
(lambda (do)
(macroexp-let2 macroexp-copyable-p k key
(gv-letplace (getter setter) alist
(macroexp-let2 nil p `(assoc ,k ,getter)
(funcall do `(cdr ,p)
(lambda (v)
`(if ,p (setcdr ,p ,v)
,(funcall setter
`(cons (cons ,k ,v) ,getter))))))))))))
(setq foo '((bar . foo) (baz . qux)))
(alist-get 'bar foo) => "Get the value associated to KEY in ALIST."
It's as if everything in declare was not evaluated. Where did I err?
Stefan Monnier <address@hidden> wrote:
> and the code we want to generate for a `setf' is along the lines of:
>
> (let* ((k KEY)
> (a ALIST)
> (p (assoc k (alist-getter a)))
> (v VAL))
> (if p (setcdr p v)
> (alist-setter a (cons (cons k v) (alist-getter a)))))
Yes this is what needs to be generated. I don't understand why there
are two lambdas in alist-get. There is no map type function so I don't
understand what they do.
Is there any chance you would uncomment this function so that I can use
it in my code?
Take care,
--
Ivan Kanis
http://ivan.kanis.fr
History is a gallery of pictures in which there are few original and
many copies.
-- Alexis de Tocqueville
- Re: defining a setter function with gv.el,
Ivan Kanis <=