Is there an easy way (perhaps through the PolyML.Compiler structure) to get the depth of ` use "foo" ' stack at runtime?
On 10/01/2013 09:12, Ian Zimmerman wrote:
Is there an easy way (perhaps through the PolyML.Compiler structure) to get the depth of ` use "foo" ' stack at runtime?
I think the answer is probably "no" but I'm not clear exactly what you're asking. "stack" can mean a lot of things.
David
On Fri, 11 Jan 2013 10:24:58 +0000 David Matthews David.Matthews@prolingua.co.uk wrote:
Ian> Is there an easy way (perhaps through the PolyML.Compiler Ian> structure) to get the depth of ` use "foo" ' stack at runtime?
David> I think the answer is probably "no" but I'm not clear exactly David> what you're asking. "stack" can mean a lot of things.
Let's call the hypothetical function use_depth. Then ideally it would behave like this:
$ poly
use_depth;
val it = fn: unit -> int
use_depth ();
val it = 0: int
$ cat level1.sml use_depth () $ poly
use "level1.sml";
val it = 1: int val it = (): unit
$ cat level2.sml use "level1.sml" $ poly
use "level2.sml";
val it = 2: int val it = (): unit val it = (): unit
I found another way to do what I want, so this is only of academic interest now.
On 11/01/2013 09:49, Ian Zimmerman wrote:
On Fri, 11 Jan 2013 10:24:58 +0000 David Matthews David.Matthews@prolingua.co.uk wrote:
Ian> Is there an easy way (perhaps through the PolyML.Compiler Ian> structure) to get the depth of ` use "foo" ' stack at runtime?
David> I think the answer is probably "no" but I'm not clear exactly David> what you're asking. "stack" can mean a lot of things.
Let's call the hypothetical function use_depth. Then ideally it would behave like this:
$ poly
use_depth;
val it = fn: unit -> int
use_depth ();
val it = 0: int $ cat level1.sml use_depth () $ poly
use "level1.sml";
val it = 1: int val it = (): unit $ cat level2.sml use "level1.sml" $ poly
use "level2.sml";
val it = 2: int val it = (): unit val it = (): unit I found another way to do what I want, so this is only of academic interest now.
How about:
val use_depth = ref 0; fun use s= (use_depth := (!use_depth) + 1; PolyML.use s; use_depth := (!use_depth) - 1);
example use...
ldixon-macbookair:~ ldixon$ cat f1.ML print (Int.toString (!use_depth)); ldixon-macbookair:~ ldixon$ cat f2.ML use "f1.ML"; print (Int.toString (!use_depth)); ldixon-macbookair:~ ldixon$ rlwrap poly Poly/ML 5.5.0 Release
val use_depth = ref 0; val use_depth = ref 0: int ref
fun use s= (use_depth := (!use_depth) + 1; PolyML.use s; use_depth :=
(!use_depth) - 1); val use = fn: string -> unit
use "f1";
1val it = (): unit val it = (): unit
use "f2";
2val it = (): unit val it = (): unit 1val it = (): unit val it = (): unit
best, lucas
On 24/02/13 02:40, Lucas Dixon wrote:
How about:
val use_depth = ref 0; fun use s= (use_depth := (!use_depth) + 1; PolyML.use s; use_depth := (!use_depth) - 1);
Presumably you'd want to handle any exceptions raised by PolyML.use too (and reraise them after decrementing use_depth).
Phil