-- -*- M2 -*-

-- Here's code that monitors every call to any method function of random, which should be incorporated into "on"

debug Core
scan( methods random, x -> (
	  f := lookup x;
	  local opts;
	  name := "random " | toString unsequence drop(x,1);
	  g := y -> (f opts) y;
	  setAttribute(g,ReverseDictionary,name); -- we should store the function body, not the function closure, see below
	  g = on g;
	  h := o -> ( opts = o ; y -> (opts = o; g y) );
	  setAttribute(h,ReverseDictionary,name);
	  installMethod append (x, h)))
dictionaryPath = select(dictionaryPath, d -> d =!= Core#"private dictionary")
lookup(random,ZZ)
random 100
random (100,200)
end
restart
input "1-on-and-methods"


i12 : f = x -> y -> z

o12 = f

o12 : FunctionClosure

i13 : setAttribute(f 1,ReverseDictionary,"hi there")

o13 = hi there

i14 : f 1

o14 = {*Function[stdio:5:11-5:14]*}

o14 : FunctionClosure

i15 : setAttribute(functionBody f 1,ReverseDictionary,"hi there")

o15 = hi there

i16 : f 1

o16 = {*Function[stdio:5:11-5:14]*}

o16 : FunctionClosure
