* [Caml-list] camlp4: ONCE construct
@ 2003-01-10 19:14 jehenrik
2003-01-10 22:35 ` Yutaka OIWA
0 siblings, 1 reply; 3+ messages in thread
From: jehenrik @ 2003-01-10 19:14 UTC (permalink / raw)
To: caml-list
Hi,
I would like to write a Camlp4 construct which causes its argument to
only be evaluated once. Eg:
...
...
...
ONCE Pcre.regexp "([0-9]+)"
would be transformed to:
let gensym000 = Pcre.regexp "([0-9]+)";;
...
...
...
gensym000
but I don't see a way to get a nonlocal transformation like that. One
way would be if the system had a way to side-effect out a new toplevel
let while the expressions were transforming. I suspect that facility
does not exist. Another way would be to have a second keyword
(ONCEBLOCK or something?) that would go where the let bindings
eventually would, which could take as an argument the entire expression
tree containing ONCE declarations. Then after a complicated recursive
parse on all the syntactic constructs, all the ONCEs could be located,
enumerated, and removed.
Note that I don't want to "memoize," or create a thunk which when
evaluated the first time does something complicated and all subsequent
times remembers what it did the first time. That still requires
manually writing the let statements in a different code location. My
goal is to improve readability by putting my regexps where they matter,
not several screens up just so that they get cached at runtime.
Thanks for any advice,
Jeff Henrikson
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] camlp4: ONCE construct
2003-01-10 19:14 [Caml-list] camlp4: ONCE construct jehenrik
@ 2003-01-10 22:35 ` Yutaka OIWA
2003-01-11 1:23 ` jehenrik
0 siblings, 1 reply; 3+ messages in thread
From: Yutaka OIWA @ 2003-01-10 22:35 UTC (permalink / raw)
To: jehenrik; +Cc: caml-list
>> On Fri, 10 Jan 2003 14:14:14 -0500, jehenrik <jehenrik@yahoo.com> said:
jehenrik> Hi,
jehenrik> I would like to write a Camlp4 construct which causes its argument to
jehenrik> only be evaluated once. Eg:
jehenrik> ...
jehenrik> ...
jehenrik> ...
jehenrik> ONCE Pcre.regexp "([0-9]+)"
jehenrik> would be transformed to:
jehenrik> let gensym000 = Pcre.regexp "([0-9]+)";;
jehenrik> ...
jehenrik> ...
jehenrik> ...
jehenrik> gensym000
See an article by Francois Pottier at
http://caml.inria.fr/archives/200107/msg00187.html
for (almost direct) answer.
Here is my question: Is there any way to declare a
module-local variable without using .mli signature?
It may not be prefarable for direct use by OCaml programmers
(than signature approach), but is useful for camlp4 programmers
to avoid name crashes caused by "open" or "include" directive.
P.S.
I have implemented a more powerful syntax extension for regular
expression matching, and I'm now preparing a documentation.
I'll release it for caml-list within this month (hopefully).
--
Yutaka Oiwa Yonezawa Lab., Dept. of Computer Science,
Graduate School of Information Sci. & Tech., Univ. of Tokyo.
<oiwa@yl.is.s.u-tokyo.ac.jp>, <yutaka@oiwa.shibuya.tokyo.jp>
PGP fingerprint = C9 8D 5C B8 86 ED D8 07 EA 59 34 D8 F4 65 53 61
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-01-11 1:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-10 19:14 [Caml-list] camlp4: ONCE construct jehenrik
2003-01-10 22:35 ` Yutaka OIWA
2003-01-11 1:23 ` jehenrik
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox