GNU bug report logs -
#14482
Macro not able to see a function
Previous Next
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.
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):
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):
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.