define-syntax with two-dimensional ellipsis

45 views
Skip to first unread message

ceving

unread,
Mar 9, 2017, 12:30:33 PM3/9/17
to chibi-scheme
I have the following macro

(define-syntax define-facts
  (syntax-rules ()
    ((_ (name a0 a1 ...) (v00 v01 ...) (v10 v11 ...) ...)
     '(define (name a0 a1 ...)
        (conde
          ((== a0 v00) (== a1 v01) ...)
          ((== a0 v10) (== a1 v11) ...)
          ...)))))

When I use it with the following data

(define-facts (fathero f c)
  ("Abraham" "Ismael")
  ("Abraham" "Isaac")
  ("Isaac"   "Jacob")
  ("Jacob"   "Benjamin"))

Guile 2.0.9 fulfills my expectation and returns

(define (fathero f c) (conde ((== f "Abraham") (== c "Ismael")) ((== f "Abraham") (== c "Isaac")) ((== f "Isaac") (== c "Jacob")) ((== f "Jacob") (== c "Benjamin"))))

But Chibi 0.7.3 does not carry out the last ellipsis:

(define (fathero f c) (conde ((== f "Abraham") (== c "Ismael")) ((== f "Abraham") (== c "Isaac"))))

Is it a bug?

ceving

unread,
Mar 10, 2017, 3:55:05 AM3/10/17
to chibi-scheme
The macro seems to be a bit controversial.

Gauche fails like Chibi.
Petite Chez succeeds.
Chicken fails with an error.
Gambit fails with an error.
MIT-Scheme succeeds.
Ikarus succeeds.
Scheme48 fails with an error.

Alex Shinn

unread,
Mar 10, 2017, 7:46:39 PM3/10/17
to chibi-...@googlegroups.com
This is illegal according to R7RS 4.3.2:

  Pattern variables that occur in subpatterns followed by one or more
  instances of the identifier ellipsisare allowed only in subtemplates
  that are followed by as many instances of ellipsis.

SRFI 149 proposes to relax this restriction, but Al* Petrofksy
points out that the resulting semantics are not well defined in
http://srfi-email.schemers.org/srfi-149/msg/5375889.  We could
choose and specify the semantics, but I'm not sure there is
a definition that will work intuitively in all cases.

-- 
Alex

--
You received this message because you are subscribed to the Google Groups "chibi-scheme" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chibi-scheme+unsubscribe@googlegroups.com.
To post to this group, send email to chibi-...@googlegroups.com.
Visit this group at https://groups.google.com/group/chibi-scheme.
For more options, visit https://groups.google.com/d/optout.

ceving

unread,
Mar 11, 2017, 5:22:37 PM3/11/17
to chibi-scheme


Am Samstag, 11. März 2017 01:46:39 UTC+1 schrieb Alex Shinn:

SRFI 149 proposes to relax this restriction, but Al* Petrofksy
points out that the resulting semantics are not well defined in
http://srfi-email.schemers.org/srfi-149/msg/5375889.  We could
choose and specify the semantics, but I'm not sure there is
a definition that will work intuitively in all cases.


Maybe it is necessary to label the ellipsis to specify which belong together.

(define-syntax foo2
 
(syntax-rules ()
   
((foo2 (axis ...) (coordinate ...) :::)
     
'(((axis coordinate) ...) :::))))

(foo2 (x y) (1 2) (3 4))
=> (((x 1) (y 2))
    ((x 3) (y 4)))

(define-syntax foo2
  (syntax-rules ()
    ((foo2 (axis :::) (coordinate ...) :::)
     '
(((axis coordinate) ...) :::))))

(foo2 (x y) (1 2) (3 4))
=> (((x 1) (x 2))
   
((y 3) (y 4)))




Reply all
Reply to author
Forward
0 new messages