Problem with dictionary addon

33 views
Skip to first unread message

Devon McCormick

unread,
Jan 13, 2026, 11:44:50 PM (2 days ago) Jan 13
to forum

Hi - I was putting together an intro to the new dictionary addon, at the latest NYCJUG meeting - https://code.jsoftware.com/wiki/NYCJUG/2026-01-13#Populating_a_Dictionary - and ran into some problems.

I want to build a dictionary with extended integers as a key and the factors of that integer as the corresponding value. However, specifying ('keytype'; 'extended') did not allow me load my data. As a work-around, I specified both key and value as type "boxed" and was able to populate the dictionary but retrieval failed. I also converted the numbers to characters as boxed numbers did not appear to work.

Most puzzlingly, it did not fail for every case so I must have done something right, or at least half-right. Here's how to reproduce the issue:

   ]nums=. 1+10^i.5x
2 11 101 1001 10001
   ]factors=. q:&.>nums
+-+--+---+-------+------+
|2|11|101|7 11 13|73 137|
+-+--+---+-------+------+
   params=: 'tree',&< ('keytype'; 'boxed') ,: ('valuetype'; 'boxed')
   prms=: params conew 'jdictionary'
   (":&.>nums) put__prms ":&.>factors    NB. Populate
   get__prms <":0{nums
+-+
|2|
+-+
   get__prms <":1{nums
+--+
|11|
+--+
   get__prms <":2{nums
+---+
|101|
+---+
   get__prms <":3{nums
|index error: get__prms
|get__prms[0]
      13!:19''
   get__prms <":4{nums
|index error: get__prms
|get__prms[0]
      13!:19''
   get__prms <":1{nums    NB. make sure this still works
+--+
|11|
+--+

Even more interestingly, when I did this same exercise with nums=. 1+10^i.10x, only the gets for 1 & 2 worked - 0 failed.

Please let me know what you think.

Devon McCormick

Devon McCormick

unread,
Jan 14, 2026, 12:19:07 AM (2 days ago) Jan 14
to forum, Devon McCormick
I just encountered this after defining a dictionary as
   prms=: ('tree',&< ('keytype'; 'extended') ,: ('valuetype'; 'boxed')) conew 'jdictionary'

When I entered put__prms for display, my session crashed:
      put__prms

Process shell<1> exited abnormally with code 5

Marcin Żołek

unread,
Jan 14, 2026, 2:21:12 AM (2 days ago) Jan 14
to fo...@jsoftware.com, Devon McCormick
Great to see dictionaries featured in NYCJUG!

Regarding the first issue, the verbs put, get, has, and del take key(s) as their right argument. In put, the numbers and factors are swapped (factors are keys), so only prime numbers ended up with the same key and value in the dictionary.

Extended integers can be used as keys as well:

   ]nums=: 1+10^i.5x

2 11 101 1001 10001
   ]factors=. q:&.>nums
┌─┬──┬───┬───────┬──────┐
│2│11│101│7 11 13│73 137│
└─┴──┴───┴───────┴──────┘
   load 'dictionary'
   prms=: 'jdictionary' conew~ 'tree' ,&< ('keytype' ; 'extended') ,: 'valuetype' ; 'boxed'
   factors put__prms nums
   get__prms 2
┌─┐
│2│
└─┘
   get__prms _2 {. nums
┌───────┬──────┐
│7 11 13│73 137│
└───────┴──────┘
 
Marcin
Reply all
Reply to author
Forward
0 new messages