Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Passing expressions as parameters
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Nihita Goel  
View profile   Translate to Translated (View Original)
 More options Jan 13 2012, 8:44 am
From: Nihita Goel <nih...@tifr.res.in>
Date: Fri, 13 Jan 2012 19:14:34 +0530
Local: Fri, Jan 13 2012 8:44 am
Subject: Passing expressions as parameters

Hi:

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.

Thanks and waiting for your response ..

-- Nihita


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Thywissen  
View profile  
 More options Jan 13 2012, 9:06 am
From: John Thywissen <jthyw...@cs.utexas.edu>
Date: Fri, 13 Jan 2012 08:06:06 -0600
Local: Fri, Jan 13 2012 9:06 am
Subject: Re: [orc-lang] Passing expressions as parameters

On 13 Jan 2012, at 0744, Nihita Goel 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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nihita Goel  
View profile   Translate to Translated (View Original)
 More options Jan 13 2012, 9:26 am
From: Nihita Goel <nih...@tifr.res.in>
Date: Fri, 13 Jan 2012 19:56:32 +0530
Local: Fri, Jan 13 2012 9:26 am
Subject: Re: [orc-lang] Passing expressions as parameters

" 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:

--
Nihita Goel
Tata Institute of Fundamental Research
Mumbai-400005

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Thywissen  
View profile  
 More options Jan 13 2012, 10:56 am
From: John Thywissen <jthyw...@cs.utexas.edu>
Date: Fri, 13 Jan 2012 09:56:47 -0600
Local: Fri, Jan 13 2012 10:56 am
Subject: Re: [orc-lang] Passing expressions as parameters

On 13 Jan 2012, at 0826, Nihita Goel wrote:

> 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 )

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nihita Goel  
View profile   Translate to Translated (View Original)
 More options Jan 13 2012, 12:24 pm
From: Nihita Goel <nih...@tifr.res.in>
Date: Fri, 13 Jan 2012 22:54:12 +0530
Local: Fri, Jan 13 2012 12:24 pm
Subject: Re: [orc-lang] Passing expressions as parameters

Thanks a lot for your quick response. Read and lambda() resolved my problem.

-- Nihita

On Fri, Jan 13, 2012 at 9:26 PM, John Thywissen <jthyw...@cs.utexas.edu>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »