numbers as keys are somewhat accidentally supported because the tosym function 
returns y if y can't be converted directly to symbols.  The error handling was 
meant to pass along symbols unchanged, but has same feature for numbers.


  4 kvget 3 4 5 kv 3 2 $ 'abc'

ca

The dsLs that allow string description of dictionaries also support numeric 
keys by using the gerund form of the dsL adverbs.  the u form of the adverb 
just processes/parses the right of ` in string (values section), while f`u 
applies f to the key section, u to values section.

4 kvget ".`cut kvdsL ' 3 4 5 ` a bc g'

bc


What isn't supported is mixing numbers and symbols as keys.  They can be mixed 
as values because they will be autoboxed.  Number keyed dictionaries embedded 
in other dictionaries will be hard to access with "dsl paths", but forming the 
path manually will give deep access.

 ('top';5) kvgetd 'top' kv < ".`cut kvdsL ' 3 4 5 ` a bc g'

g 


  ('top'; 4) kvgetd ('top' kv < 4 5 kv > cut 'dd ee') kvsetd 'top' kv < ".`cut 
kvdsL ' 3 4 5 ` a bc g'

dd


> tutorial 

almost all functions (except kvdsL) are dyadic.  In above examples cutting from 
left the x v portions of x v y will provide the intermediate results of right 
uncut expressions.  kvtest has a series of function calls that provide examples 
of all functions.





> function filtering values

G1 -: kvvals  NB. values is just 1 {:: dictionary

  G1 'top' kvget 'top' kv < ".`cut kvdsL ' 3 4 5 ` a bc g'  NB. unwrap embedded 
dict before getting deep values

a
bc
g 

kvi is a function that will "filter" dictionary by index list x.  kvdi deletes 
by indexes.

so filtering by values by creating a hook with kvi~ 
functionThatEvaluatesIndexes 

  4 kvget (kvi~ ('b' I.@:= {."1)@:G1) ".`cut kvdsL ' 3 4 5 ` a bc g'

bc

kvvals 0 2 kvi ".`cut kvdsL ' 3 4 5 ` a bc g'

a
g 

kvfilt and kvfiltall will filter dictionary by list of keys.  The all version 
returns duplicate keys if any.  kvdel and kvdelall are "inverse filters" by 
keys.

kvQ is a "query language" for inverted tables (when all keys in dictionary hold 
a boxed table, representing 1 column per key)


> filter with predicates both for key and value?

doing them in sequence,

G1 'g' (] kvi~ I.@:(padstrmatch G1)) 4 kvdel ".`cut kvdsL ' 3 4 5 ` a bc g'

g 




On Saturday, February 19, 2022, 04:33:59 a.m. EST, Pawel Jakubas 
<jakubas.pa...@gmail.com> wrote: 





Hi Pascal,

Thanks for the release. Couple questions:
1. Can key be number, if not why not?
2. Any chance to add user friendly tutorial how to use every kv function
and what are consequences/peculiarities in such a way that one can by
copy-pasting get the same result and understand them?
3. What about function filtering values, maybe having filter with
predicates both for key and value?
Thanks,
Pawel
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to