Menu ▾ ▴

#986 declare refuses subscripted variables and other non atoms

None
open
nobody
7
2022-02-27
2006-09-12
No

declare refuses subscripted variables and other non
atoms. E.g.

(%i25) declare (foo[1], integer);

Improper argument to declare:
foo[1]

declare should at least recognize variables with
literal subscripts (e.g. foo[1], bar[2], baz[3]).

declare might also recognize other kinds of expressions
such as variable subscripts (e.g. foo[n]), unevaluated
function calls (e.g. foo(x)), or maybe arbitrary
expressions (e.g. sin(foo(x) + bar[y]) + baz).

At present declarations are stored in the property list
of the symbol for the declared symbol. I don't know how
we would modify that to store declarations for nonatoms.

Discussion

  • Robert Dodier

    Robert Dodier - 2006-09-12

    Logged In: YES
    user_id=501686

    Need to review featurep and beef it up to look for
    properties associated with foo[1] or whatever, if it can't
    do that already.

     
  • Barton Willis

    Barton Willis - 2006-09-13

    Logged In: YES
    user_id=895922

    It would be nice to ditch Maxima's property list scheme for
    storing information and place all such data into hash
    tables. But Maxima uses mget, zl-get, safe-get, safe-mget,
    get, and maybe other methods for retrieving data from
    property lists, so changing to hash tables could be a big
    job and cause lots of bugs.

    We could have subscripted variables inherit the properties
    of the subscribed symbol; thus n[1] is an integer if n is a
    declared integer. But if 'x' was declared nonscalar, few
    would like for x[1] to also be nonscalar.

     
  • Robert Dodier

    Robert Dodier - 2022-02-27
    • labels: Lisp Core - Assume --> declare, subscripted variables
    • Group: --> None
     
  • Robert Dodier

    Robert Dodier - 2022-02-27

    I'm kind of leaning towards having subscripted variables inherit declarations from the simple variable, but I do see the problem with x being declared nonscalar, and then x[1] being inferred nonscalar. Hmm. Not sure what to think about that.

    For what it's worth, looking at ? declare, it looks like nonscalaris the only declaration which has that problem. Not sure if that should make a difference.

    I agree that one solution is to keep declarations in a hash table, but it does seem kind of messy, both for declarations (e.g. if x[i] has a property, does x[j] have it too) and where the declarations are used in the Lisp code. I think I'm inclined to consider such inheritance all or nothing -- either all subscripted variables inherit properties, or none do. Either way there are problems, but at least the whole situation is more comprehensible.

     
  • Robert Dodier

    Robert Dodier - 2022-02-27

    Note that implementing the proposal mentioned here would change the existing behavior as described in bug #3180. Not sure what to think at this point.

     

Log in to post a comment.