Skip to content

Instantly share code, notes, and snippets.

@masak
masak / find-palindromes.p6
Last active August 29, 2015 14:00
Python and Perl 6 are kinda similar :)
given open('words') -> $f {
LEAVE { $f.close }
for $f.lines -> $line {
next if $line.chars == 1;
if $line.flip eq $line {
say $line
}
}
}
@masak
masak / git-commit-branch
Created April 20, 2014 10:22
git-commit-branch
BRANCH="$1"
shift
git checkout $BRANCH
git commit "$*"
git checkout -
@masak
masak / problem.txt
Created April 17, 2014 19:38
Problem in NQP make-land
$ make && make test
/usr/bin/perl -MExtUtils::Command -e mkpath bin
javac -source 1.7 -cp 3rdparty/asm/asm-4.1.jar:3rdparty/asm/asm-tree-4.1.jar:3rdparty/jline/jline-1.0.jar:3rdparty/jna/jna.jar -g -d bin src/vm/jvm/runtime/org/perl6/nqp/io/*.java src/vm/jvm/runtime/org/perl6/nqp/jast2bc/*.java src/vm/jvm/runtime/org/perl6/nqp/runtime/*.java src/vm/jvm/runtime/org/perl6/nqp/sixmodel/*.java src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/*.java src/vm/jvm/runtime/org/perl6/nqp/tools/*.java
/usr/bin/perl tools/build/gen-jvm-properties.pl . 3rdparty/asm/asm-4.1.jar:3rdparty/asm/asm-tree-4.1.jar:3rdparty/jline/jline-1.0.jar:3rdparty/jna/jna.jar > jvmconfig.properties
/usr/bin/perl tools/build/gen-jvm-properties.pl /home/masak/ours/nqp/install 3rdparty/asm/asm-4.1.jar:3rdparty/asm/asm-tree-4.1.jar:3rdparty/jline/jline-1.0.jar:3rdparty/jna/jna.jar > bin/jvmconfig.properties
jar cf0 nqp-runtime.jar -C bin/ .
sh: 1: jar: not found
make: *** [nqp-runtime.jar] Error 127
@masak
masak / cps-kinda.p6
Created April 14, 2014 06:18
Simulating CPS in Perl 6 - code that can be paused and resumed in the middle
## Test
my $point_1_reached = False;
my $point_2_reached = False;
my $point_3_reached = False;
class Event1 {}
class Event2 {}
class Event3 {}
@masak
masak / indent.p6
Last active August 29, 2015 13:57
Indent handling in Perl 6
constant TABSTOP = 4;
class Suite {
has @.items handles <push at_pos Numeric Bool>;
}
class X::Double::Indent::NotAllowed is Exception { }
class X::Partial::Indent is Exception { }
class X::Initial::Indent is Exception { }
@masak
masak / warnings.txt
Created February 14, 2014 11:13
Uninitializedness warnings in Configure.pl script in Rakudo
$ perl Configure.pl --backends=moar
Use of uninitialized value in concatenation (.) or string at Configure.pl line 247.
Use of uninitialized value in concatenation (.) or string at Configure.pl line 247.
Using /home/masak/ours/rakudo/install/bin/nqp-m (version / MoarVM ).
Use of uninitialized value $nqp_config{"moar::dll"} in sprintf at Configure.pl line 249.
Cleaning up ...
You can now use 'make' to build Rakudo.
After that, 'make test' will run some tests and
'make install' will install Rakudo.
@masak
masak / control-shift.diff
Created January 6, 2014 20:07
like this, diakopter?
diff --git a/t/jvm/01-continuations.t b/t/jvm/01-continuations.t
index 1ec9228..cdb9acb 100644
--- a/t/jvm/01-continuations.t
+++ b/t/jvm/01-continuations.t
@@ -29,7 +29,7 @@ plan(22);
# nqp::continuationcontrol(0, nqp::null(), { $run++ });
# CATCH { $ex := $! }
# }
- # ok( $ex ~~ /'no matching'/, 'shift dies with no reset' );
+ # ok( $ex ~~ /'no matching'/, 'control dies with no reset' );
@masak
masak / post.md
Last active December 31, 2015 09:29
Day 15 - Numbers and ways of writing them

Consider the humble integer.

my $number-of-dwarfs = 7;
say $number-of-dwarfs.WHAT;   # (Int)

Integers are great. (Well, many of them are.) Computers basically run on integers. Also, God made the integers, and everything else is basically cheap Chinese knock-offs of the real thing. If they're so important, we'd expect to have lots of good ways of writing them in any respectable programming language.

Do we have lots of ways of writing integers in Perl 6? We do. (Does that make Perl 6 respectable? No, because it's a necessary but not sufficient condition. Duh.)

One thing we might want to do, for example, is write our numbers in other number bases. The need for this crops up now and then, for example if you're stranded on Binarium where everyone has a total of two fingers:

@masak
masak / post.md
Last active December 30, 2015 17:49
Hashes and pairs

Hashes are nice. They can work as a kind of "poor man's objects" when creating a class seems like just too much work for the occasion.

my $employee = {
    name => 'Fred',
    age => 51,
    skills => <sweeping accounting barking>,
};

Perl (both 5 and 6) takes hashes seriously. So seriously, even that there's a dedicated sigil for them, and by using it you can omit the braces in the above code:

@masak
masak / blog-post.md
Last active December 29, 2015 23:09
The humble type object

For some inscrutable reason, we have defined a Dog class in today's post.

class Dog {
    has $.name;
}

Don't ask me why — maybe we're writing software for a kennel? Maybe we're writing software for dogs? "Teach your dog how to type!" Clever dogs can do up to 10 words a minute, with surprisingly few typos.

Anyway. Having a Dog class gives us the dubious pleasure of being able to create dogs out of thin air and passing them to functions. No surprise there.