emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#14482: closed (Macro not able to see a function)


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#14482: closed (Macro not able to see a function)
Date: Thu, 30 May 2013 21:24:02 +0000

Your message dated Thu, 30 May 2013 23:21:59 +0200
with message-id <address@hidden>
and subject line Re: bug#14482: Macro not able to see a function
has caused the debbugs.gnu.org bug report #14482,
regarding Macro not able to see a function
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
14482: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=14482
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- Subject: Macro not able to see a function Date: Mon, 27 May 2013 12:51:42 +0200
Hi,

Here is example code:

---------------------------------------

(define (partition-two lst)
  (if (< (length lst) 2)
    '()
    (cons
      (list (car lst) (cadr lst))
      (partition-two (cddr lst)))))

(define-macro (letn bindings . body)
  `(let* ,(partition-two bindings)
     ,@body))

(define (println v)
  (display v)
  (newline))

(println
  (letn (a 3
         b 4
         c 4
         d a
         f (+ a b))
     (+ a b c d f)))

---------------------------------------

It correctly prints result, but I'm getting also:

---------------------------------------
;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
;;;       or pass the --no-auto-compile argument to disable.
;;; compiling /home/sanel/letn.ss
;;; WARNING: compilation of /home/sanel/letn.ss failed:
;;; ERROR: Unbound variable: partition-two
21
---------------------------------------

I'm using guile: 2.1.0.180-9b977-dirty

Best.



--- End Message ---
--- Begin Message --- Subject: Re: bug#14482: Macro not able to see a function Date: Thu, 30 May 2013 23:21:59 +0200 User-agent: Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3 (gnu/linux)
tags 14482 notabug
thanks

Hi,

Sanel Zukan <address@hidden> skribis:

> ---------------------------------------
>
> (define (partition-two lst)
>   (if (< (length lst) 2)
>     '()
>     (cons
>       (list (car lst) (cadr lst))
>       (partition-two (cddr lst)))))
>
> (define-macro (letn bindings . body)
>   `(let* ,(partition-two bindings)
>      ,@body))
>
> (define (println v)
>   (display v)
>   (newline))
>
> (println
>   (letn (a 3
>          b 4
>          c 4
>          d a
>          f (+ a b))
>      (+ a b c d f)))
>
> ---------------------------------------
>
> It correctly prints result, but I'm getting also:
>
> ---------------------------------------
> ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0
> ;;;       or pass the --no-auto-compile argument to disable.
> ;;; compiling /home/sanel/letn.ss
> ;;; WARNING: compilation of /home/sanel/letn.ss failed:
> ;;; ERROR: Unbound variable: partition-two
> 21
> ---------------------------------------

That’s because ‘partition-two’ is only visible at run time, and not at
macro-expansion time.

To fix that, use the ‘eval-when’ form:

--8<---------------cut here---------------start------------->8---
(eval-when (load compile eval)
   (define (partition-two lst)
     (if (< (length lst) 2)
         '()
         (cons
          (list (car lst) (cadr lst))
          (partition-two (cddr lst))))))
--8<---------------cut here---------------end--------------->8---

(BTW, I recommend looking at R5RS ‘syntax-rules’ and R6RS ‘syntax-case’
hygienic macros.)

Ludo’.


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]