using lambda functions (they've been found)
10-04-2015, 04:46 PM
Post: #1
 ji3m Member Posts: 149 Joined: Sep 2015
using lambda functions (they've been found)
Since my previous post looking for lambdas things have improved.

We do have access to true lambda functions which can be generated and passed around at runtime.
Certaintly with #cas <> #cas functions.

But some care is required when using ppl code and lambdas.

Below is code with lambda examples and comments.
You can copy and paste it or download the attached text file(same stuff).

//BELOW ARE TWO HELPER FUNCTINS:
//NEEDED SINCE #CAS PGMS DONT STO WELL TO LISTS

EXPORT putl(L,N,V)
BEGIN
L(N) := exact(V);//PPL IS EVAL CRAZY
END;

//FOR USE IN PPL TO "COMPILE" LAMBDA STRINGS
LOCAL DUMMY1 ;

#cas
myexpr(S):=
BEGIN
return expr(S);
END;
#end

#cas
lopl(f,l1,l2) :=
BEGIN
LOCAL K,Q := {};
FOR K FROM 1 TO SIZE(l1) DO
Q := putl(Q,K,f(l1(K),l2(K)));
END;
Q;
END;
#end

//THE ABOVE CAS PGM APPLIES THE LAMBDA FUN f
// TO THE TWO LISTS AND RETURNS LIST Q

LOCAL DUMMY2;

//SIMPLE BINARY LAMBDAS (NO ";" AFTER END!)

EXPORT lamdiv := "(A,B)->BEGIN A/B; END";
EXPORT lamadd := "(A,B)->BEGIN A+B; END";

//YOU CAN COMPILE THE LAM STRINGS AS CAS VARS

// clamdiv := expr(lamdiv);

// AND CALL A CAS FUN LIKE THIS

// lopl(clamdiv,{1,2},{3,5}) -> {1/3,2/5}

//THIS WORKS

EXPORT trymediv(L1,L2)
BEGIN
LOCAL F := myexpr(lamdiv);
lopl(F,L1,L2);
END;

//BUT THIS WILL CRASH AND BURN
EXPORT crash(f,L1,L2)
BEGIN
lopl(f,L1,L2);
END;

// IF YOU ENTER crash(clamdiv,{2,5,6},{7,8,9})

//PPL SEEMS TO DISLIKE RAW LAMBDAS

//BUT THIS DOES WORK
EXPORT nocrash(fstr,L1,L2)
BEGIN
lopl(myexpr(fstr),L1,L2);
END;

//WHEN YOU PASS ANY LEGIT LAMBDA STRING
//WHY myexpr? BECAUSE expr COMPILES WRONG IN PPL
//AND myexpr IS #cas.

// try
// nocrash("(W,Z)->BEGIN 2*W-Z END",{1},{9})

//OF COURSE YOU CAN GEN ANY LAM AT RUNTIME

Attached File(s)

I work with android Prime only for now on my
Galaxy Tab Pro/Note 2
10-09-2015, 06:41 PM
Post: #2
 ji3m Member Posts: 149 Joined: Sep 2015
RE: using lambda functions (they've been found)