|
Ok, I will give you more details about my project... maybe you could
be interested in it :> But first I need to underline that the macro *cannot foresee* which extern variables the lambda can reference ... so I cannot adopt your solution: (define-syntax mym
(syntax-rules ()
[(_ input ...)
(let* ([x 10]) ; at this time, I don't know if lambda will use "x", if "x" is bounded
; and (if bounded) which is the binding
(lambda (stuff)
input ... ;; line 2
x))]))
Now let's describe my project.I have defined a new language in racket, named chemical language (HOCL). The basic data structure of HOCL is the "multiset". It is a similar to a vector, with the difference that the elements are not ordered, but they move stochastically inside the vector (but this is all folks!). The multiset is a sort of chemical container (solution) of molecules. molecules can be any racket object: numbers?, strings, lists, and "gamma-rules". A "gamma-rule" is very similar to a scheme lambda. It is a function that captures some elements (chemical molecules) of the multiset and produces new molecules. In the chemical language, gamma-rules are the "chemical rules" that fire reactions in the mutliset (the chemical solution), and that transform molecules in new molecules. I implemented a reader for the multiset notation: < molecule1, molecule2, ... > where commas separates the multiset elements, and "<" ">" are multiset delimiters. I create and bind a multiset in this way (define m < 1,2,3,4,(replace x y by (+ x y)), 5, 6 >) ; top level definition < 1,2,3,4, #<procedure>, 5, 6 > ; the output is a chemical container with a gamma-rule inside it (plus other molecules) ; the "x" and "y" free variables of the rule are bound to molecules by a pattern matching mechanism, Now I have a chemical engine ("cham") that starts reactions in the chemical solution. The gamma-rules are applied to the mutliset (with the sheme "apply"). > (cham m) < 21, #<procedure> > As you see the chemical rule (gamma-rule) applies many times, and each time it adds pairs of molecules until one molecule (the total sum) is left (the chemical inert state). Now let's talk about the "gamma-rule" generation: the macro "replace ... by ... " generate the gamma-rule code (define-syntax replace
(syntax-rules (replace)
[(replace input ...)
(let* (...)
(eval `(lambda (cntx) ; the code of the "gamma-rule"
...
))]))Now the problem... In the previous example I can define a rule like this: (replace x y by (+ x y) if (> top (+ x y))), 5, 6 >) that is, I want the reaction to take place only if the partial sum of molecules is not over "top", where the "top" variable may be externally defined. Now I can write the code: (let ((top 8) (m < 1,2,3,4,(replace x y by (+ x y) if (> top (+ x y))), 5, 6 >))) ; multiset elements are evaluated after reading (cham m)) reference to undefined identifier: top ... I hope now it is clear that I need to generate procedures with references to symbols that can (or cannot) have bindings when the procedure is called... in fact, the user writes the (replace ....) form but the system cannot foresee which extern symbols the generated procedure may use. Thank you for your attention. Sorry for a so long email... I couldn't explain my probelm with less details. Maurizio. Il 11/07/2011 17.26, Matthias Felleisen ha scritto:
|
_________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users

