unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* macro syntax
@ 2005-10-29 23:38 Aurelien Chanudet
  2005-11-02  8:49 ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: Aurelien Chanudet @ 2005-10-29 23:38 UTC (permalink / raw)


Hi all,

Please consider the following lines of code :

(defmacro-public new-func (f x) `(define (,f) ,x))

(define alist (list (cons "f" 1) (cons "g" 2)))

(define (find-x f) (cdr (assoc f alist)))

(new-func f (find-x "f"))
(new-func g (find-x "g"))

How can I rewrite the macro new-func to factor out find-x in the macro
definition ?

Thanks,
Aurelien


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: macro syntax
  2005-10-29 23:38 macro syntax Aurelien Chanudet
@ 2005-11-02  8:49 ` Ludovic Courtès
  2005-11-02 10:03   ` Aurelien Chanudet
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2005-11-02  8:49 UTC (permalink / raw)
  Cc: guile-user

Hi,

Aurelien Chanudet <aurelien.chanudet@gmail.com> writes:

> (define (find-x f) (cdr (assoc f alist)))

You might want to use `assoc-ref' instead of `find-x'.

> How can I rewrite the macro new-func to factor out find-x in the macro
> definition ?

I don't clearly understand what you mean.  Could you rephrase it?

Thanks,
Ludovic.


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: macro syntax
  2005-11-02  8:49 ` Ludovic Courtès
@ 2005-11-02 10:03   ` Aurelien Chanudet
  0 siblings, 0 replies; 3+ messages in thread
From: Aurelien Chanudet @ 2005-11-02 10:03 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 748 bytes --]

Hi,
 And thanks for your attention.
 I'd like something in the following flavor :
 (define alist (list (cons "f" 1) (cons "g" 2)))
 (defmacro-public new-func (f str) some code here to retrieve x from the
alist given str `(define (,f) ,x))

(new-func f "f")
(new-func g "g")
 On 11/2/05, Ludovic Courtès <ludovic.courtes@laas.fr> wrote:
>
> Hi,
>
> Aurelien Chanudet <aurelien.chanudet@gmail.com> writes:
>
> > (define (find-x f) (cdr (assoc f alist)))
>
> You might want to use `assoc-ref' instead of `find-x'.

 Thanks for the tip !

> How can I rewrite the macro new-func to factor out find-x in the macro
> > definition ?
>
> I don't clearly understand what you mean. Could you rephrase it?
>
> Thanks,
> Ludovic.
>

[-- Attachment #1.2: Type: text/html, Size: 1433 bytes --]

[-- Attachment #2: Type: text/plain, Size: 140 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2005-11-02 10:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-29 23:38 macro syntax Aurelien Chanudet
2005-11-02  8:49 ` Ludovic Courtès
2005-11-02 10:03   ` Aurelien Chanudet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).