[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: guile-syntax-parse

From: Stefan Israelsson Tampe
Subject: Re: guile-syntax-parse
Date: Thu, 24 Nov 2011 15:24:47 +0100


syntax-parse is quite a heavy where it basically defines a syntax-case + verifying logic from the beginning.

What I have played with a lighter version of that code and a kind of system around it that worked by
piggy-pack on guiles syntax-case.

It's not much code needed to get something that is acceptable for my uses here so this is what I did.

I redefined matchers so that one could enter validators inside the matcher like

(syntax-parse x () ((_ x y : list-of-symbols) #'(cons x y)))

If you did not have this information you would use syntax-case and write a verifier-function (list-of-symbols)
that is called in the first possition and send #'(x y) as the first argument to this function. This is what I
basically do as well.

So the gain is a clearer specification of what is allowed in the matcher. So not much logic here
to meet my humble need. The code does get significantly more self documented by this though.

I did try to get line-numbers in the error outputs but I somehow failed to do this correctly right now I just
get the function location where the error appear.

I have used this system quite alot and are found of it. And I strongly advocate to enter such a system into
guile. You get qute a lot of code readability and code patterns from quite a limitid amount of code.

I will try to writeup something more meaty the next days' but I hope you got a feeling for the general
approach I took.

Oh, it really pay's off to write specifications for macros and report on errors reasonable exact. It really cut's down on debugging time.

Here is an example of how I use it
(define-syntax <const>
  (lambda (x)

    (define <tp>     (mk-type-vd         #t '<const>))
    (define <id>     (mk-identifier-vd   #t '<const>))
    (define <arg3> (mk-arg-vd          #t '<const> 3))

    (reg-form x)

    (syntax-parse x ()
      ((_ (t : <tp>) (s : <id>)  v : <arg3>)
           (define s (mk-var (auto-type t)
                             (auto-t s)
                             (auto v)
           (set! *clambda*
                 (cons (c-const (c-var (auto-type t) (s #t) (v #t)))

(t : <tp>)

when there is only one element the the left of : then this is inetrpreted as (<tp> #'t) but idf we would have
(t1 t2 : <tp>) I would interpret it as (<tp> #'(t1 t2))


On Wed, Nov 23, 2011 at 10:47 PM, Andy Wingo <address@hidden> wrote:
On Mon 09 May 2011 14:11, Stefan Israelsson Tampe <address@hidden> writes:

> Hi, check out guile-syntax-parse at

How is this going?  Are you still using it?

You didn't get any responses, but I'm still curious to see it working.
Syntax-parse sounds like a useful facility.  I'm offline at the moment,
but I would be interested in hearing about your experiences with this.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]