Browse thread
[Caml-list] Dynamically evaluating OCaml code
-
John Goerzen
- Vitaly Lugovsky
- Samuel Mimram
-
Basile Starynkevitch
-
Issac Trotts
- Dustin Sallings
-
Brian Hurt
- Oleg Trott
- Ville-Pertti Keinonen
-
John Goerzen
-
Markus Mottl
-
Richard Jones
-
Markus Mottl
- Jon Harrop
-
John Goerzen
- Jean-Marc EBER
-
Trevor Andrade
-
Gerd Stolpmann
- skaller
-
John Goerzen
-
Gerd Stolpmann
-
Christophe TROESTLER
-
Gerd Stolpmann
-
Christophe TROESTLER
- Brandon J. Van Every
- John Goerzen
- Jacques GARRIGUE
-
Christophe TROESTLER
-
Gerd Stolpmann
-
Christophe TROESTLER
- Matt Gushee
-
Gerd Stolpmann
- Benjamin Geer
-
Gerd Stolpmann
- skaller
-
Markus Mottl
- John Goerzen
- Jon Harrop
-
Richard Jones
- Fernando Alegre
- Jean-Marc EBER
- Kenneth Knowles
- Brian Hurt
- skaller
-
Markus Mottl
- Issac Trotts
- Basile Starynkevitch
-
Issac Trotts
- clement capel
- Jon Harrop
- Walid Taha
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Walid Taha <taha@c...> |
| Subject: | Re: [Caml-list] Dynamically evaluating OCaml code |
Hi John, You might want to take a look at MetaOCaml. Instead of strings it uses "Brackets" (written .<...>.) and uses ".!" for "eval". Here's a simple interactive session: # let a = .< 1 + 2 >.;; val a : int code = .<(1 + 2)>. # let b = .< .~a + .~ a >.;; val b : int code = .<((1 + 2) + (1 + 2))>. # let c = .! a;; val c : int = 3 # let d = .! b;; val d : int = 6 Notice that the also type checks what goes inside the brackets (it doesn't just say "code", it says "int code"). Walid. On Wed, 7 Apr 2004, John Goerzen wrote: |Hello, | |I am moving from Python to OCaml and one of the things I miss is |Python's eval() call. It takes a string representing a bit of Python |source code, evaluates it, and returns the result. I would like to be |able to do similar things with OCaml. | |I have observed that /usr/bin/ocaml, the interactive top-level, is |itself written in OCaml, which suggests that this should be possible. |Although I have tried to study the source for this, it seems extremely |complex and I can't figure out a way to do the simple evaluation |described above. | |Can anyone help me out here? | |Thanks, |John | | |------------------- |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 | -- ------------------- 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