Skip to content

Instantly share code, notes, and snippets.

View jnthn's full-sized avatar

Jonathan Worthington jnthn

View GitHub Profile
module Events;
use JSON::Tiny;
package EXPORT::DEFAULT { }
my @events = @(from-json(slurp("events.json")));
for @events -> (:$name, :@values) {
my $type := Metamodel::ClassHOW.new_type(:$name);
for @values -> $attr_name {
$type.HOW.add_attribute($type, Attribute.new(
module Describe;
sub describe(::T) is export {
join "\n", gather {
take "Type {T.^name}";
take " Attributes:";
for T.^attributes(:local) -> $attr {
take " $attr.name() ({
$attr.has_accessor ?? 'public' !! 'private'
})";
for 1..1000 {
(0 but Bool::True);
1;
}
diff --git a/src/Perl6/Actions.pm b/src/Perl6/Actions.pm
index fd4b9cd..b460a75 100644
--- a/src/Perl6/Actions.pm
+++ b/src/Perl6/Actions.pm
@@ -1158,9 +1158,9 @@ class Perl6::Actions is HLL::Actions {
# Expect variable to have been declared somewhere.
# Locate descriptor and thus type.
+ $past.scope('lexical_6model');
try {
> my Rat %h{Int};
().hash
> %h<foo> = 1.5
Nominal type check failed for parameter '$key'; expected Int but got Str instead
> %h{1} = 1.5; %h{2} = 2.5; say %h{1}; say %h{2};
1.5
2.5
> .WHAT.say for %h.keys
Int()
Int()
@jnthn
jnthn / objhash.pl
Created February 14, 2012 13:31 — forked from moritz/objhash.pl
First experiments with
class ObjHash {
has %!keys handles (keys => 'values');
has %!values handles <values elems>;
method at_key(Mu $key) is rw {
my $lkey = $key.WHICH;
%!values.exists($lkey)
?? %!values{$lkey}
!! pir::setattribute__0PPsP(my $v, Scalar, '$!whence',
-> {
%!keys{$lkey} := $key;
use MONKEY_TYPING;
augment class Code {
method outer() {
pir::perl6_code_object_from_parrot_sub__PP($!do.get_outer())
}
}
sub bar() {
my $foo := {
my $foo := {
my $x := 1; $x = 2;
}
my $bar := { $foo() }
$bar();
Here's the doc, in text form, before parsing:
<test><element1 attrib1="hello" attrib2="world"/><element2 attrib1="goodbye" attrib2="universe">with content</element2><element3 what="is it"><foo/></element3></test>
Setting attrib1 to hello
Setting attrib2 to world
Now, here's the doc, after being parsed into an object.
<?xml version="1.0"?><test><element1 attrib1="hello" attrib2="world"/><element2>with content</element2><element3><foo/></element3></test>
Now, what happened to the attributes for the element with contents?
diff --git a/src/PAST/Regex.pir b/src/PAST/Regex.pir
index a5ae908..3434834 100644
--- a/src/PAST/Regex.pir
+++ b/src/PAST/Regex.pir
@@ -251,7 +251,7 @@ at this node.
charlist_negate:
if subtype == 'zerowidth' goto charlist_negate_0
- unless tail goto charlist_negate_0
+ if tail goto charlist_negate_0