Forum Discussion
A statement of truth or a wasted opportunity. Lambda helper functions reluctant to return 2D arrays.
It's an interesting idea. Given the formula
=GLOBAL_(√, LAMBDA(x,SQRT(x)))
The following code could be inserted into a new VBA module:
Dim namedef(1) As String
Function GLOBAL_(ParamArray args()) As Boolean
Application.Volatile False
Formula = Trim(Mid(Application.ThisCell.FormulaLocal, 2))
Namestr = Mid(Formula, InStr(Formula, ",") + 1)
namedef(1) = "=" & Left(Namestr, InStrRev(Namestr, ")") - 1)
namedef(0) = Mid(Split(Formula, ",")(0), 9)
Evaluate "addname()"
GLOBAL_ = True
End Function
Function addname()
Names.Add namedef(0), namedef(1)
End Function
This appears to do the job on my setup (tested without access to LAMBDA). Clearly there is room for improvement in the string parsing to handle more general cases.
The reservation I would have with worksheet functions like GLOBAL is introducing the ability to alter workbook state which is not strictly consistent with the functional programming paradigm. Possible side effects may include losing undo and changing range dependencies within the workbook during a calculation cycle.
A button or hyperlink upload tool would be a safer approach at the expense of additional user interaction.
P.S. The attachment contains the following modification to the GLOBALλ definition:
= LAMBDA(name,λfn,IF(GLOBAL_(),λfn))This might allow Peter's original formulation to work:
=GLOBALλ(√, LAMBDA(x,SQRT(x)))(25)