On 2 Dec 2010, at 10:57, Marco Maggi wrote:
I am writing on a parser that translates normal function
syntax in to Guile code.
I do not know which scenario you are working with, ...
I have a Bison/Flex parser/lexer combination that writes Guile code
directly by calling Guile C-functions, some via C++ wrap I wrote. The
expressions are not evaluated until after the construction, just as
when one enter expressions in the Guile interpreter, which gives
greater flexibility.
So I am not limited by any syntax, only the Guile semantics, which is
more general than that of Scheme, in view of that one by calling C-
functions, one can build things that not possible in Scheme proper. By
writing out the expression before evaluation, I get a Guile code
expression.
I think I may be able to solve the original problem. I am now thinking
by making functions that are called as (f (x y) z), where some
arguments are lists, which correspond to Haskell
f (1, 2) 3 where f (x, y) z = x + y + z
--> 6
...but it is
perfectly possible to convert the input syntax:
((sin , cos , tan) 1.2)
to the output:
((lambda args
(map (lambda (f)
(apply f args))
(list sin cos tan)))
1.2)
if you accept to write the input syntax expressions only as
part of a macro use, let's call this macro H; so the macro
use:
(h
((sin , cos) 1.2))
can be expanded to:
((lambda args
(map (lambda (f)
(apply f args))
(list sin cos tan)))
1.2)
It is also possible to write the H macro such that any
expression with nested expressions can appear in its use; H
can be made just like the built in syntax BEGIN but with
syntax different from standard Scheme. Example:
(h
(display (+ 4 ((sin , cos) 1.2))))
Once you have H you can write a DEFINE/H syntax which
works just like the standard DEFINE but accepts in its body
the modified syntax:
(define/h (doit x y)
(display (+ x ((sin , cos) y))))
The tool to do it is the syntax-case macro system.
HTH
--
Marco Maggi