* Toploop.setvalue
@ 2009-03-08 21:43 Roland Zumkeller
2009-03-13 4:53 ` [Caml-list] Toploop.setvalue Dave Benjamin
2009-03-13 15:22 ` Toploop.setvalue Zheng Li
0 siblings, 2 replies; 3+ messages in thread
From: Roland Zumkeller @ 2009-03-08 21:43 UTC (permalink / raw)
To: caml-list
Hi,
Can Toploop.setvalue be used to bind a value to an identifier, as does "let"?
# Toploop.setvalue "b" (Obj.repr 43);;
- : unit = ()
# b;;
Unbound value b
I only got the other direction to work:
# let a = 42;;
val a : int = 42
# (Obj.obj (Toploop.getvalue "a") : int);;
- : int = 42
Best,
Roland
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Toploop.setvalue
2009-03-08 21:43 Toploop.setvalue Roland Zumkeller
@ 2009-03-13 4:53 ` Dave Benjamin
2009-03-13 15:22 ` Toploop.setvalue Zheng Li
1 sibling, 0 replies; 3+ messages in thread
From: Dave Benjamin @ 2009-03-13 4:53 UTC (permalink / raw)
To: Roland Zumkeller; +Cc: caml-list
Roland Zumkeller wrote:
> Hi,
>
> Can Toploop.setvalue be used to bind a value to an identifier, as does "let"?
>
> # Toploop.setvalue "b" (Obj.repr 43);;
> - : unit = ()
> # b;;
> Unbound value b
>
> I only got the other direction to work:
>
> # let a = 42;;
> val a : int = 42
> # (Obj.obj (Toploop.getvalue "a") : int);;
> - : int = 42
Not that I know of. I was only able to get it to rebind values that I
initialized by evaluating expressions like "let b = 43;;". Here's an
example:
http://pleac.sourceforge.net/pleac_ocaml/strings.html#AEN68
Hope this helps - and if anyone has better advice I'd love to hear it,
Dave
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Toploop.setvalue
2009-03-08 21:43 Toploop.setvalue Roland Zumkeller
2009-03-13 4:53 ` [Caml-list] Toploop.setvalue Dave Benjamin
@ 2009-03-13 15:22 ` Zheng Li
1 sibling, 0 replies; 3+ messages in thread
From: Zheng Li @ 2009-03-13 15:22 UTC (permalink / raw)
To: Roland Zumkeller; +Cc: caml-list
Hello,
On 3/8/2009 10:43 PM, Roland Zumkeller wrote:
> Can Toploop.setvalue be used to bind a value to an identifier, as does "let"?
No. I don't think it's intended to be used in this way.
> # Toploop.setvalue "b" (Obj.repr 43);;
> - : unit = ()
> # b;;
> Unbound value b
This will only inject the value into the runtime, it won't add the
necessary information into the compiler's working environment. So "b" is
only visitable through the Toploop.getvalue, not through the normal
toplevel.
> I only got the other direction to work:
>
> # let a = 42;;
> val a : int = 42
> # (Obj.obj (Toploop.getvalue "a") : int);;
> - : int = 42
In this case, you define a binding the normal way, so both the compiler
and the runtime knows it. You can visit "a" via both the
Toploop.getvalue and the normal toplevel.
I don't really understand what purpose you want to achieve, so I can
only answer your question literally.
HTH.
--
Zheng
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-03-13 15:21 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-08 21:43 Toploop.setvalue Roland Zumkeller
2009-03-13 4:53 ` [Caml-list] Toploop.setvalue Dave Benjamin
2009-03-13 15:22 ` Toploop.setvalue Zheng Li
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox