lambda function syntax [message #92249] |
Thu, 05 November 2015 06:36  |
greg.addr
Messages: 160 Registered: May 2007
|
Senior Member |
|
|
I've created a lambda procedure inside an object (to hold a user-defined function):
self.lambda=lambdap("t,n1:"+code)
where, e.g. code="n1=sqrt(t)"
This appears to work fine, but I can't figure out a legal syntax to call it inside a method:
function test_obj::N1,t
self.n1_lambda,t,n1
return,n1
end
IDL> print,obj->n1(1)
% Attempt to call undefined method: 'TEST_OBJ::N1_LAMBDA'.
---
Having written the example, I discovered it does work if I do this:
function test_obj::N1,t
lam=self.n1_lambda
lam,t,n1
return,n1
end
which isn't so bad. The first should be correct syntax, though, I think.
cheers,
Greg
|
|
|
Re: lambda function syntax [message #92275 is a reply to message #92249] |
Mon, 09 November 2015 09:30  |
chris_torrence@NOSPAM
Messages: 528 Registered: March 2007
|
Senior Member |
|
|
On Thursday, November 5, 2015 at 7:36:12 AM UTC-7, greg...@googlemail.com wrote:
> I've created a lambda procedure inside an object (to hold a user-defined function):
>
> self.lambda=lambdap("t,n1:"+code)
>
> where, e.g. code="n1=sqrt(t)"
>
> This appears to work fine, but I can't figure out a legal syntax to call it inside a method:
>
>
> function test_obj::N1,t
> self.n1_lambda,t,n1
> return,n1
> end
>
>
> IDL> print,obj->n1(1)
> % Attempt to call undefined method: 'TEST_OBJ::N1_LAMBDA'.
>
> ---
>
> Having written the example, I discovered it does work if I do this:
>
> function test_obj::N1,t
> lam=self.n1_lambda
> lam,t,n1
> return,n1
> end
>
> which isn't so bad. The first should be correct syntax, though, I think.
>
> cheers,
> Greg
Hi Greg,
Yeah, I don't think this is going to work. The parser is interpreting that at compile time as a method call, rather than waiting until runtime. I thought that setting "compile_opt strictarr" might help, but it didn't.
I think your workaround is the best solution. Sorry about that.
-Chris
|
|
|