Skip to content

Instantly share code, notes, and snippets.

@raydiak
raydiak / gist:46b0727fddfd3c0b659e
Last active August 29, 2015 14:22
restricted weirdness
x@patience:~/data/projects/perl6/panda > rakudo/install/bin/perl6 -e 'my $*RESTRICTED; say EVAL "(:a(1):b(2))"'
a => 1
x@patience:~/data/projects/perl6/panda > rakudo/install/bin/perl6 -e 'say EVAL "(:a(1):b(2))"'
a => 1 b => 2
x@patience:~/data/projects/perl6/panda > rakudo/install/bin/perl6 -e 'my $*RESTRICTED; say do { (:a(1):b(2)) }'
a => 1 b => 2
x@patience:~/data/projects/perl6/panda > rakudo/install/bin/perl6 -e 'my $*FOO; say do { (:a(1):b(2)) }'
a => 1 b => 2
declare_array line
for_input_lines
trim _
split _ line ' '
if line[0] 'declare_array'
print 'my $'
print_var line[1]
say ' = [];'
elsif line[0] 'for_input_lines'
say 'for $*IN.lines -> $_ is copy {'
This file has been truncated, but you can view the full file.
<!DOCTYPE html>
<html lang="en" ng-app="moarProfApp" ng-controller="NavigationController">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>MoarVM Profiler Results</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
<style>
> examples/sum.p6 1e8
lua...
5.00000005e+15
perlint...
5000000050000000
perlnum...
5.00000005e+15
perlnum64...
5.00000005e+15
#!/usr/bin/env perl6
use NativeCall;
class SDL_Window is repr('CStruct') {}
class SDL_Renderer is repr('CStruct') {}
class SDL_Point is repr('CStruct') {
has int32 $.x;
has int32 $.y;
method set($x, $y) {
@raydiak
raydiak / n.p6
Created February 15, 2015 22:25
1/p + 1/q + 1/r = 1/2 where 0 < p <= q <= r
#!/usr/bin/env perl6
my $bound = 100;
my @answers;
Pl: for 3..$bound -> $p {
my $pv = 1 / $p;
Ql: for $p..$bound -> $q {
my $qv = 1 / $q;
@raydiak
raydiak / assuming.p6
Created February 15, 2015 06:10
Whatever support for positional currying
#!/usr/bin/env perl6
sub assuming ($r, |curried) {
if my @holes := (^curried).grep: { curried[$_] ~~ Whatever } {
my $last-hole = @holes[*-1];
my @mixed;
@mixed[$_] := curried[$_] for 0 .. $last-hole;
my @curried := curried[$last-hole ^.. *];
return sub CURRIED (|direct) {
@mixed[@holes[$_]] := direct[$_] for ^@holes;
@raydiak
raydiak / ZMQ.pm6
Created February 13, 2015 08:29
Script-generated P6 0MQ bindings
module ZMQ;
use NativeCall;
sub zmq_version (OpaquePointer, OpaquePointer, OpaquePointer) is native('zmq') {*};
sub zmq_errno () returns int is native('zmq') {*};
sub zmq_strerror (int) returns Str is native('zmq') {*};
sub zmq_ctx_new () returns OpaquePointer is native('zmq') {*};
sub zmq_ctx_term (OpaquePointer) returns int is native('zmq') {*};
sub zmq_ctx_shutdown (OpaquePointer) returns int is native('zmq') {*};
#!/usr/bin/env perl6
use lib $?FILE.IO.parent.child('lib');
use C::Parser::Grammar;
class CFunction {
has $.name;
has $.return = Any;
has @.args = ();
// parse fails
typedef __off64_t __loff_t;
typedef __quad_t *__qaddr_t;
struct _IO_FILE;
typedef struct { __off_t __pos; __mbstate_t __state; } _G_fpos_t;
typedef struct { __off64_t __pos; __mbstate_t __state; } _G_fpos64_t;
struct _IO_jump_t;
struct _IO_FILE;
struct _IO_FILE_plus;
typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);