cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Robbb
Level III

Copy of a function in JSL

Hi,

my function F is a complex function and in some cases I need to redefine it while keeping its old functionality. I would like to keep a copy of F before changing it. So far, I did not find a way to do this in JSL. Here is a small example, what I am trying to do. What is the correct way to really copy a function and not just link it?

Thanks!

F = Function( {x,y}, x+y ); // actually much more complex
Show(F(1,2)); // 3
// G = F; // Error, JMP complains about missing parameters
G = Function( {x,y}, F(x,y));
Show(G(1,2)); // 3
F = Function( {x,y}, x*y ); // Changes G, too.
Show(F(1,2)); // 2
Show(G(1,2)); // 2, but I want it to remain 3.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ErraticAttack
Level VI

Re: Copy of a function in JSL

You can essentially grab the function pointer with the Name Expr() command

F = Function( {x,y}, x+y ); // actually much more complex
Show(F(1,2)); // 3
G = Name Expr( F ); // use the magic NameExpr function to grab a pointer
Show(G(1,2)); // 3
F = Function( {x,y}, x*y ); // Changes G, too.
Show(F(1,2)); // 2
Show(G(1,2)); // 2, but I want it to remain 3.

/*:
F(1, 2) = 3;
G(1, 2) = 3;
F(1, 2) = 2;
G(1, 2) = 3;
*/

 

Looks like there is an issue on this site preventing proper JSL code insertion

Jordan

View solution in original post

1 REPLY 1
ErraticAttack
Level VI

Re: Copy of a function in JSL

You can essentially grab the function pointer with the Name Expr() command

F = Function( {x,y}, x+y ); // actually much more complex
Show(F(1,2)); // 3
G = Name Expr( F ); // use the magic NameExpr function to grab a pointer
Show(G(1,2)); // 3
F = Function( {x,y}, x*y ); // Changes G, too.
Show(F(1,2)); // 2
Show(G(1,2)); // 2, but I want it to remain 3.

/*:
F(1, 2) = 3;
G(1, 2) = 3;
F(1, 2) = 2;
G(1, 2) = 3;
*/

 

Looks like there is an issue on this site preventing proper JSL code insertion

Jordan