[Parrot-users] does, multi sub, or.... more language philosophy
Andrew Whitworth
wknight8111 at gmail.com
Wed Jul 6 18:11:29 UTC 2011
I was working on a port of MATLAB/Octave to Parrot a while back, which
had very similar semantics (most data objects were matrices, not
scalars, etc). What I would suggest you do is create your own custom
subclass of an array type, instead of trying to hack together all the
semantics you need on top of the existing types. You can override the
"does" vtable in your custom type to indicate different states, then
use the "does" vtable to query those. Here is an example:
class MyVectorType {
has $!length;
has $!width;
method does($role) is vtable {
if ($role eq "scalar" && $!length == 1 && $!width == 1) { return 1; }
if ($role eq "vector" && ($!length == 1 || $!width == 1) { return 1; }
if ($role eq "matrix") { return 1; }
return 0;
}
}
...
if (pir::does($arg, "scalar")) { ... }
I hope that helps.
--Andrew Whitworth
On Wed, Jul 6, 2011 at 1:54 PM, Jay Emerson <jayemerson at gmail.com> wrote:
> Thanks to Will Coleda for letting me about 'does' (which is terribly
> hard to google, sadly), and providing a concise multi sub example as
> an alternative. I see how both work. The language I'm working on in
> its most basic form (R) has no scalar:
>
> a = 5
> b = 1:3
>
> Both are vectors, the first of length 1, the second of length 3. I
> would think there is a certain simplicity to this, as subsequent
> methods would only be needed for arrays (handling the length
> appropriately for the context) rather than treating the former as an
> object of a different type. However, maybe I'm thinking at the
> "high-level" of the user rather than the "low-level" of the
> implementation of the language. Any advice?
>
> Jay
>
>
> --
> John W. Emerson (Jay)
> Associate Professor of Statistics
> Department of Statistics
> Yale University
> http://www.stat.yale.edu/~jay
> _______________________________________________
> Parrot-users mailing list
> Parrot-users at lists.parrot.org
> http://lists.parrot.org/mailman/listinfo/parrot-users
>
More information about the Parrot-users
mailing list