Forum Discussion
Legacy EVALUATE in LAMBDA: Build/Test LAMBDAs from Sheet
I tried to play with some of your ideas but it may be that EVALUATE has some limitations when applied to modern dynamic arrays.
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.
- PeterBartholomew1Feb 20, 2021Silver Contributor
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.