Hello,

Infix in Scheme is all the rage these days. ;-) Awhile back I mentioned an 'alg' procedure which converts a string containing an infix expression to an sexp. So for example:

> (import (numero symbolic alg))
> (alg "x+y")
(+ x y)
> (alg "f(x,y)+z")
(+ (f x y) z)
>

I'd like to have a macro version of alg which expands to the sexp at at "expansion time" (what's the right terminology here?).

Here's a version which seems to work in simple cases. I wanted to run it by y'all though; does it look correct? Any advice?

(define-syntax algm

  (lambda (stx)

    (syntax-case stx ()

      ( (algm expr)

        (with-syntax ((new-expr (datum->syntax
                                 (syntax algm)
                                 (alg (syntax->datum (syntax expr))))))

                     (syntax new-expr)) ))))

Example; let's say we try the "x+y" where those symbols aren't bound. We should get an error:

> (algm "x+y")
Unhandled exception
...
>

Try the same expression, but in a context where the symbols have values:

> (let ((x 10)
        (y 20))

    (algm "x+y"))
30
>

Ed

Reply via email to