* Macro expansion: unknown location
@ 2014-06-10 20:16 Dmitry Bogatov
2014-06-11 13:31 ` Ludovic Courtès
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Bogatov @ 2014-06-10 20:16 UTC (permalink / raw)
To: guile-user
[-- Attachment #1: Type: text/plain, Size: 1485 bytes --]
Hello!
Here is very simple code with error (lines numbered with `cat -n`)
1 ;(read-enable 'copy)
2
3 (define-syntax zero!
4 (lambda (x)
5 (syntax-case x ()
6 ((_ var)
7 (begin
8 (unless (identifier? #'var)
9 (syntax-violation 'zero! "identifier expected" #'var))
10 #'(set! var 0))))))
11
12 (zero! #f)
Trying to run or compile it of course leads to error, but it says
nothing about offending expression.
ice-9/boot-9.scm:106:20: In procedure #<procedure e1f4c0 at ice-9/boot-9.scm:97:6 (thrown-k . args)>:
ice-9/boot-9.scm:106:20: Syntax error:
unknown location: zero!: identifier expected
In this example `syntax-violation` is not actually needed, guard would
suffice. But if guard fails, I get "do not match pattern error" without
any clues what expectation I violated, and I found myself writing macros
compicated enough, that I want detailed description.
(read-enable 'positions) did not helped.
(read-enable 'copy) (commented line 1) cause Guile to hang.
When called from repl (load "foo.scm") repl hangs and do not respond
to ^C.
guile (GNU Guile) 2.0.9
Linux localhost 3.14.0-gnu #8 SMP Sat Apr 12 11:56:49 MSK 2014 x86_64 Intel(R) Core(TM) i7 CPU Q 740 @ 1.73GHz GenuineIntel GNU/Linux
Any suggestions or workarounds?
--
Best regards, Dmitry Bogatov <KAction@gnu.org>,
Free Software supporter, esperantisto and netiquette guardian.
git://kaction.name/rc-files.git
GPG: 54B7F00D
[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Macro expansion: unknown location
2014-06-10 20:16 Macro expansion: unknown location Dmitry Bogatov
@ 2014-06-11 13:31 ` Ludovic Courtès
2014-06-14 18:21 ` Mark H Weaver
0 siblings, 1 reply; 5+ messages in thread
From: Ludovic Courtès @ 2014-06-11 13:31 UTC (permalink / raw)
To: guile-user
A workaround is to get location info from the outer syntax object ‘x’:
--8<---------------cut here---------------start------------->8---
(define-syntax zero!
(lambda (x)
(syntax-case x ()
((_ var)
(begin
(unless (identifier? #'var)
(syntax-violation 'zero! "identifier expected" x)) ; <-- here
#'(set! var 0))))))
--8<---------------cut here---------------end--------------->8---
I’m not sure why ‘var’ has no location info.
Ludo’.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Macro expansion: unknown location
2014-06-11 13:31 ` Ludovic Courtès
@ 2014-06-14 18:21 ` Mark H Weaver
2014-06-14 22:45 ` Mark H Weaver
0 siblings, 1 reply; 5+ messages in thread
From: Mark H Weaver @ 2014-06-14 18:21 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-user
ludo@gnu.org (Ludovic Courtès) writes:
> A workaround is to get location info from the outer syntax object ‘x’:
>
> (define-syntax zero!
> (lambda (x)
> (syntax-case x ()
> ((_ var)
> (begin
> (unless (identifier? #'var)
> (syntax-violation 'zero! "identifier expected" x)) ; <-- here
> #'(set! var 0))))))
>
> I’m not sure why ‘var’ has no location info.
Currently, Guile stores location info using a weak-key hash table, keyed
on the datums read from the file. This means that location info cannot
be stored for bare symbols or other immediate values (booleans,
characters, small exact integers).
I intend to fix this at some point, but it entails using a reader with a
different API than the standard reader. The new reader would have to
return symbols and immediates wrapped in some other data type.
Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Macro expansion: unknown location
2014-06-14 18:21 ` Mark H Weaver
@ 2014-06-14 22:45 ` Mark H Weaver
2014-06-15 21:08 ` Dmitry Bogatov
0 siblings, 1 reply; 5+ messages in thread
From: Mark H Weaver @ 2014-06-14 22:45 UTC (permalink / raw)
To: Ludovic Courtès; +Cc: guile-user
Mark H Weaver <mhw@netris.org> writes:
> Currently, Guile stores location info using a weak-key hash table, keyed
> on the datums read from the file. This means that location info cannot
> be stored for bare symbols or other immediate values (booleans,
> characters, small exact integers).
Symbols are not immediate values, so I shouldn't have written "other".
However, because they are interned, they behave like immediates in the
following sense: 'read' returns the same (by 'eq?') object for any two
occurrences of a given symbol. Therefore, there's no way to associate
source location information with each copy of the same symbol.
Mark
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Macro expansion: unknown location
2014-06-14 22:45 ` Mark H Weaver
@ 2014-06-15 21:08 ` Dmitry Bogatov
0 siblings, 0 replies; 5+ messages in thread
From: Dmitry Bogatov @ 2014-06-15 21:08 UTC (permalink / raw)
To: Mark H Weaver; +Cc: Ludovic Courtès, guile-user
[-- Attachment #1: Type: text/plain, Size: 871 bytes --]
* Mark H Weaver <mhw@netris.org> [2014-06-14 18:45:59-0400]
> > Currently, Guile stores location info using a weak-key hash table, keyed
> > on the datums read from the file. This means that location info cannot
> > be stored for bare symbols or other immediate values (booleans,
> > characters, small exact integers).
>
> Symbols are not immediate values, so I shouldn't have written "other".
>
> However, because they are interned, they behave like immediates in the
> following sense: 'read' returns the same (by 'eq?') object for any two
> occurrences of a given symbol. Therefore, there's no way to associate
> source location information with each copy of the same symbol.
Thanks for clarification.
--
Best regards, Dmitry Bogatov <KAction@gnu.org>,
Free Software supporter, esperantisto and netiquette guardian.
git://kaction.name/rc-files.git
GPG: 54B7F00D
[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-06-15 21:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-10 20:16 Macro expansion: unknown location Dmitry Bogatov
2014-06-11 13:31 ` Ludovic Courtès
2014-06-14 18:21 ` Mark H Weaver
2014-06-14 22:45 ` Mark H Weaver
2014-06-15 21:08 ` Dmitry Bogatov
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).