-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with MODULE.FUNCTIONNAME When Sharing Lambdas #17
Comments
For problem 1. would you be able to provide a self-contained gist that demonstrates the problem? Name resolution in modules allow a name to refer to another name within the same module, regardless of the module name. For example, the module:
Within For problem 2, similarly, is there a gist I can import that shows the error? You can define a name like:
And the reference to For problem 3, yes this is a limitation / by design in AFE. In general, we only allow dot's to be in top-level name to avoid complex resolution cases such as |
Hi Jack, thank you for your reply. My mistake. After trying your examples, I figured out that I was doing a couple of things wrong:
Example: Load the following gist (your examples) into a module named "X" I'm not sure how to get around this second issue if a person happens to name their module the same thing as one of the parameters in a function, but at least the main issue can be avoided by not using periods in lambda names. Thanks! |
The second bullet is a design limitation in AFE, Excel, and how formulas are saved. We prevent it and flag an error, otherwise the formula would not work. We do raise errors more than we need to, so in that sense there is a 'bug'. The reason why we flag the error is as follows. Suppose we have a module called
When we save Unfortunately, this will not work correctly. The presence of the parameter My only suggestion and workaround is to prefix LET or LAMBDA parameters with underscore to make them different from module names. |
Thank you. In my documentation, I think I will also suggest a few safe names for the module in case they want to import to a separate module. |
I want to create a library of Lambda functions to share and after experimenting with various ways of sharing, I'm running into problems when importing from a Gist.
When you import a Gist into a new module, the user can name that module whatever they want, and then the functions within that module are automatically named MODULE.FUNCTION. For example, the user creates a module named MATH and imports a Gist containing a function named MYFUN. The name that Excel Labs creates in the Name Manager is MATH.MYFUN. This is of course already documented, but creates a couple of problems:
Problem 1: If any of the other functions contained within the Gist use MYFUN, those functions are now broken. A possible solution would be to have Excel Labs automatically refactor the function names. Meanwhile, the best solution I can think of is to warn users to NOT import the Gist into a new module. The not-good solution (because it means duplication of code which defeats the purpose) is to avoid calling any named lambda functions within other lambdas.
Problem 2: Functions that use recursion, calling themselves by name, will become broken.
Solution: Wrap the recursive function with LET like this example (this function stacks an array n times - something you can do with REDUCE, but shown here for the sake of an example):
EXAMPLE = LAMBDA(param_1,param_2,
LET(
recurseFun,LAMBDA(SELF,param_1,param_2,[i],[accumulator],
IF( ISOMITTED(accumulator),
IF( IF(ISOMITTED(i),1,i) >= param_2,
param_1,
SELF(SELF,param_1,param_2,i+1,param_1)
),
IF( IF(ISOMITTED(i),1,i) >= param_2,
accumulator,
SELF(SELF,param_1,param_2,i+1,VSTACK(accumulator,param_1))
)
)
),
recurseFun(recurseFun,param_1,param_2)
));
Problem 3: If I create functions named ODE.MYFUN or L.MYFUN, and these are imported into any new module, they result in errors. I think this is an AFE issue because MODULE.ODE.MYFUN is still a valid lambda name. But, the AFE considers it an error if ODE.MYFUN is contained within a module named MODULE.
Solution: Avoid using periods in lambda names, to avoid conflicts with parameter names and how the AFE works.
The text was updated successfully, but these errors were encountered: