I wanted to know about passing expressions as parameters. Suppose I have an expression defined as:
def E(x,f) = Rtimer(x) >> f()
Then E(A) would call A() in E (after Rtimer(x) )
Is it possible to use E for calling "A() >> B()" or any such expression ?
Is there a way of passing A() >> B() as the parameter such that they are invoked using E?
I know that I can always create A() >> B() as another expression C and then pass C as the parameter but I wanted to know if there is a way to pass this as parameter. My problem is that the parameter for E i.e the functions to call is being created dynamically as a string.
> I wanted to know about passing expressions as parameters. Suppose I have an expression defined as:
> def E(x,f) = Rtimer(x) >> f()
> . . . . . . > My problem is that the parameter for E i.e the functions to call is being created dynamically as a string.
Hello:
It seems like you're looking for a Lisp EVAL-style feature, which Orc doesn't have currently. I think you'll need to parse the input string and construct a closure, using def or lambda. (However, if you're calling Java classes, you can use java.lang.Class.getMethod, but that gets quite ugly quickly if you're trying to do this in a general case.)
--J^T
John A. Thywissen Computer Science The University of Texas at Austin
" I think you'll need to parse the input string and construct a closure, using def or lambda. "
Could you let me know how to do this with my example. Am not using Java classes.
I have def f() = println("1") >> let(1) def g() = println("2") >> let(2) def k() = println("3") >> let(3)
def E(x,A) = Rtimer(x) >> A()
Now if I want f() >> g() OR (g(),k()) OR f() | g() | k()
What should I specify as E's argument for these 4 cases? I tried giving E(f>>g) for the first case but it just prints 2 ( looks like f is not invoked )
Thank you for your help in this regard,
-- Nihita
On Fri, Jan 13, 2012 at 7:36 PM, John Thywissen <jthyw...@cs.utexas.edu>wrote:
> I wanted to know about passing expressions as parameters. Suppose I have > an expression defined as:
> def E(x,f) = Rtimer(x) >> f()
> . . . . . .
> My problem is that the parameter for E i.e the functions to call is being > created dynamically as a string.
> Hello:
> It seems like you're looking for a Lisp EVAL-style feature, which Orc > doesn't have currently. I think you'll need to parse the input string and > construct a closure, using def or lambda. (However, if you're calling > Java classes, you can use java.lang.Class.getMethod, but that gets quite > ugly quickly if you're trying to do this in a general case.)
> --J^T
> *John A. Thywissen* > *Computer Science* > The University of Texas at Austin
-- Nihita Goel Tata Institute of Fundamental Research Mumbai-400005
> Now if I want > f() >> g() OR > (g(),k()) OR > f() | g() | k()
> What should I specify as E's argument for these 4 cases? I tried giving E(f>>g) for the first case but it just prints 2 ( looks like f is not invoked )
Create a closure using lambda or def:
E(100, lambda() = f() >> g())
or, equivalently,
def f_seq_g() = f() >> g() E(100, f_seq_g)
Also, relating to your previous question about converting strings to expressions: If your input strings are only values that correspond to Orc constant literals (numbers, Booleans, quoted strings, signal, null; and lists and tuples thereof), then the Orc library site "Read" may be of use to you.
--J^T
John A. Thywissen Computer Science The University of Texas at Austin
> Now if I want > f() >> g() OR > (g(),k()) OR > f() | g() | k()
> What should I specify as E's argument for these 4 cases? I tried giving > E(f>>g) for the first case but it just prints 2 ( looks like f is not > invoked )
> Create a closure using lambda or def:
> E(100, lambda() = f() >> g())
> or, equivalently,
> def f_seq_g() = f() >> g() > E(100, f_seq_g)
> Also, relating to your previous question about converting strings to > expressions: If your input strings are only values that correspond to Orc > constant literals (numbers, Booleans, quoted strings, signal, null; and > lists and tuples thereof), then the Orc library site "Read" may be of use > to you.
> --J^T
> *John A. Thywissen* > *Computer Science* > The University of Texas at Austin