Skip to main content
Known Participant
Jul 22, 2022 1:25 PM UTC
Question

Underscore using within functions

Hi,

In some ER code, I have found this kind of things :

rule!APP_GreaterTo(value: _, to: 14),

or :
      contains(
        reject(
          isnull(_),
          ri!names
        ),
        tostring(ri!name)
      ),                                                 
Could you explain me what does mean that "_" ?
is it just to specify we do not want to pass any parameter in the function ?  (because "isnull()" is not authorized)
but why "value: _"  in place of "value: null" ?

6 replies

gopalk2865
Participating Frequently
Jul 22, 2022 1:33 PM UTC

Underscore is used for partial evaluation.it gives you ability to evaluate the function without having that value defined yet.

Known Participant
Jul 22, 2022 1:37 PM UTC

Thank you GopalK,

I'd never thought of such an ability...

mikes0011
Brainy
Jul 22, 2022 1:40 PM UTC

It's not used much anymore, because it was only ever required in the legacy looping functions, and the only one that can't be fully replaced by a!forEach(), is reduce() (sadly).  But we don't need reject() or apply() anymore, so there aren't all that many cases where the _ operator is still needed - which is good because even those of us who knew how to use it, still tended to be fairly confused by it.

The Expression Guru