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 231 forks source link

bug in ??= and mutable hash tables #3351

Closed mahrud closed 2 months ago

mahrud commented 3 months ago

Why is this happening?

i1 : X = Proj QQ[x];

i2 : X.sheaf ??= ring X

o2 = QQ[x]

o2 : PolynomialRing

i3 : X.sheaf ??= ring X
stdio:3:9:(3): error: expected method to be a function or TYPE => function'

cc: @d-torrance

d-torrance commented 3 months ago

It's because QQ[x] is a PolynomialRing, which inherits from Type, and Type ??= is syntactic sugar for calling installMethod to install a ??= method for a given type. So it's yelling at us that ring X isn't a function.

Your use case definitely seems more important than having that particular syntactic sugar. I'll open a PR soonish removing it (probably in the next few days).

mahrud commented 3 months ago

Hmm shouldn't the syntax for installing ??= methods have a key like ((??=, =), Type, Type)? What is an example of using this syntactic sugar?

d-torrance commented 3 months ago

Right now they key is just ??=. So installMethod(symbol ??=, T, f) will set it so that x ??= y (when x is an instance of T) will call f(x, y).

I don't think the syntactic sugar is currently used anywhere outside of the documentation (see installing augmented assignment methods

mahrud commented 3 months ago

I'm not sure if I understand. In the bug above, is Type ??= Type triggering a syntactic sugar for installing a method on (symbol ??=, Type)? I can't figure out how to use this syntactic sugar without installMethod.

d-torrance commented 3 months ago

It's installing a method on (symbol ??=, QQ[x])