Deprecation of has_keys
Closed this issue · 0 comments
Currently there is the function has_keys(arg., list.) which will take the list of indices the right hand side and return a list with boolean values for each element. E.g.
has_keys({'a':0,'c':1}, ['a','b','c'])
[true, false, true]
This is ok, but has two major shortcomings.
- Most functions now are left conformable, so the shape of the result is the same as the left argument. This makes chaining functions a snap f(g(h(larg., rarg.),...)
- Having a list of elements means having to explicitly loop over everything rather than use the implicit looping that QDL excels at.
Therefore, a new function has_key(l_arg., r_arg.) (note there is no final s) has been introduced that works like it should., E.g.
ccc.:={'a':0,'b':1,'c':2};
ddd.:={'a':[0,1,2,3,4], 'b':-1, 'c':2, 'd':3, 'e':4};
has_key(ccc.,ddd.)
{a:true, b:true, c:true}
has_key(ddd., ccc.)
{a:true, b:true, c:true, d:false, e:false}
In other words, has_key gives a map of keys so we can just compare them and do things like select elements without looping:
mask(has_key(ccc., ddd.), ccc.)
{a:0, b:1, c:2}
Takes the elements in ccc. that are in ddd. (Using has_keys would require taking the result, then creating a stem that conforms to the arguments of mask, which is just annoying, or just writing out loops that do what mask does, which defeats the purpose of having a function for mask.)
Also, this affords a scalarized version, that checks if a single index is in a stem:
has_key(i, r_arg.)
returns a boolean if i is an index in r_arg. E.g.
has_key('a', ddd.)
true
**Therefore, the proposal is to deprecate has_keys and eventually remove it from the system, since it just is not that useful, hence mostly unused. **