qtspecs icon indicating copy to clipboard operation
qtspecs copied to clipboard

$sequence-of-maps ? info()

Open michaelhkay opened this issue 9 months ago • 4 comments

We're increasingly using the design pattern where maps contain entries that are function items. If $map is a map and it has an entry info that is a zero-arity function, then $map ? info() invokes the function. This looks appealingly as if it's a method application applying the method info() on the object $map, but that's not actually what's really going on underneath. What is really happening is that we evaluate ($map ? info) which yields a function item, and then we dynamically call this function.

Now what if $maps is a sequence of maps each of which has an info field? This parses as ($maps ? info)(). $maps ? info returns a sequence of function items, and a dynamic function call can't be applied to a sequence of functions items. Instead you have to write ($maps ? info)!.() which feels fairly bizarre.

Should we allow the LHS of a dynamic function call to be a sequence? On the whole, I don't tend to like operations to do implicit mapping over one of the arguments, but I feel like this might warrant an exception. The justification is that a dynamic function call is a postfix expression, and all the other postfix expressions accept a sequence on the LHS. Thoughts please.

michaelhkay avatar May 23 '24 16:05 michaelhkay