Re: NETLink - CREATING a new class?
- To: mathgroup at smc.vnet.net
- Subject: [mg45115] Re: [mg45085] NETLink - CREATING a new class?
- From: "Werner Schuster" <werner.schuster at netway.at>
- Date: Wed, 17 Dec 2003 07:54:31 -0500 (EST)
- References: <200312161121.GAA24769@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
> Question:
> Is it possible to COMPLETELY do .NET programming from within
> Mathematica?
Well... you answered your questions yourself anyway;
> [And ultimately, to write an interactive .NET programming tool inside
> Mathematica, that would convert my mathematically-rigorous
> representation of algorithms into .NET code, that could be analyzed from
> Mathematica.]
Hmm... I am not sure what you want to do;
.Net/Link as well as J/Link basically offer a connection between the
M_-kernel
("M_" === "Mathematica")
and .Net and Java; you can either call M_ functions from .Net orJava or
script .Net or Java using M_ code;
What you want in the paragraph above sounds more like you want to
have an Mathematica -> .Net (CLR) compiler; at least it sounds like it,
as you want to convert code (algorithms) written in M_ into .Net code;
You can intermingle M_ code and .Net code pretty tightly, but when
you call M_ code, you just about always call code in the M_-Kernel;
for instance, a function like "Sin[]" is implemented in C(++) code in the
M_-Kernel
(I suppose it is, if it is not, take some function that is);
The Problem with that is: as soon as you call a function in the M_-Kernel.
you have to use MathLink to do that; this has some overhead, as Mathlink is
basically a protocol for transporting M_-Expressions. This means, that
frequent invocation of M_-functions using Mathlink (.Net/Link and J/Link
use Mathlink) is not a good idea and a sure way to kill your performance.
But maybe you are aware of that, and I just misunderstood your ideas;
> 1. Create new types (abstract interfaces) and new classes.
> The hard part: these must INHERIT from fundamental classes provided
> in the .NET Common Language Runtime (CLR).
Possible with CodeDOM (as you mentioned in your other mail);
Though I think, users would basically have to define their classes
in a manner similar to CodeDOM; ie. something along the lines of
this PseudoCode:
cl = NetLinkCreateNewClass["fooClass", "Foo.Package.List"];
(* cl is now a class derived from Foo.Package.List *)
NetLinkAddMethod["fooBar", symbolOfMathematicaMethod];
...
NetLinkLoadClass[cl];
... now use the class...
Hmm... I am not sure, I would like to program like that; though, some
better syntax or API to use this functionality might be found.
J/Link uses some form of what you want by using the Java Dynamic Proxy API;
this allows you to assign Handlers for Methods of a Java Interface;
example:
public interface Foo{
public void bar();
}
Now, say you want to create an object whose class implements type Foo,
that invokes an M_-function when the "bar()" method is invoked; this is
possible
with J/Link (see the details at
http://documents.wolfram.com/v5/Add-onsLinks/JLink/Part1.InstallableJavaCallingJavaFromMathematica/JLink1.2.17.html
)
murphee
- References:
- NETLink - CREATING a new class?
- From: ToolmakerSteve@shawstudio.com (ToolmakerSteve)
- NETLink - CREATING a new class?