caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* ignoring toplevel phrases?
@ 2009-06-26  4:22 Roland Zumkeller
  2009-06-26 17:44 ` [Caml-list] " Ashish Agarwal
  2009-06-27  8:32 ` Richard Jones
  0 siblings, 2 replies; 4+ messages in thread
From: Roland Zumkeller @ 2009-06-26  4:22 UTC (permalink / raw)
  To: caml-list

Hi,

Is it possible to modify the toplevel's behavior such that it silently
ignores any re-definitions of already bound identifiers (without
recompiling)? I would like to achieve the following:

# let x = 0;;
val x : int = 0
# let x = 1;;
# x;;
- : int = 0

The following code is supposed to replace all toplevel phrases by
"();;" during parsing (just as an experiment, it renders the toplevel
useless of course).

let original = !Toploop.parse_toplevel_phrase;;

Toploop.parse_toplevel_phrase :=
  fun _ -> original (Lexing.from_string ("();;"));;

After executing this, a non-terminating sequence is shown:
- : unit = ()
- : unit = ()
- : unit = ()
...

I'm probably not using the right hook. Any insight would be appreciated.

Best,

Roland

-- 
http://roland.zumkeller.googlepages.com/


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] ignoring toplevel phrases?
  2009-06-26  4:22 ignoring toplevel phrases? Roland Zumkeller
@ 2009-06-26 17:44 ` Ashish Agarwal
  2009-07-01  3:16   ` Roland Zumkeller
  2009-06-27  8:32 ` Richard Jones
  1 sibling, 1 reply; 4+ messages in thread
From: Ashish Agarwal @ 2009-06-26 17:44 UTC (permalink / raw)
  To: Roland Zumkeller; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1286 bytes --]

Just curious, why do you want this?

On Fri, Jun 26, 2009 at 12:22 AM, Roland Zumkeller <
roland.zumkeller@gmail.com> wrote:

> Hi,
>
> Is it possible to modify the toplevel's behavior such that it silently
> ignores any re-definitions of already bound identifiers (without
> recompiling)? I would like to achieve the following:
>
> # let x = 0;;
> val x : int = 0
> # let x = 1;;
> # x;;
> - : int = 0
>
> The following code is supposed to replace all toplevel phrases by
> "();;" during parsing (just as an experiment, it renders the toplevel
> useless of course).
>
> let original = !Toploop.parse_toplevel_phrase;;
>
> Toploop.parse_toplevel_phrase :=
>  fun _ -> original (Lexing.from_string ("();;"));;
>
> After executing this, a non-terminating sequence is shown:
> - : unit = ()
> - : unit = ()
> - : unit = ()
> ...
>
> I'm probably not using the right hook. Any insight would be appreciated.
>
> Best,
>
> Roland
>
> --
> http://roland.zumkeller.googlepages.com/
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 2057 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] ignoring toplevel phrases?
  2009-06-26  4:22 ignoring toplevel phrases? Roland Zumkeller
  2009-06-26 17:44 ` [Caml-list] " Ashish Agarwal
@ 2009-06-27  8:32 ` Richard Jones
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Jones @ 2009-06-27  8:32 UTC (permalink / raw)
  To: Roland Zumkeller; +Cc: caml-list

On Fri, Jun 26, 2009 at 11:22:16AM +0700, Roland Zumkeller wrote:
> Hi,
> 
> Is it possible to modify the toplevel's behavior such that it silently
> ignores any re-definitions of already bound identifiers (without
> recompiling)? I would like to achieve the following:
> 
> # let x = 0;;
> val x : int = 0
> # let x = 1;;
> # x;;
> - : int = 0

Have you considered a camlp4 extension?  I use a camlp4 extension in
Xavierbot to close some potential security holes in the toplevel, so
you could look at that code:

http://et.redhat.com/~rjones/xavierbot/

Rich.

-- 
Richard Jones
Red Hat


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] ignoring toplevel phrases?
  2009-06-26 17:44 ` [Caml-list] " Ashish Agarwal
@ 2009-07-01  3:16   ` Roland Zumkeller
  0 siblings, 0 replies; 4+ messages in thread
From: Roland Zumkeller @ 2009-07-01  3:16 UTC (permalink / raw)
  To: Ashish Agarwal; +Cc: caml-list

On Sat, Jun 27, 2009 at 12:44 AM, Ashish Agarwal<agarwal1975@gmail.com> wrote:
> Just curious, why do you want this?

I would like to save the state of the toplevel to the disk using
serialization. As functions can't be serialized one could check at
every "let" statement if there is a saved serialized value and if yes,
take that, otherwise execute the let-body. Just complinig is not an
option, since the *results* of previous computations should be saved,
i.e. 120 as opposed to "fact 5".


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-07-01  3:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-06-26  4:22 ignoring toplevel phrases? Roland Zumkeller
2009-06-26 17:44 ` [Caml-list] " Ashish Agarwal
2009-07-01  3:16   ` Roland Zumkeller
2009-06-27  8:32 ` Richard Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).