Macaulay2 / M2

The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields.
https://macaulay2.com
343 stars 230 forks source link

memoize and options #3491

Open mahrud opened 1 week ago

mahrud commented 1 week ago

Should memoize be sensitive to options?

I can see arguments both ways:

  1. sometimes the options contain important parameters, like coefficient ring or variable name (e.g. see https://github.com/Macaulay2/M2/pull/3481#discussion_r1768381949);
  2. on the other hand, sometimes options are just verbosity level or strategy, and if the code has already run maybe we don't care about that.

I don't think using memoize (as opposed to other means of caching) should be recommended anyway, so maybe this is a moot point.

pzinn commented 2 days ago

Note that it's not so easy to use memoize with say a method with options, as I think I pointed out in some other thread. e.g., givin

f= method(Options=>new OptionTable from{a=>1})

neither

f ZZ := o -> memoize(x -> (print (x,o#a); x+o#a))

nor

f ZZ := memoize(o -> x -> (print (x,o#a); x+o#a))

will work, as can be checked by applying repeatedly. this does work:

f ZZ := memoize(o -> memoize(x -> (print (x,o#a); x+o#a)))

but seems heavy. If one wants to ignore the option for memoize purposes, I don't even know any simple option.