Dictionary not updating?

22 views
Skip to first unread message

douglas mennella

unread,
Jan 5, 2022, 6:00:57 AM1/5/22
to Kona Users
Hi, I'm still new to kona so maybe there's something I'm not understanding.  I was trying to make an index of which words in a given dictionary can be made from the letters of what other words.  I was using the COMMON.txt set of words found at Project Gutenberg.

The idea was to make a key for each word comprised of the sorted list of letters contained in the word and to make a dictionary matching each key with the words sharing the same key like so:

  wds:0: `"/tmp/COMMON.TXT"
  idx:{lts:{l@<l:x@*:'=:x}'x;ix:lts[*:'=lts];(ix[<ix];(=lts)[<ix])} wds
  l2w:.+(`$'*idx;*|idx)

That works fine.  The next step was to sort the keys by length and then update each dictionary entry by appending the list of each of its subkeys.  Since I'm going from shortest to longest, I should only need to check keys one letter shorter.  The trouble is this wasn't updating the dictionary.

{l2w[`$x],:g@*:'=g:,/{:[@x;();x]}'l2w[`$x@&:'(!#x)!\:~~!#x]}'{i@<#:'i:i@&~7<#:'i:x@&97<_ic',/1#'x} *:idx

I was worried that "each" might be doing some parallelizing and thus missing earlier stages.  Can that happen?  I tried to work around that possibility with the following:

que:{i@<#:'i:i@&~7<#:'i:x@&97<_ic',/1#'x} *:idx
while[0<#que;{l2w[`$x],:g@*:'=g:,/{:[@x;();x]}'l2w[`$x@&:'(!#x)!\:~~!#x]}*:que;que:1_ que]


If I add output it at least seems to be running sequentially.  But neither of these seem to update l2w.  But when I run the following from the REPL I do see a change.

  w:"abcdekt"
  que?w
10835
  l2w[`$w]
,17437
  {l2w[`$x],:g@*:'=g:,/{:[@x;();x]}'l2w[`$x@&:'(!#x)!\:~~!#x]}w
17437 17439
  l2w[`$w]
17437 17439


It even worked when I processed this out of a queue:

  w:"abcdekt"
  que:,w
  l2w[`$w]
,17437
  while[0<#que;{l2w[`$x],:g@*:'=g:,/{:[@x;();x]}'l2w[`$x@&:'(!#x)!\:~~!#x]}*:que;que:1_ que]
  l2w[`$w]
17437 17439


Demonstrating all of this in one go, I have this:

wds:0: `"/tmp/COMMON.TXT"
idx:{lts:{l@<l:x@*:'=:x}'x;ix:lts[*:'=lts];(ix[<ix];(=lts)[<ix])} wds
l2w:.+(`$'*idx;*|idx)

que:{i@<#:'i:i@&~7<#:'i:x@&97<_ic',/1#'x} *:idx
w:"abcdekt"
que?w
l2w[`$w]
while[0<#que;{l2w[`$x],:g@*:'=g:,/{:[@x;();x]}'l2w[`$x@&:'(!#x)!\:~~!#x]}*:que;que:1_ que]
l2w[`$w]
que:,w
while[0<#que;{l2w[`$x],:g@*:'=g:,/{:[@x;();x]}'l2w[`$x@&:'(!#x)!\:~~!#x]}*:que;que:1_ que]
l2w[`$w]


Which produces the following output after a couple of minutes:

kona      \ for help. \\ to exit.

10835
,17437
,17437
17437 17439


Why would it work out of the shorter queue but not the longer one?  It's clearly in both.  Should I report this as a bug or am I misunderstanding?

Thanks,
-Doug

douglas mennella

unread,
Jan 5, 2022, 6:12:47 AM1/5/22
to Kona Users
I assume maybe it's something like it's updating a local variable and not the one at the outer scope, but the following didn't help.

{l2w[`$x]::l2w[`$x],g@*:'=g:,/{:[@x;();x]}'l2w[`$x@&:'(!#x)!\:~~!#x]}'{i@<#:'i:i@&~7<#:'i:x@&97<_ic',/1#'x} *:idx


Do I have the syntax wrong?  Even if it was this, I don't understand the difference between the two different queues above.  Also, this didn't parse:


{l2w[`$x],::g@*:'=g:,/{:[@x;();x]}'l2w[`$x@&:'(!#x)!\:~~!#x]}'{i@<#:'i:i@&~7<#:'i:x@&97<_ic',/1#'x} *:idx

douglas mennella

unread,
Jan 5, 2022, 6:18:14 AM1/5/22
to Kona Users
This works as well:

  l2w[`$w]
,17437
   {.k.l2w[`$x],:g@*:'=g:,/{:[@x;();x]}'l2w[`$x@&:'(!#x)!\:~~!#x]}',w
,17437 17439
  l2w[`$w]
17437 17439

douglas mennella

unread,
Jan 5, 2022, 9:17:47 AM1/5/22
to Kona Users
Sorry.  This is my mistake.  That index is the size of the array meaning that that string is not being processed.  So far it looks like those which are in the list are being processed.  My bug is somewhere else.  Sorry for the noise.

douglas mennella

unread,
Jan 5, 2022, 9:22:50 AM1/5/22
to Kona Users
Dang..  Spotted it.  _ic["a"] = 97.  I want keys which start with a character > 96, not > 97.

Kevin Lawler

unread,
Jan 5, 2022, 11:11:13 AM1/5/22
to kona...@googlegroups.com
np. glad you found it
> --
> You received this message because you are subscribed to the Google Groups "Kona Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kona-user+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kona-user/3c6ad517-5d01-4c08-8317-6f087cf2e07fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages