* Help to TeXmacs with Guile 2
@ 2014-06-01 4:16 Germán Arias
2014-06-01 17:54 ` David Pirotte
0 siblings, 1 reply; 4+ messages in thread
From: Germán Arias @ 2014-06-01 4:16 UTC (permalink / raw)
To: Guile
Hi,
I don't have experience with macros. But I get this error trying TeXmacs with Guile 2.x:
ERROR: Syntax error:
;;; kernel/boot/boot.scm:57:4: definition in expression context, where definitions are not allowed, in form (define-syntax define-public-macro (lambda (y) #f #((macro-type . defmacro) (defmacro-args args)) (syntax-case y () ((_ . args) (let ((v (syntax->datum (syntax args)))) (datum->syntax y (apply (lambda (head . body) (quasiquote (define-public (unquote (car head)) (procedure->memoizing-macro (lambda (cmd env) (apply (lambda (unquote (cdr head)) (unquote-splicing body)) (cdr cmd))))))) v)))))))
The offending code is:
(if (guile-a?)
(define-macro (define-public-macro head . body)
`(define-public ,(car head)
;; FIXME: why can't we use procedure->macro
;; for a non-memoizing variant?
(procedure->memoizing-macro
(lambda (cmd env)
(apply (lambda ,(cdr head) ,@body) (cdr cmd)))))))
Any advice? Thanks.
Germán.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Help to TeXmacs with Guile 2
[not found] <mailman.89.1401638430.28681.guile-user@gnu.org>
@ 2014-06-01 16:58 ` Artyom Poptsov
0 siblings, 0 replies; 4+ messages in thread
From: Artyom Poptsov @ 2014-06-01 16:58 UTC (permalink / raw)
To: guile-user
Hi German,
> I don't have experience with macros. But I get this error trying
> TeXmacs with Guile 2.x:
I think the problem is that you trying to define a macro in a context in
which definitions are not allowed. Here what the Guile docs says:
"A ‘define-syntax’ form is valid anywhere a definition may appear: at
the top-level, or locally." [1]
"A ‘define’ form which appears inside the body of a ‘lambda’, ‘let’,
‘let*’, ‘letrec’, ‘letrec*’ or equivalent expression is called an
"internal definition". [..] Internal definitions are only allowed at
the beginning of the body of an enclosing expression. They may not be
mixed with other expressions." [2]
It means that you should define the macro either in the top level
context (outside any define's, let's etc) or at the beginning of a local
binding contruct like `let', `letrec' etc.
I hope this helps.
Thanks,
- Artyom
[1] https://www.gnu.org/software/guile/manual/html_node/Defining-Macros.html#Defining-Macros
[2] https://www.gnu.org/software/guile/manual/html_node/Internal-Definitions.html#Internal-Definitions
--
Artyom V. Poptsov <poptsov.artyom@gmail.com>
Home page: http://poptsov-artyom.narod.ru/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Help to TeXmacs with Guile 2
2014-06-01 4:16 Help to TeXmacs with Guile 2 Germán Arias
@ 2014-06-01 17:54 ` David Pirotte
2014-06-02 5:14 ` Germán Arias
0 siblings, 1 reply; 4+ messages in thread
From: David Pirotte @ 2014-06-01 17:54 UTC (permalink / raw)
To: germanandre; +Cc: Guile
Hello Germán,
> (if (guile-a?)
> (define-macro (define-public-macro head . body)
> `(define-public ,(car head)
> ;; FIXME: why can't we use procedure->macro
> ;; for a non-memoizing variant?
> (procedure->memoizing-macro
> (lambda (cmd env)
> (apply (lambda ,(cdr head) ,@body) (cdr cmd)))))))
For these guile version related code, I suggest something like this:
(cond-expand
(guile-2
... ...)
(else
(define-macro (unless test . body)
`(if (not ,test) (begin ,@body)))
(export unless))))
Here is a real case example [which starts @ line 44]:
http://git.savannah.gnu.org/cgit/guile-gnome.git/tree/glib/gnome/gobject/utils.scm
Cheers,
David
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Help to TeXmacs with Guile 2
2014-06-01 17:54 ` David Pirotte
@ 2014-06-02 5:14 ` Germán Arias
0 siblings, 0 replies; 4+ messages in thread
From: Germán Arias @ 2014-06-02 5:14 UTC (permalink / raw)
To: David Pirotte; +Cc: Guile
On 2014-06-01 11:54:13 -0600 David Pirotte <david@altosw.be> wrote:
> Hello Germán,
>
>> (if (guile-a?)
>> (define-macro (define-public-macro head . body)
>> `(define-public ,(car head)
>> ;; FIXME: why can't we use procedure->macro
>> ;; for a non-memoizing variant?
>> (procedure->memoizing-macro
>> (lambda (cmd env)
>> (apply (lambda ,(cdr head) ,@body) (cdr cmd)))))))
>
> For these guile version related code, I suggest something like this:
>
> (cond-expand
> (guile-2
> ... ...)
> (else
> (define-macro (unless test . body)
> `(if (not ,test) (begin ,@body)))
> (export unless))))
>
> Here is a real case example [which starts @ line 44]:
>
> http://git.savannah.gnu.org/cgit/guile-gnome.git/tree/glib/gnome/gobject/utils.scm
>
> Cheers,
> David
>
>
Thanks for the answers. I solved this problem, although now I have other problems. I will try to solve them, if not I request again your help.
Germán.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-06-02 5:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-01 4:16 Help to TeXmacs with Guile 2 Germán Arias
2014-06-01 17:54 ` David Pirotte
2014-06-02 5:14 ` Germán Arias
[not found] <mailman.89.1401638430.28681.guile-user@gnu.org>
2014-06-01 16:58 ` Artyom Poptsov
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).