Forum Discussion
Legacy EVALUATE in LAMBDA: Build/Test LAMBDAs from Sheet
PeterBartholomew1In researching this further, I've covered territory that you and lori_m were traversing prior to the implementation of dynamic arrays: de-referencing and coercion! Due to the primordial nature of EVALUATE, these results would previously have required CSE I think, so we have to provide some incentive at times for it to give us what we want. Please see attached! I'm glad this is a thing of the past, but it is very interesting to learn about, kind of like working on your own car.
Well done. I was sure I had tried the old
N(IF(1,arr))
formula in the INDEX but clearly I got something wrong.
I decided that, if I wasn't allowed 'n' as a formula-local name, I would switch to Unicode symbols.
One perfectly legal Lambda that I amused myself with recently was
= √(x²+y²)
- tbouldenFeb 21, 2021Iron Contributor
PeterBartholomew1I'm afraid I'm not picking up your comment re: the hypoteneuse LAMBDA, perhaps I'm dense?
I've got another bit of troubleshooting I might like your help with, if you'll indulge me. As originally stated in the thread subject, I'm trying to refine using EVALUATE to make a nice worksheet-based "environment" for testing LET/LAMBDAs during construction. I've recently tried putting together your FOREACH and XSTACK in this "environment" and run into trouble with FOREACH, particularly passing in a function as a parameter. If doing so with LET and EVAL, it works happily; for LAMBDA I'm extremely confused. I can pass in the Name Manager-based LAMBDA (Iterate, in this example) and the following construction returns "128" as expected:
=EVAL(LAMBDA(function,TYPE(function)))
However, if I try to apply function as in the following:
=EVAL(LAMBDA(function,function(1)))
I'm given #NAME?. Please see attached for more detail, and thanks in advance!
- PeterBartholomew1Feb 21, 2021Silver Contributor
I have only just seen your post so this represents fresh thoughts rather than a reply.
The attachment uses a problem with a 2-D array of number triples and seeks to return the maximum of each triple as an array. The problem arose within the Chandoo forum but the thing of interest for me was the structure and role of the nested λ-functions that may be combined to provide a solution.
I share your interest in providing techniques that make the modern function easier to use and debug. In this workbook, I have provided a VBA macro that allows the user to specify the λ-function as a working function on the spreadsheet. FORMULATEXT is used to make the formula visible and the function can be named and a comment provided. The macro uploads the name definition, by-passing the need for Name Manager.
I have also included a working version of the formula
= √(x²+y²)
within the second file. It is just 'smoke and mirrors' implemented using the λ-function, '√' which is defined to be
=LAMBDA(a,SQRT(a))
I think it does look prettier than
= IMABS(COMPLEX(x,y))
which will also do the job.
- tbouldenFeb 22, 2021Iron Contributor
PeterBartholomew1Marvelous, that is much more pleasant to look at!
I experimented with your Array MAX Item spreadsheet and added another LAMBDA I've been working on, see λ₃ in the name manager; your VBA code is a reasonable person's implementation of what I'm trying to do with it conceptually.
λ₃ = LAMBDA(name,arg₁,arg₂,arg₃,λ_EVAL(INDEX(Definitions,MATCH(name,Names,0))&"("&arg₁&","&arg₂&","&arg₃&")"))
I've introduced a sheet "Repository" with 2 named ranges "Names" and "Definitions", and populated them with the details for your LAMBDA Array, slightly massaged to cooperate with EVALUATE. λ₃ takes a name and 3 arguments, and does a look-up on the definition, concatenates the 3 args and the required trappings (I admit this is ugly, trying to come up with something cleaner). Once constructed, it then EVALUATEs it.
Use it in a cell like so =λ₃("Array",T,S,2) and it should be the same as your original construction =Array(T, S, 2). I've set this up with 1 arg = λ₁, 2 arg = λ₂, and now 3 arg = λ₃ and its worked with a little massaging.
However!! DataRange is a RANDARRAY introduces something I didn't suspect, but makes sense now that I've seen it. My λ₃ doesn't update as often as your Array function; I have to change something in the named ranges for the functions to be in sync. I tried doing a plain λ_EVAL in the sheet, which is worse! It only reacts to changes in the spill range.
Interesting!! My list of limitations is growing, though. As I said before, the VBA approach you're taking is seeming very reasonable at this point.