
Planet Parrot is an aggregation of select Parrot related blogs. You won't find anything about birdseed or molting here. The list of contributors changes periodically. You might also like to visit Planet Perl or Planet Perl Six for more focus on their respective topics.
Planet Parrot provides its aggregated feeds in Atom, RSS 2.0, and RSS 1.0, and its blogroll in FOAF and OPML
There is life on other planets. A heck of a lot, considering the community of Planet sites forming. It's the Big Bang all over again!
This site is powered by Python (via planetplanet) and maintained by Robert and Ask.

Planet Parrot is licensed under
a Creative
Commons Attribution-Noncommercial-Share Alike 3.0 United States
License. Individual blog posts and source feeds are the
property of their respsective authors, and licensed
indepdently.
VTABLE_add_i(interp, pmc, 5);
pmc->vtable->add_i(interp, pmc, 5);
pmc->vtable->base_type; // type number
pmc->vtable->whoami; // type name (Parrot STRING)
pmc->vtable->class; // Class or PMCProxy PMC for the type
VTABLE * tbl = interp->vtable[index];
$P0 = new ['Foo']
$P1 = find_method $P0, "bar"
callmethodcc $P0, $P1
PMC * p0 = Parrot_pmc_new(interp, type_Foo);
PMC * p1 = VTABLE_find_method(interp, p0, "bar");
setup_method_call(interp, p0);
VTABLE_invoke(interp, p1);
PMC * class = pmc->vtable->class;
PMC * methods = class->data->methods;
PMC * method = VTABLE_get_pmc_keyed_str(interp, methods, "bar");
The Perl 6 design team met by phone on 24 February 2010. Larry, Allison, Patrick, and chromatic attended.
Larry:
LEAVE-style phasers do not trip till after an exception is handled (and not resumed)* is no longer required to intuit the series on the left; the absence of generator before the ... operator is sufficient... is now always a limiter argument...^ form to exclude a literal limiter from the generated series^... or ^...^ ... pays attention only the portion of the list immediately to its left (plus the limit from the right)Any, and must explicitly declare Mu or Junction type to hold junctions== with Mu arguments; most of our failure values should be derived from Any in any caseMu result is more indicative of a major malfunction now, and is caught at first assignment to an Any variableInstant/Duration types are biased away from Num and towards Rat/FatRat semanticsInstant is now completely opaque; we no longer pretend to be the same as TAI, numerically speakingInstants are now considered a more basic type than epochs, which are just particular named instantsWhatever semantics now autocurry any prefix, postfix, or infix operator that doesn't explicitly declare that it handles whateverness itselfWhateverCode objects now take a signature to keep clear how many args are not yet curried*+* is now more like WhateverCode:($x,$y) * Slicel type to go with Parcel @array[1,2,3] differently from @array[1,2,3;4,5,6], for instanceMatcher type now excludes Bool arguments to prevent accidental binding to outer $_ when closure is neededwhen and ~~ will now warn of always/never matching on direct use of True or False names as matcher\w lookahead to all twigils now1 min 2 max 3 are now illegal, and require parenthesization for clarityTrigBase enumerationPatrick:
sort methodAllison:
c:
Allison:
Patrick:
Allison:
$P0 = new ['Foo']
$P0.'Bar'()
$P0 = new ['Foo']
$P1 = find_method $P0, 'Bar'
callmethodcc $P0, $P1
int num_classes = VTABLE_elements(interp, class->all_parents);
int i;
for (i = 0; i num_classes; i++) {
cur_class = VTABLE_get_pmc_keyed_int(interp,class->all_parents, i);
if (VTABLE_exists_keyed_str(interp, class->methods, name))
return VTABLE_get_pmc_keyed_str(interp, class->methods, name);
}
$P0 = getclass 'Foo'
$P0.'add_vtable_override'("bar")
$P0 = new ['Foo']
$P1 = getclass 'Foo'
$P2 = find_class_method 'Bar'
callmethodcc $P0, $P2
VTABLE PMC * find_class_method(STRING *name, PMC *mro_iterator)
$P0 = getclass "Foo"
$P1 = find_class_method $P0, "Frobulate"
VTABLE_find_class_method("Frobulate", NULL). Foo would then create an iterator over it's MRO (removing itself from the front of the list to avoid direct recursion) and passing that MRO iterator to Bar, which then calls the next item on the list (Baz). This has a few major advantages which are not necessarily obvious up front: Any object that defines find_class_method can be inserted into the MRO. This includes things that aren't really classes like Roles, Mixins, extension methods, and even autoloaders. Second, we gain more flexibility to modify the MRO of a class, because that class (and it's super-classes) can add additional search parents to the iterator as needed. We would also gain the ability to have more manual control over the MRO, because we could add a find_class_method_p_p_s_p op variant that also takes an existing MRO iterator. This would enable us to better implement something like a super() call, where we take the MRO iterator, manually pop the top item off it, and then call find_class_method with it. I've got several bonus points available to whoever can explain how to call a method in a super class when it's overridden in the subclass, without having to hard-code in the name of the parent class. With the new VTABLE and a new op, this becomes trivial.The Perl 6 design team met by phone on 17 February 2010. Larry, Allison, Patrick, and chromatic attended.
Larry:
<a b>, assignment, arguments, captures, parameters, signatures, gather/take, and loop returns)qw angles.Rat64's denominator automatically keep the string form around for coercion to other types.getobj to .getarg since arguments are the typical positional/slicey usagereturn, take, and loop return objects are also arguments in that sense$) variable error where ) is the $*GOAL WHAT etc. to list of functions that require an argumentAllison:
Patrick:
Allison:
Patrick:
sort and grammars over the next weekc:
exceptions are indications by running code that something unusual -- an "exception" to the normal processing -- has occurred. When code detects an exceptional condition, it throws an exception object. Before this occurs, code can register exception handlers, which are functions (or closures) which may (but are not obligated to) handle the exception. Some exceptions permit continued execution immediately after the throw; some don't.
Exceptions transfer control to a piece of code outside the normal flow of control. They are mainly used for error reporting or cleanup tasks.
When an exception is thrown, Parrot walks up the stack of active exception handlers, invoking each one in turn, but still in the dynamic context of the exception (i.e. the call stack is not unwound first).
Exception handlers can resume execution after handling the exception by
invoking the continuation stored in the 'resume' slot of the exception object. That continuation must be invoked with no parameters; in other words, throw never returns a value.
The die opcode throws an exception of type exception;death and severity
except_error with a payload of message. The exception payload is a string PMC containing message.
die 'Program is closing'
exit 0
die 5, 0
All exceptions will have at least message, severity, resume, and payload attributes.
count_eh Return the quantity of currently active exception handlers.
If no handler is found, and the exception is non-fatal (such as a warning), and there is a continuation in the exception record (because the throwing opcode was throw), invoke the continuation (resume execution). Whether to resume or die when an exception isn't handled is determined by the severity of the exception.
typedef enum {
EXCEPT_normal = 0,
EXCEPT_warning = 1,
EXCEPT_error = 2,
EXCEPT_severe = 3,
EXCEPT_fatal = 4,
EXCEPT_doomed = 5,
EXCEPT_exit = 6
} exception_severity;
typedef enum {
EXCEPTION_BAD_BUFFER_SIZE,
EXCEPTION_MISSING_ENCODING_NAME,
EXCEPTION_INVALID_STRING_REPRESENTATION,
EXCEPTION_ICU_ERROR,
EXCEPTION_UNIMPLEMENTED,
EXCEPTION_NULL_REG_ACCESS,
EXCEPTION_NO_REG_FRAMES,
EXCEPTION_SUBSTR_OUT_OF_STRING,
EXCEPTION_ORD_OUT_OF_STRING,
...
} exception_type_enum;
The payload more specifically identifies the detailed cause/nature of
the exception. Each exception class will have its own specific payload type(s). See the table of standard exception classes for examples.
Exceptions have been incorporated into built-in opcodes in a limited way. For the most part, they're used when the return value is either impractical to
check (perhaps because we don't want to add that many error checks in line), or where the output type is unable to represent an error state (e.g. the output I register of the ord opcode).
Other opcodes respond to an errorson setting to decide whether to throw an exception or return an error value.
{{ TODO: "errorson" as specified is dynamically rather than lexically
scoped; is this good? Probably not good. Let's revisit it when we get the basic exceptions functionality implemented. }}
{{ NOTE: There are a couple of different factors here. One is the ability to globally define the severity of certain exceptions or categories of exceptions without needing to define a handler for each one. (e.g. Perl 6 may have pragmas to set how severe type-checking errors are. A simple "incompatible type" error may be fatal under one pragma, a resumable warning under another pragma, and completely silent under a third pragma.) Another is the ability to "defang" opcodes so they return error codes instead of throwing exceptions. We might provide a very simple interface to catch an exception and capture its payload without the full complexity of manually defining exception handlers (though it would still be implemented as an exception handler internally)
I was going to embark on a rant about this, but then I read the PDD, and i realized the entire exception subsystem is a farce.
That which is documented is inadequate and poorly thought out. And that which is implemented doesn't do even remotely what is documented.
The pdd makes the assumption that exception filtering will be done based on 'type', but provides no mechanism for extending the 'types'. The logical (and widely popular) alternative is to filter based on subclass. The pdd's answer to that is that you can throw anything, if you just stuff it in the payload. So naturally, the parameters to the exception handler objects are the...
...exception and it's *message*.
The throw/rethrow ops differ in that rethrow marks the exception unhandled. IMO, rethrow should be transparent - particularly, the exception backtrace should still point at the original location where the exception occured. The pdd makes nothing of this, and naturally parrot gets it wrong.
There are too many categories of severity, too many attributes (backtrace versus resume versus thrower; severity versus exit code versus type versus class).
My signature improvements Hague Grant is pretty much wrapped up. I wrote a couple of posts already about the new signature binder and also about signature introspection. In this post I want to talk about some of the other cool stuff I've been working on as part of it.
First, a little background. When you make a call in Perl 6, the arguments are packaged up into a data structure called a capture. A capture contains an arrayish part (for positional parameters) and a hashish part (for smok^Wnamed parameters). The thing you're calling has a signature, which essentially describes where we want the data from a capture to end up. The signature binder is the chunk of code that takes a capture and a signature as inputs, and maps things in the capture to - most of the time, anyway - variables in the lexpad, according to the names given in the signature.
Where things get interesting is that if you take a parameter and coerce it to a Capture, then you can bind that too against a signature. And it so turns out that Perl 6 allows you to write a signature within another signature just for this very purpose. Let's take a look.
multi quicksort([$pivot, *@values]) {
my @before = @values.grep({ $^n < $pivot });
my @after = @values.grep({ $^n >= $pivot });
(quicksort(@before), $pivot, quicksort(@after))
}
multi quicksort( [] ) { () }
Here, instead of writing an array in the signature, we use [...] to specify we want a sub-signature. The binder takes the incoming array and coerces it into a Capture, which essentially flattens it out. We then bind the sub-signature against it, which puts the first item in the incoming array into $pivot and the rest into @values. We then just partition the values and recurse.
The second multi candidate has a nested empty signature, which binds only if the capture is empty. Thus when we have an empty list, we end up there, since the first candidate requires at least one item to bind to $pivot. Multi-dispatch is smart enough to know about sub-signatures and treat them like constraints, which means that you can now use multi-dispatch to distinguish between the deeper structure of your incoming parameters. So, to try it out...
my @unsorted = 1, 9, 28, 3, -9, 10;
my @sorted = quicksort(@unsorted);
say @sorted.perl; # [-9, 1, 3, 9, 10, 28]
It's not just for lists either. An incoming hash can be unpacked as if it had named parameters; for that write the nested signature in (...) rather than [...] (we could have use (...) above too, but [...] implies we expect to be passed a Positional). For any other object, we coerce to a capture by looking at all of the public attributes (things declared has $.foo) up the class hierarchy and making those available as named parameters. Here's an example.
class TreeNode { has $.left; has $.right; }
sub unpack(TreeNode $node (:$left, :$right)) {
say "Node has L: $left, R: $right";
}
unpack(TreeNode.new(left => 42, right => 99));
This outputs:
Node has L: 42, R: 99
You can probably imagine that a multi and some constraints on the branches gives you some interesting possibilities in writing tree transversals. Also fun is that you can also unpack return values. When you write things like:
my ($a, $b) = foo();
Then you get list assignment. No surprises there. What maybe will surprise you a bit is that Perl 6 actually parses a signature after the my, not just a list of variables. There's a few reasons for that, not least that you can put different type constraints on the variables too. I've referred to signature binding a lot, and it turns out that if instead of writing the assignment operator you write the binding operator, you get signature binding semantics. Which means...you can do unpacks on return values too. So assuming the same TreeNode class:
sub foo() {
return TreeNode.new(left => 'lol', right => 'rofl');
}
my ($node (:$left, :$right)) := foo();
say "Node has L: $left, R: $right";
This, as you might have guessed, outputs:
Node has L: lol, R: rofl
Note that if you didn't need the $node, you could just omit it (put keep the things that follow nested in another level of parentheses). This works with some built-in classes too, by the way.
It works for some built-in types with accessors too:
sub frac() { return 2/3; }
my ((:$numerator, :$denominator)) := frac();
say "$numerator, $denominator";
Have fun, be creative, submit bugs. :-)
($P0, $I0) = foo(1, 2.0, $S0)
.const 'Sub' foo = 'foo'
.begin_call
.set_arg 1
.set_arg 2.0
.set_arg $S0
.call foo
.get_result $P0
.get_result $I0
.end_call
$P97 = find_name "foo"
$P98 = new ['String']
$P98 = "0x0010,0x0013,0x0001"
set_args $P98, 1, 2.0, $S0
$P99 = new ['FixedIntegerArray']
$P99[0] = 0x02
$P99[1] = 0x00
get_results $P99, $P0, $I0
invokecc $P97
The Perl 6 design team met by phone on 10 February 2010. Larry, Patrick, Will, Jerry, and chromatic attended.
Will:
Jerry:
Larry:
**() special form to prefix:<||> by analogy to prefix:<|>, and relationship of ** to *.|| for slice interpolationPatrick:
c:
Jerry:
Will:
Jerry:
Will:
Jerry:
Patrick:
Will:
Patrick:
Will:
Patrick:
Will:
Patrick:
The Perl 6 design team met by phone on 03 February 2010. Larry, Patrick, and chromatic attended.
Larry:
Nil, but with special EMPTY failureE operator for efficient list end detection; gathering feedback@ no longer implies flattening@@ sigil; have fixed up most of the bloody stumps** slice marker on parameters[;] reduction since it wouldn't work (because of return parcel embedding)**() interpolator insteadget, getobj, batch, and batchobj get and getobj must be atomic under multi-threading so message queues work (but maybe that's backwards, and push should be atomic)Seq objectsflat and slice are done by binding to *@ or **@ flat operator detangles flattening semantics from normal unmarked list semantics*@@ parameters changed to **@ @@ to something else appropriatePatrick:
c:
Tomorrow's regularly scheduled Rakudo release is the first one since the long-running "ng" branch became master. It represents both a huge step forward and at the same time a fairly major regression. Internally, the changes are enormous; some of the biggest include:
Every one of these - and some others I didn't mention - are important for getting us towards the Rakudo * release. The downside is that since we've essentially taken Rakudo apart and put it back together again - albeit on far, far better foundations - we're still some way from getting all of the language constructs, built-in types and functions back in place that we had before. It's often not just a case of copy-paste; many of the list related things now have to be written with laziness in mind, for example.
So anyway, if you download tomorrow's release and your code doesn't compile or run, this post should explain - at least at a higher level - why. After a slower December and January, Rakudo development has now once again picked up an incredible pace, and the last couple of week's efforts by many Rakudo hackers have made this release far better than I had feared it was going to be. If we can keep this up, the March release should be a very exciting one.
|
When you need perl, think perl.org
|
|