Skip to main content
July 22, 2022
Question

Underscore using within functions

  • July 22, 2022
  • 6 replies
  • 0 views

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
July 22, 2022

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

July 22, 2022

Thank you GopalK,

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

mikes0011
Brainy
July 22, 2022

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.