unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* syntax-case guards
@ 2013-02-03 23:56 Aleix Conchillo Flaqué
  2013-02-04  0:52 ` Stephen Compall
  2013-02-04  1:14 ` Ian Price
  0 siblings, 2 replies; 4+ messages in thread
From: Aleix Conchillo Flaqué @ 2013-02-03 23:56 UTC (permalink / raw)
  To: guile-user

Hi,

I'm trying to use a syntax-case guard when the pattern has ellipsis.
So I have something like,

      ((_ (struct (k v) ...))
       (string? (syntax->datum #'k))
       exp)

And I want k to be a string. However, I am getting this error:

missing ellipsis in form (syntax k)

In ice-9/boot-9.scm:
   106:20  0 (#<procedure 297a240 at ice-9/boot-9.scm:97:6 (thrown-k .
args)> # …)

For patterns without ellipsis it works great.

So, how do I make the guard when I have a pattern with ellipsis?

Thanks in advance,

Aleix



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

* Re: syntax-case guards
  2013-02-03 23:56 syntax-case guards Aleix Conchillo Flaqué
@ 2013-02-04  0:52 ` Stephen Compall
  2013-02-04  1:14 ` Ian Price
  1 sibling, 0 replies; 4+ messages in thread
From: Stephen Compall @ 2013-02-04  0:52 UTC (permalink / raw)
  To: Aleix Conchillo Flaqué; +Cc: guile-user

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

On Feb 3, 2013 6:56 PM, "Aleix Conchillo Flaqué" <aconchillo@gmail.com>
wrote:
> So I have something like,
>
>       ((_ (struct (k v) ...))
>        (string? (syntax->datum #'k))
>        exp)
>
> And I want k to be a string. However, I am getting this error:
>
> missing ellipsis in form (syntax k)

The error is correct; k lives in single-ellipsis world.  What should k mean
to syntax->datum?  The first k?  The last k?

Try changing #'k to #'(k ...), and adjusting the guard to deal with list of
k, such as you will get, instead of just k.

--
Stephen Compall
If anyone in the MSA is online, you should watch this flythrough.

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

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

* Re: syntax-case guards
  2013-02-03 23:56 syntax-case guards Aleix Conchillo Flaqué
  2013-02-04  0:52 ` Stephen Compall
@ 2013-02-04  1:14 ` Ian Price
  2013-02-04  5:19   ` Aleix Conchillo Flaqué
  1 sibling, 1 reply; 4+ messages in thread
From: Ian Price @ 2013-02-04  1:14 UTC (permalink / raw)
  To: Aleix Conchillo Flaqué; +Cc: guile-user

Aleix Conchillo Flaqué <aconchillo@gmail.com> writes:

> Hi,
>
> I'm trying to use a syntax-case guard when the pattern has ellipsis.
> So I have something like,
>
>       ((_ (struct (k v) ...))
>        (string? (syntax->datum #'k))
>        exp)
You were probably wanting this to apply to each and every k
individually? syntax-case does not work this way. Patterns with ellipsis
are expected to be matched with templates with ellipsis. Sorry.

> So, how do I make the guard when I have a pattern with ellipsis?
using every from (srfi srfi-1) or for-all from (rnrs lists) [same
procedure different name] you get

(every (compose string? syntax->datum) #'(k ...))

As an aside, this won't work in Racket, since they also make lists into
syntax objects, unlike psyntax or the r6rs.

-- 
Ian Price -- shift-reset.com

"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"



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

* Re: syntax-case guards
  2013-02-04  1:14 ` Ian Price
@ 2013-02-04  5:19   ` Aleix Conchillo Flaqué
  0 siblings, 0 replies; 4+ messages in thread
From: Aleix Conchillo Flaqué @ 2013-02-04  5:19 UTC (permalink / raw)
  To: Ian Price; +Cc: guile-user

On Sun, Feb 3, 2013 at 5:14 PM, Ian Price <ianprice90@googlemail.com> wrote:
>
> You were probably wanting this to apply to each and every k
> individually? syntax-case does not work this way. Patterns with ellipsis
> are expected to be matched with templates with ellipsis. Sorry.
>

Yes. I see.

> using every from (srfi srfi-1) or for-all from (rnrs lists) [same
> procedure different name] you get
>
> (every (compose string? syntax->datum) #'(k ...))
>

Great, that did it!.

> As an aside, this won't work in Racket, since they also make lists into
> syntax objects, unlike psyntax or the r6rs.
>

By now, this doesn't worry much, but good to know.

Thank you so much,

Aleix



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

end of thread, other threads:[~2013-02-04  5:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-03 23:56 syntax-case guards Aleix Conchillo Flaqué
2013-02-04  0:52 ` Stephen Compall
2013-02-04  1:14 ` Ian Price
2013-02-04  5:19   ` Aleix Conchillo Flaqué

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