unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#18245: [master branch] Useless imported module cause strange problem
@ 2014-08-11  9:14 Nala Ginrut
  2014-08-11 15:30 ` Mark H Weaver
  0 siblings, 1 reply; 3+ messages in thread
From: Nala Ginrut @ 2014-08-11  9:14 UTC (permalink / raw)
  To: 18245

[-- Attachment #1: Type: text/plain, Size: 636 bytes --]

Note this bug is under Master branch, it's fine in stable-2.0.


I've imported srfi-1, but after some modifications, the program happens
not to use any srfi-1 symbols, then there's the problem that one of the
rule in syntax-rules can't be found and threw error.
It works when I removed useless srfi-1 from imported list.


I think srfi-1 here is not related, and maybe the same with
syntax-rules. But I can reproduce it with these two prerequisites.


I've attached two simplified files(modules) for reproducing.
(The code may look not so nice, but it's unrelated, some code looks ugly
because of the simplification from my project)




[-- Attachment #2: mmr.scm --]
[-- Type: text/x-scheme, Size: 1274 bytes --]

(define-module (xxx mmr)
  #:export (->sql2))

(define-syntax ->
  (syntax-rules (end)
    ((_ end fmt args ...)
     (format #f "~@?;" fmt args ...))
    ((_ fmt args ...)
     (format #f fmt args ...))))

(define-syntax-rule (->end name arg)
  (-> end "~a ~a" name arg))

(define-syntax sql-alter
  (syntax-rules (table rename to add modify drop column as select
                 primary key)
    ((_ table name drop primary key)
     (-> "table ~a drop primary key" name))
    ((_ table old-name rename to new-name)
     (-> "table ~a rename to ~a" old-name new-name))
    ((_ table name add cname ctype) 
     ;; e.g: (->sql alter table 'mmr add 'cname 'varchar(50))
     (-> "table ~a add ~a ~a" cname ctype))
    ((_ table name mofify pairs)
     (-> "table ~a modify (~{~a~^,~})" name (->lst pairs)))
    ((_ table name drop column cname)
     (-> "table ~a drop column ~a" name cname))
    ((_ table name add primary key keys)
     (-> "table ~a add primary key (~{~a~^,~})" name keys))
    ((_ table name rename column old-name to new-name)
     (-> "table ~a rename column ~a to ~a" name old-name new-name))))

(define-syntax ->sql2
  (syntax-rules (select insert alter create update delete use)
    ((_ alter rest ...)
     (->end 'alter (sql-alter rest ...)))))

[-- Attachment #3: mmr2.scm --]
[-- Type: text/x-scheme, Size: 157 bytes --]

(define-module (xxx mmr2)
  #:use-module (xxx mmr)
  #:use-module (srfi srfi-1)
  #:export (mmr))

(define mmr (->sql2 alter table 'tname drop primary key))

^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#18245: [master branch] Useless imported module cause strange problem
  2014-08-11  9:14 bug#18245: [master branch] Useless imported module cause strange problem Nala Ginrut
@ 2014-08-11 15:30 ` Mark H Weaver
  2014-08-12  1:46   ` Nala Ginrut
  0 siblings, 1 reply; 3+ messages in thread
From: Mark H Weaver @ 2014-08-11 15:30 UTC (permalink / raw)
  To: Nala Ginrut; +Cc: 18245, request

tags 18245 notabug
close 18245
thanks

Nala Ginrut <nalaginrut@gmail.com> writes:
> I've imported srfi-1, but after some modifications, the program happens
> not to use any srfi-1 symbols, then there's the problem that one of the
> rule in syntax-rules can't be found and threw error.
> It works when I removed useless srfi-1 from imported list.

The problem is that srfi-1 exports a 'drop' procedure, and 'drop' is
also used as a syntax-rules literal in your macros.  Literals are
matched as follows: if the literal identifier has the same name and the
same binding where the macro is defined and where it is used, then
there's a match.  If the identifier is not bound in either place, then
there's also a match.

However, in this case 'drop' is not defined where the 'sql-alter' macro
is defined, but it _is_ defined to a procedure in srfi-1 in your example
module where it is used.  Therefore, the macro does not consider the
'drop' to be a match for the literal it's looking for.

This is similar to the issue that if you define 'else' to be something
in a module (or import it from somewhere), then 'else' will no longer
have its special meaning in a 'cond' form.  Ditto for '=>'.

There is some question about whether these rules for matches literals
are the best ones, and the issue has been debated during the R7RS
standardization process, but nonetheless the standards are clear on this
matter.

I recommend choosing literals that are not likely to be bound in modules
that use your sql macros.

I'm closing this.

     Regards,
       Mark





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#18245: [master branch] Useless imported module cause strange problem
  2014-08-11 15:30 ` Mark H Weaver
@ 2014-08-12  1:46   ` Nala Ginrut
  0 siblings, 0 replies; 3+ messages in thread
From: Nala Ginrut @ 2014-08-12  1:46 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: 18245, request

[-- Attachment #1: Type: text/plain, Size: 797 bytes --]

2014年8月11日 下午11:31于 "Mark H Weaver" <mhw@netris.org>写道:
>
> tags 18245 notabug
> close 18245
> thanks
>

> The problem is that srfi-1 exports a 'drop' procedure, and 'drop' is
> also used as a syntax-rules literal in your macros.  Literals are
> matched as follows: if the literal identifier has the same name and the
> same binding where the macro is defined and where it is used, then
> there's a match.  If the identifier is not bound in either place, then
> there's also a match.
>

Thanks for explaining!
The issue can't be reproduced in stable-2.0, so I suspected it's a
potential bug.

>
> I recommend choosing literals that are not likely to be bound in modules
> that use your sql macros.
>

Or import srfi-1 with a proper prefix :-)

Thanks!

[-- Attachment #2: Type: text/html, Size: 1090 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-08-12  1:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-11  9:14 bug#18245: [master branch] Useless imported module cause strange problem Nala Ginrut
2014-08-11 15:30 ` Mark H Weaver
2014-08-12  1:46   ` Nala Ginrut

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).