Post Reply 
in search of LAMBA functions
10-04-2015, 02:44 AM
Post: #1
in search of LAMBA functions
Define a couple of binary cas-lam functions:

vadd := "(A,B)->BEGIN return; A+B; END" <-- No SEMI VERY IMPORTANT

vmpy:="(A,B)->BEGIN return; A*B; END"

Then make a cas pgm which applies an arbitrary input binary funtion to two list
arguments:

#cas
toboth(f,l1,l2) :=
BEGIN
LOCAL K;
FOR K FROM 1 TO SIZE(l1) DO
L3(K) := expr(f)(l1(K),l2(K)); <-- this would never compile in ppl
END;
L3;
END;
#end


Then call our function with each of our "lamdas"

toboth(vmpy,{1,2,3},{8,6,7}) -> {8,12,21}

toboth(vadd,{1,2,3},{8,6,7}) -> {9,8,10}


Doesn work if we send expr (lam) first. Seems to need string form.
Not quite lambda but its pretty darn close.

The problem with using Programs (name):=string is that the target cant compile if the pgm doesn exist until runtime. I suppose you could compile
with a dummy then change it at runtime. But....

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
10-04-2015, 10:54 AM
Post: #2
RE: in search of LAMBA functions UPDATE
I take it back. You CAN pre-evaluate the strings.

cvadd := expr (vadd); (the result is super)

Then modify the target and remove the expr (f).
Just write f ( ...) in the receiving cas function.

It works. They are true lamdas. No doubt about it.

My experiments failed for other reasons. There were errors in the target
function. The compiler will pass just about anything for #cas objects.
In my example the output list needs to be global.

So are #cas objects not really compiled but interpreted?

Anyhow n-ary lamba function are fully present and available for use.
The target must be a #cas function.

Be happy xset.

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)