Skip to content

Instantly share code, notes, and snippets.

@PWBENNETT
PWBENNETT / mathwrangler.pl
Created June 28, 2013 08:12
Work in progress to make something a little more substantial based on the Marpa::R2::Scanless Synopsis
#!/usr/bin/env perl
use 5.010;
use utf8;
use bignum;
use Marpa::R2;
my $grammar = Marpa::R2::Scanless::G->new(
{ bless_package => 'My_Nodes',
5 5
"hello"
(DEFINE A 5)
(DEFINE * 5)
#!/usr/bin/env perl
use 5.018;
use utf8;
local $| = 1;
for my $i (map { chr($_) } 32 .. 127) {
if ($i =~ /\p{Magic::Wow}+/) {
print $i;
@PWBENNETT
PWBENNETT / Gaussian.pm
Created September 30, 2013 12:24
What I'd like to be able to do with Perl5 operator creation. Writing the "operator" pragma is left as an exercise to the reader.
package Gaussian;
use overload '0+' => 'generate';
use operator '+/-' => { code => 'new', assoc => 'left', prio => 1 };
sub new {
my ($class, $n, $sd3) = @_;
bless [ $n, $sd3 / 3 ] => $class;
}
@PWBENNETT
PWBENNETT / cons.js
Created October 3, 2013 12:29
Pure functional cons, car, and cdr in Javascript
function cons(a, b) {
return function (n) {
return n == 1 ? a : b;
}
}
function car(l) {
return l(1);
}
@PWBENNETT
PWBENNETT / cons.pl
Created October 7, 2013 04:37
Just realized how easy it is to implement (practically) opaque conses in Perl -- about as easy as it is in JavaScript or Lisp, with more typing
package cons;
use Exporter qw( import );
our @EXPORT = qw( cons car cdr );
sub cons {
my ($x, $y) = @_;
return sub {
my ($n) = @_;
@PWBENNETT
PWBENNETT / cons.pm
Last active December 24, 2015 21:09
Template
package cons;
# Package for taking two "things", joining them together into a "pair", and accessing each "half" of the pair
use Exporter qw( import );
our @EXPORT = qw( cons car cdr );
sub cons {
# Takes two things and returns a pair
@PWBENNETT
PWBENNETT / traffsim
Last active December 25, 2015 20:38
Quick bluff together of a traffic simulator. Might be useful some day.
#!/usr/bin/env perl
use App::traffsim;
App::traffsim->run();
@PWBENNETT
PWBENNETT / delta.pm
Last active December 26, 2015 00:19
I've been meaning for some time to knock together a nice way of finding the smallest possible delta for any given variable. This one, I hope, should do the trick. Better than just dividing by 15360 and hoping that IEEE 754 as implemented on the target system will "just cope".
package delta;
use 5.012;
use Exporter qw( import );
our @EXPORT = qw( delta );
sub delta ($);