Message Boards Message Boards

MTools, Object Oriented Programming in Mathematica 10+

Posted 9 years ago
POSTED BY: Faysal Aberkane
2 Replies

enter image description here - you earned "Featured Contributor" badge, congratulations !

This is a great post and it has been selected for the curated Staff Picks group. Your profile is now distinguished by a "Featured Contributor" badge and displayed on the "Featured Contributor" board.

POSTED BY: EDITORIAL BOARD

For many years I have been asking myself how I could avoid the rule that was responsible for method resolution using the Villegas-Gayley pattern:

HoldPattern[class[params___].(f:Except[super])[args___] /; !TrueQ[$blockSub[class, f]] ] :> class[params].sub.f[args]

Although the method worked, it slowed down the evaluation of methods. I managed to find another mechanism that can rely solely on the traditional mathematica evaluation using UpValues.

The key idea consists in storing method definitions using the form o_MyClass.this.f[x_] instead of o_MyClass.f[x_] (the rewriting is done automatically, existing code still works). This then avoids having to intercept method calls of the form o.f[] using the rule above that was previously required.

There was also a sub funtion responsible for executing a given definition (Class[object].sub.f[]) that is not used anymore, that's why I'm bumping the version by 1 in the first part of the version.

My estimate is that the new method resolution is at least two times faster than before.

POSTED BY: Faysal Aberkane
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract