Scheme pattern matching -


i have written following syntax rule:

(define-syntax match-rewriter     (syntax-rules ()     ((_ (patt body) ...)      (λ (x) (match x (patt body) ... (_ x)))))) 

which match-lambda except returns argument if no match found rather throwing exception.

now want write function, let_as_lambda, take strings of source code input , rewrite let statements new let_as_lambda function. have:

(define let_as_lambda     (match-rewriter (`(let((,<var> ,<val>)) ... ,<expressions>)                    `((lambda (,<var> ...) ,<expressions>) ,<val> ...)))) 

it wrong as:

(let_as_lambda '(let((x 3)) (+ x 2))) 

returns:

'((λ ((x) ...) (+ x 2)) (3) ...) 

still showing ellipses , "3" in parentheses. believe problem don't understand proper usage of symbols `, ., , , in pattern matching.

if show me correct way appreciated.

thanks.

you're confused because use 2 different pattern matching tools. first syntax-rules , second match. seem close enough there important differences -- , in case, main problem unlike syntax-rules, cannot use ... in quasi-quoted results of match. deal lists of matched values need use unquote-splicing (or ,@) , other functions map etc. example, compare results of these 2 expressions:

(match '(1 2 3) [`(,x ...) `(foo ,x ...)]) (match '(1 2 3) [`(,x ...) `(foo ,@x)]) 

as side note, nice if usual quasi-quote want, complete solution needs possible simple functions -- , complicates whole thing (uses of ... need translate apply).


Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -