Thomas D. Dean on Fri, 24 Nov 2023 08:16:39 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Lookup Table


I want to create a sparse lookup table with a key and value or key and set.
When I do table[N], or a function call, I want to get back either 1 or 0. Another use, I want to return a set, {1,2,3,...} or {}.

For example, I want table[N] to return 0 if entry N exists or 1 if it does not.

I tried
? M=Map();
%131 = Map([;])
? mapput(~M,7,0)
? mapget(M,7)
%133 = 0

Does mapget(M,7) use pass by value or is M passed by reference?

? mapget(M,8)
  ***   at top-level: mapget(M,8)
  ***                 ^-----------
  *** mapget: nonexistent component in mapget: index not in map
  ***   Break loop: type 'break' to go back to GP prompt


Is it possible to do this?