M2 icon indicating copy to clipboard operation
M2 copied to clipboard

overriding methods implemented internally

Open antonleykin opened this issue 12 years ago • 2 comments

It appears that one can override methods implemented internally, but can't use them.

toList Matrix := M -> flatten entries M
M = matrix{{1}}
class M
toList M

stdio:4:1:(3): error: expected list, sequence, or set

antonleykin avatar Nov 19 '13 08:11 antonleykin

Yes, some functions are not actually method functions. Probably we should give an error message when adding methods. Can you make an issue about that on github?

i1 : res

o1 = resolution

o1 : MethodFunctionWithOptions

i2 : toList

o2 = toList

o2 : CompiledFunction

i3 : toList Matrix := x -> "foo"

o3 = {*Function[stdio:3:20-3:20]*}

o3 : FunctionClosure

i4 : toList matrix {{1}}
stdio:4:1:(3): error: expected list, sequence, or set

On Tue, Nov 19, 2013 at 3:52 AM, antonleykin [email protected]:

It appears that one can override methods implemented internally, but can't use them.

toList Matrix := M -> flatten entries M M = matrix{{1}} class M toList M

stdio:4:1:(3): error: expected list, sequence, or set

— Reply to this email directly or view it on GitHubhttps://github.com/Macaulay2/M2/issues/62 .

DanGrayson avatar Nov 19 '13 15:11 DanGrayson

Why is this not easily doable?

i1 : toList Matrix := M -> flatten entries M

o1 = -*Function[stdio:1:20-1:39]*-

o1 : FunctionClosure

i2 : lookup(toList, Matrix)

o2 = -*Function[stdio:1:20-1:39]*-

o2 : FunctionClosure

i3 : toList matrix{{0}}
stdio:4:1:(3): error: expected list, sequence, or set

Maybe there can be something like

toList = method(InternalFunction => toList)

which calls methods toList (which are "fake" methods from typicalvalues.m2) and replaces each of those with an actual method function.

Then we could call this on all internal functions mentioned in typicalvalues.m2.

mahrud avatar Feb 09 '21 22:02 mahrud