GNU bug report logs - #14482
Macro not able to see a function

Previous Next

Package: guile;

Reported by: Sanel Zukan <sanelz <at> gmail.com>

Date: Mon, 27 May 2013 10:54:01 UTC

Severity: normal

Tags: notabug

Done: ludo <at> gnu.org (Ludovic Courtès)

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 14482 in the body.
You can then email your comments to 14482 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#14482; Package guile. (Mon, 27 May 2013 10:54:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Sanel Zukan <sanelz <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Mon, 27 May 2013 10:54:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Sanel Zukan <sanelz <at> gmail.com>
To: bug-guile <at> gnu.org
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.




Reply sent to ludo <at> gnu.org (Ludovic Courtès):
You have taken responsibility. (Thu, 30 May 2013 21:24:02 GMT) Full text and rfc822 format available.

Notification sent to Sanel Zukan <sanelz <at> gmail.com>:
bug acknowledged by developer. (Thu, 30 May 2013 21:24:02 GMT) Full text and rfc822 format available.

Message #10 received at 14482-done <at> debbugs.gnu.org (full text, mbox):

From: ludo <at> gnu.org (Ludovic Courtès)
To: Sanel Zukan <sanelz <at> gmail.com>
Cc: 14482-done <at> debbugs.gnu.org, request <at> debbugs.gnu.org
Subject: Re: bug#14482: Macro not able to see a function
Date: Thu, 30 May 2013 23:21:59 +0200
tags 14482 notabug
thanks

Hi,

Sanel Zukan <sanelz <at> gmail.com> 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’.




Added tag(s) notabug. Request was from ludo <at> gnu.org (Ludovic Courtès) to control <at> debbugs.gnu.org. (Thu, 30 May 2013 21:24:03 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 28 Jun 2013 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 361 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.