- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Copy of a function in JSL
Created:
Oct 15, 2021 06:39 AM
| Last Modified: Oct 15, 2021 4:15 AM
(756 views)
| Posted in reply to message from Robbb 10-15-2021
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
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Copy of a function in JSL
Created:
Oct 15, 2021 06:39 AM
| Last Modified: Oct 15, 2021 4:15 AM
(757 views)
| Posted in reply to message from Robbb 10-15-2021
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