Menu ▾ ▴

#3721 arrayinfo fails on hashed array created by make_array(hashed, ...)

None
closed
nobody
5
3 days ago
2021-02-24
No

arrayinfo fails on a hashed array created by make_array(hashed, ...) although arrayinfo handles a hashed array created by use_fast_arrays: true and then assigning to elements of the array.

Looks like arrayinfo is constructing the key list incorrectly for hashed arrays created by make_array(hashed, ...). Dunno how those differ from the ones created by use_fast_arrays: true.

%o4 is actually incorrect here; it should be [hash_table, 1, [aaa]].

(%i1) hh1: make_array (hashed, 1);
(%o1)    {Lisp Array: #<HASH-TABLE :TEST EQUAL :COUNT 1 {100276D563}>}
(%i2) hh1["aaa"]: 123;
(%o2)                                 123
(%i3) trace(arrayinfo);
(%o3)                             [arrayinfo]
(%i4) arrayinfo(hh1);
1 Enter arrayinfo [hh1]
1 Exit  arrayinfo [hash_table, 1, aaa]
(%o4)                        [hash_table, 1, aaa]
(%i5) hh2: make_array (hashed, 2);
(%o5)    {Lisp Array: #<HASH-TABLE :TEST EQUAL :COUNT 1 {100277DB23}>}
(%i6) hh2["bbb", "ccc"]: 9392;
(%o6)                                9392
(%i7) arrayinfo (hh2);
1 Enter arrayinfo [hh2]
1 Exit  arrayinfo [hash_table, 1, (bbb, ccc)]
Maxima encountered a Lisp error:

 The value
   "bbb"
 is not of type
   SYMBOL
 when binding SYMBOL

Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
(%i8) use_fast_arrays: true $

(%i9) hh3["ddd", "eee"]: 9121;
(%o9)                                9121
(%i10) arrayinfo (hh3);
1 Enter arrayinfo [hh3]
1 Exit  arrayinfo [hash_table, true, [ddd, eee]]
(%o10)                  [hash_table, true, [ddd, eee]]

Discussion

  • Kris Katterjohn

    Kris Katterjohn - 2021-02-25

    While working on the translator I've stumbled across a couple other (interpreted and translated) array-related bugs.

    If nobody beats me to it then I'll look into this bug too while working on those other ones.

     
  • Robert Dodier

    Robert Dodier - 2022-09-01

    I bumped into this bug again and it looks like the current behavior hinges on the presence or absence of the key DIM1 for the hash table. It appears that DIM1 being present as a hash key means that the hash table has 1 index, otherwise it has multiple indices.

    When DIM1 is absent, arrayinfo returns the list of keys as [..., [a, b, c], [d, e, f], ...], i.e. each key (third and later items) is a list. However, when DIM1 is present, arrayinfo returns [..., a, b, c, ...], i.e. each key is a simple item, not a list such as [... [a], [b], [c], ...] as one might expect by analogy with two or more keys.

    Note that make_array(hashed, 2) actually defines a hash table with ONE key, not two. So hh2: make_array(hashed, e); hh2["bbb", "ccc"]: ... is incorrect -- there's an inconsistency between the number of keys declared and used. That's probably a bug in array assignment -- it should detect the inconsistency and refuse the assignment.

    At this point I guess it looks like the bug is actually in array assignment; it should detect and reject the inconsistency.

    I think the DIM1 business is suboptimal, since it makes one key results different from two or more. I'm kind of leaning towards expunging DIM1 and making arrayinfo results consistent between one and two or more keys, but that's beyond the scope of this bug.

    Also, another wart is that make_array(hashed, foo, bar, baz) doesn't actually make use of foo, bar, or baz, or even how many there are exactly; only whether there's one or two or more. Not sure how to clean that up. Maybe just accept one argument, which is an integer telling the number of keys (as I was implicitly assuming when I wrote this bug originally).

     
  • Robert Dodier

    Robert Dodier - 3 days ago
    • status: open --> closed
     
  • Robert Dodier

    Robert Dodier - 3 days ago

    arrayinfo seems to have gotten fixed at some point. About other issues that were raised, see bugs #5800 and #5801.

     

Log in to post a comment.