Skip to content

Instantly share code, notes, and snippets.

Q:PIR{
loadlib $P0, 'rational'
};
class Rat {
has $.v is rw; # Should be $!v;
submethod BUILD () {
$!v = Q:PIR{
Grammar and some extra language for 01_base.pod... Questions: 1) Is the new language about where instance data may be stored accurate? Could a struct SMOP__Object * be used merely as a key into a separate data structure, without any content after .RI? 2) What's a weak reference used for? It explains what, but not why.
@skids
skids / multikey
Created February 21, 2012 18:05
Meandering around Perl6 Capture multi-key semantics
Notes from my drive-time meditations...
Two semantics for Associative with multiple identical keys.
( :a<foo>, :a<bar> )
#1 #2
a => bar or a => ( foo, bar )
What Perl5 users expect In regexp/Match for multiple <name>
Used to amend defaults In Hash.invert
@skids
skids / EmittiveGrammar
Created May 18, 2012 00:27
Random thought on emitting from Perl6 grammars
# So for building ASTs we already have something like:
class Actions {
method foo { make $0 };
#etc
}
# The complement would look something like this, using the same convention
# of matching names that appear as Grammar rules.
#
@skids
skids / CStructDate.pm
Created May 22, 2012 21:29
Current working rakudo recipe for making a CStruct member behave like a given type.
# Current working rakudo recipe for making a CStruct member behave like a
# given type. (As of rakudo/rakudo 22c12b0cffa05d999fbf84b83eeb551922860ed5)
class A is repr('CStruct') {
# For a rw attribute, must use a private attribute. Using $.x gives error:
# "Cannot create rw-accessors for natively typed attribute '$!x'"
# (Also if you use $.x and then try to make a method x to write your
# own accessors you get an infinite loop at runtime.
@skids
skids / rolecompiled.txt
Created October 13, 2012 00:31
rakudo Parametric role breakage when precompiling
Subject: Curried role compose fails in precompiled modules
When a parametric role is curried it works fine straight from source,
but when the role has been precompiled into a module, a parrot
error is thrown:
cat mod2.pm6
role Foo [ ] { }; role Bar does Foo[] { }
$ PERL6LIB="." perl6 -e 'use mod2; class C does Bar { };'
$ PERL6LIB="." perl6 --target=pir --output=mod2.pir mod2.pm6
@skids
skids / diamond
Created November 5, 2012 01:47
Perl6 diamond inheritance interim workaround
This trick can be used to temporarily work around some NYI areas of Perl6 Parametric Roles for a specific use case.
A known shortfall in the current Parametric Role implementation is NYI diamond composure:
role A { method foo ($x) { "HIYA".say } }
role B does A { }
role C does A { }
role D does B does C { }
class E does D { }
my E $e .= new();
@skids
skids / fix_rshift-nqp_bigint_ops
Created November 30, 2012 21:31
A fix for tomath repr right shifts
/* Cargo-culted fix for right shift issues in nqp_bigint.ops. */
/* This could be done better in a way that doesn't dirty so much write cache
for huge shifts/values, since the results are calculatable without actually
performing additions across the whole number. */
inline op nqp_bigint_shr(out PMC, invar PMC, in INT, invar PMC) :base_core {
mp_int b;
mp_int *a = get_bigint(interp, $2);
@skids
skids / nqp_bigint_ops_fix_bitops
Created December 2, 2012 07:00
A fix for tomath repr bitops
static void grow_and_negate(mp_int *a, int size, mp_int *b) {
int i;
/* Always add an extra digit so we can tell positive values
* with a one in the highest bit apart from negative values
* with a zero in the highest bit.
*/
int actual_size = MAX(size, USED(a)) + 1;
SIGN(b) = MP_ZPOS;
mp_grow(b, actual_size);
USED(b) = actual_size;
@skids
skids / a programming challenge
Last active December 11, 2015 13:48
1d packing mini-challenge
You have an unlimited supply of black and red checkers.
You stack checkers next to each other into two piles on a level table.
In the first pile, you stack N red checkers, then M black checkers,
then P red checkers, and then (possibly) repeat M black/P red checkers for
a total of X times.
In the second pile you do the same, with (possibly) different values