syntax-rules not accepting #(<pattern> ...)

16 views
Skip to first unread message

Duy Nguyen

unread,
Mar 7, 2020, 4:28:27 AM3/7/20
to chibi-...@googlegroups.com
In r7rs-small, 4.3.2 lists these as accaptable patterns

#(<pattern> ...)
#(<pattern> ... <pattern> <ellipsis> <pattern> ...)

but when I tried using #() pattern with chibi it failed, example below.

Do I read the spec wrong, or should chibi support these patterns (and
probably templates too)?

---
(import (scheme base) (scheme write))

(define-syntax huh
(syntax-rules ()
(#(_ test body) (if test body))))

(huh #t (display "he\n"))
---

--
Duy

Alex Shinn

unread,
Mar 7, 2020, 8:58:55 PM3/7/20
to chibi-...@googlegroups.com
Do other schemes support this?  I don't believe it is intended to support vectors as a top-level pattern.

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/CACsJy8ALNM-SV192vAvxfA3h60i%2BzXw%3DaQ93%2BvhfjFOg27iGYg%40mail.gmail.com.

John Cowan

unread,
Mar 7, 2020, 9:10:04 PM3/7/20
to chibi-...@googlegroups.com
FWIW, when I asked why vectors are allowed in patterns at all, the answer was "So that `#(10 ,foo 20)" works.  Which in Chibi it does.

Alex Shinn

unread,
Mar 8, 2020, 12:02:16 AM3/8/20
to chibi-...@googlegroups.com
Actually, this is a grey area that only applies to R5RS, in which a raw, unquoted vector in the source code is unspecified.  In R7RS it is implicitly quoted, i.e. #(a b c) means the same as '#(a b c), so it is not possible for `a' to be interpreted as a macro.

--
Alex

Duy Nguyen

unread,
Mar 8, 2020, 12:21:20 AM3/8/20
to chibi-...@googlegroups.com
I tried chibi first because it looked new to me and chibi is the r7rs
reference implementation. At least Gauche does not accept it either.

Vectors as subpatterns work well on both. Perhaps we should add this
to r7rs errata if vectors are not meant to be top-level patterns.
> To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/CAMMPzYOT1OaPRH4jf12LX7QudKSH4WvoA2G%2BEU9gsx-J9o284Q%40mail.gmail.com.



--
Duy

Alex Shinn

unread,
Mar 8, 2020, 5:07:31 AM3/8/20
to chibi-...@googlegroups.com
No errata is needed as this case never happens due to the implicit quoting rule. 

2020年3月8日(日) 14:21 Duy Nguyen <pcl...@gmail.com>:

Marc Nieper-Wißkirchen

unread,
Apr 17, 2020, 3:03:58 AM4/17/20
to chibi-scheme
Even without any implicit quoting rule, the R5RS and R7RS are clear on this matter.

Both R5RS and R7RS use the same language in section 4.3.2: "The <pattern> in a <syntax rule> is a list <pattern> ...".

The important point is that the <pattern> has to be a list <pattern>. This only applies to the <pattern> in a <syntax rule>, not to a <pattern> nested in another <pattern>.

Marc
>> To unsubscribe from this group and stop receiving emails from it, send an email to chibi-...@googlegroups.com.

>> To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/CACsJy8ALNM-SV192vAvxfA3h60i%2BzXw%3DaQ93%2BvhfjFOg27iGYg%40mail.gmail.com.
>
> --
> 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-...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/chibi-scheme/CAMMPzYOT1OaPRH4jf12LX7QudKSH4WvoA2G%2BEU9gsx-J9o284Q%40mail.gmail.com.



--
Duy

--
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-...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages