Skip to content

Instantly share code, notes, and snippets.

0racle

Block or report user

Report or block 0racle

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Nested.md

I was playing around with nesting data in hashes, and came up with... something.
Some kinda tree structure with JSON-Path like access.
Not sure what this might be useful for.

Perl 5 and 5 implementations below...

Perl 6

use Data::Dump;
@0racle
0racle / Bla.pm6
Created Oct 26, 2018 — forked from FCO/Bla.pm6
Exportation Exploration
View Bla.pm6
use Exportable;
sub bla is exportable { "bla" }
sub ble is exportable { "ble" }
sub bli is exportable { "bli" }
sub blo is exportable { "blo" }
sub blu is exportable { "blu" }
View function-compostion.md

Given the example of a count-words function, I could compose it like so

my &f = *.elems  *.words;
say f 'this is a test'; # OUTPUT: 4

or like this...

my &f =      *.elems;
   &f = &f  *.words;
@0racle
0racle / slang.p6
Last active Jul 4, 2018
Perl 6 Slang
View slang.p6
# I could export this role from a module,
# but here I'm just running it at BEGIN phase
BEGIN {
$*LANG.define_slang: 'MAIN',
$*LANG.slang_grammar('MAIN').^mixin:
role :: {
token routine_declarator:sym<sub> {
'fn' <routine_def('sub')>
}
@0racle
0racle / pies.md
Last active Apr 9, 2018
Possible Number of Pies
View pies.md

/r/dailyprogrammer - [2018-03-28] Challenge #355 [Intermediate] - Link

This is not my solution... Just a modification I made of /u/ruincreep's solution while playing around.

my %recipes =
  'Pumpkin pie' => (:1Pumpkin, :3Eggs, :4Milk, :3Sugar).Bag,
  'Apple pie'   => (:1Apple,   :4Eggs, :3Milk, :2Sugar).Bag;

sub solve-pies($items) {
@0racle
0racle / smfe.md
Last active Mar 29, 2018
Sub-Module Function Exports
View smfe.md

Sub-Modules

  • lib/Foo/Bar.pm6
unit module Foo::Bar;

sub bar(|) is export { 'bar' }
  • lib/Foo/Baz.pm6
@0racle
0racle / Permutations
Last active Mar 13, 2018
Permutation Iterator
View Permutations
#!/usr/bin/env perl6 #`[ This is a quick example implementation of a permutation iterator that uses a factorial calculation to quickly return `.elems` on a permutation, and can efficiently skip elements of enormous sequences. This is just an example to showcase the special Iterator methods... Not be a fast permutation generator. I found this `nth-perm` function online and converted it
@0racle
0racle / rots.p6
Created Feb 25, 2018
Gather Take Rots
View rots.p6
sub rots($list is copy) {
gather for ^$list {
$list[*] .= rotate;
take $list;
}
}
my @l = ^3;
my $r = rots(@l); say $r; # ([1 2 0] [2 0 1] [0 1 2])
my @r = rots(@l); say @r; # [[0 1 2] [0 1 2] [0 1 2]]
@0racle
0racle / Readline.md
Last active Nov 9, 2017
Readline / NativeCall encoding error
View Readline.md

Readline / NativeCall encoding error

Issue occurs the first time I type any expression.

# perl6
To exit type 'exit' or '^D'
> []
Internal error: unhandled encoding
  in method CALL-ME at ... (NativeCall) line 587
View hanoi.p6
sub hanoi(\n, \a = 1, \b = 2, \c = 3) {
return unless n;
hanoi n - 1, a, c, b;
#say "Move disk {n} from peg {a} to peg {c}";
hanoi n - 1, c, b, a;
}
hanoi(20);
say now - INIT now
You can’t perform that action at this time.