Skip to content

Instantly share code, notes, and snippets.

Source:
BEGIN { say 'Before "use OpenGL:from<Parrot>;"' }
use OpenGL:from<Parrot>;
BEGIN { say 'After "use OpenGL:from<Parrot>;"' }
say 'Running regular code'
Instrumented result:
Perl6::Compiler.import('Any', ...);
ChangeLog: * experimental mmap IO layer for slurping files
ChangeLog: * Experimental support for "make install"
ChangeLog: * Experimental freeze/thaw code for some PMC types
ChangeLog: * Experimental struct handling
ChangeLog: * Experimental network socket interface code and opcodes
ChangeLog: Wildly experimental patch to make Parrot compile on FreeBSD. (And
compilers/pirc/src/pircompunit.c:is experimental, and not actually used at this point.
config/gen/makefiles/root.in:# directory for the (experimental) PIR code compiler
Configure.pl:This option is experimental. See F<config/init/defaults.pm> for more.
docs/pdds/pdd19_pir.pod:The C<:instanceof> pragma is an experimental pragma that creates a sub as a
@japhb
japhb / median-of-three-conjecture.p6
Created October 29, 2009 20:32 — forked from jnthn/gist:221659
Working out a conjectured syntax for slicing long lists in a Perl 6 signature
multi quicksort([$head, *@front, $mid, *@back, $tail]) {
my ($pivot, @others) := median-of-three($head, $mid, $tail);
my @rest := |@others, |@front, |@back;
quicksort(@rest.grep(* < $pivot)),
$pivot,
quicksort(@rest.grep(* >= $pivot))
}
multi quicksort([$a, $b]) { $a < $b ?? $a, $b !! $b, $a }
multi quicksort(@a [$a?]) { @a }
#! parrot-nqp
INIT {
pir::load_language('parrot');
pir::load_bytecode('kakapo_full.pbc');
}
class Test::Sanity is UnitTest::Testcase;
INIT { use('UnitTest::All'); }
@japhb
japhb / gist:821144
Created February 10, 2011 19:17
Proof of concept Dist::Zilla::Plugin::ScpUpload
package Dist::Zilla::Plugin::ScpUpload;
# ABSTRACT: Release a dist by uploading it with scp
use Moose;
use Moose::Autobox;
with 'Dist::Zilla::Role::Releaser';
use IO::Handle;
use IPC::Open3;
@japhb
japhb / gist:1243461
Created September 26, 2011 21:29
MAIN $?USAGE generation (WIP)
Usage:
./test-usage
./test-usage name
./test-usage age rank [serial-number]
./test-usage [--eyes=<Any>] [--hair=<Any>] [--toes=<Int>]
./test-usage --toes=<Int> [--smug] [--e|--eyes=<Color>] [--h|--ha|--hai|--hair=<Color>] age rank ignored [serial-number] [pos ...] [names ...]
@japhb
japhb / gist:1305223
Created October 21, 2011 23:06
Use cases for email handling in Perl
(The following is a brainstorm of things people might want to do with email, in "How do I ...?" format. For cases where the best answer requires Moose or other heavy modules, a second answer with fewer/lighter dependencies would be most appreciated.)
"How do I / What's the best way to / What do you use to ..."
* verify a purported email address is sane?
* parse an email address into smallest parts?
* canonify an email address?
* parse/canonify a date header?
* send a raw email (already stringified and encoded), simply and safely?
* send a (possibly templated) simple text email?
@japhb
japhb / gist:1321836
Created October 28, 2011 07:58
Three variants of RANGEPOS() from Rakudo's src/core/Str.pm
# Three versions of the sub: the original, a native-types and nqp-heavy version that
# should run faster, and a native-types but nqp-light version that is easier to read.
# Anyone have more improvements to either of the latter two?
# ORIGINAL
my sub RANGEPOS($str) {
my $pos = $str.chars;
while $pos > 0 {
$pos--;
my str $ch = nqp::substr(nqp::unbox_s($str), nqp::unbox_i($pos), 1);
@japhb
japhb / gist:1327012
Created October 31, 2011 06:29
Baseline test of Str.Numeric() in nom
# Nowhere to go but up ... :-)
# Δt is the time actually spent in the tight .Numeric loop;
# most of the remainder is spent generating the test strings.
# The first three rows of output indicate successful parses;
# the Failure() row indicates cases that don't parse correctly.
$ time ./perl6 ./test-numeric
"Int()" => 7438
"Num()" => 70389
@japhb
japhb / gist:1361357
Created November 13, 2011 00:28
Current snapshot of Str.Numeric() rewrite stress test
# 'old' is current Rakudo nom implementation of Str.Numeric()
# 'new' is WIP rewrite
# Time to complete tight loop of .Numeric() calls
PERF TEST Δt-old = 7.82440400123596
PERF TEST Δt-new = 10.397479057312
# Comparison of conversion quality; ideal is diagonal matrix.