Skip to content

Instantly share code, notes, and snippets.

View alabamenhu's full-sized avatar

L'Alabameñu alabamenhu

  • Tennessee
View GitHub Profile
@alabamenhu
alabamenhu / PREVIEW (do not use yet).raku
Created September 9, 2020 15:30
Translation Template
# EXCEPTIONS LOCALIZATION FOR ----
#
# Note that this file has been automatically generated.
# Do NOT allow a code editor to reformat, as it will mess up (NYI) comparison
# and update scripts.
#
# 1. Change the ?? to your language code
unit module Intl::X::??;
# 2. Rename this template file to match the language code
# 3. Place in the lib/Intl/X/ directory.
@alabamenhu
alabamenhu / X.pm6
Created September 4, 2020 13:14
Localization template
my %translations = Map.new:
=begin pod
=class X::Cannot::Lazy
=updated 2020-05-01
=begin code
$.what
?? "Cannot $.action a lazy list onto a $.what"
!! "Cannot $.action a lazy list";
=end code
@alabamenhu
alabamenhu / CustomCoercer.raku
Last active August 9, 2020 22:58
How to (mostly safely) add a custom coercer to another class
class Percent {
has $.value;
method new (Numeric $value) { self.bless: :value($value * 100) }
# Coercers from Percent
method Str { $.value ~ "%" }
method Numeric { $.value / 100 } 
@alabamenhu
alabamenhu / world-clock.raku
Last active August 8, 2020 19:58
World Clock
use DateTime::Timezones;
sub MAIN (**@timezones) {
react whenever Supply.interval(1) {
my $time = DateTime.new: now;
say " {.hh-mm-ss} {.tz-abbr}\t{.olson-id}"
for @timezones.map({$time.in-timezone: $_});
print "\x001b[F" xx @timezones;
}
}
@alabamenhu
alabamenhu / Advent20.md
Created August 6, 2020 01:03
20th Anniversary Advent Day - RFC 233

RFC 223: Superpositions

Damian Conway is one of those names in the Perl and Raku world that almost doesn't need mentioning. He is one of the most prolific contributors to CPAN and was foundational in the design of Raku (then Perl 6). One of his more interesting proposals came in RFC223 on Superpositions, which suggested making his Perl Quantum::Superposition's features available in the core of the language.

What is a Superposition?¹

In the quantum world, there are measurable things that can exist in multiple states — simultaneously — until the point in time in which we measure them. For computer scientists, perhaps the most salient application of this is in qubits which, as a core element of quantum computing, threaten to destroy encryption as we know it, if quantum supremacy is borne out.

At the end of the day, though, for us it means being able to treat multiple values as if they were a single value so long as never actually need there to only be one, at which point we get a single state f

@alabamenhu
alabamenhu / Grammar proposal.md
Last active November 21, 2021 15:32
Grammar proposal

This is designed to be a working proposal. Comments/corrections/suggestions are welcome, as the first draft was written fairly hastily. I'm working on doing a rough implementation to play around with, beginning with the Binex proposal, which can be found here. It is not currently a full implementation of this proposal, but progressing rapidly.

Background

Grammars in Raku are awesome, and allow for some truly amazing text parsing.
Unfortunately, they are less than ideal for binary files, and there is no way to have them support matching objects, both of which would be very useful (image being able to pattern match on an AST!) This requires writing complex and/or error prone workaround code.

Goal

@alabamenhu
alabamenhu / Strongly Typed Raku (pod6).txt
Last active January 9, 2022 04:29
Strongly Typed Raku (WIP)
=begin pod
Raku is a gradual typed language, allowing you to completely ignore typing for quick mock ups,
or enforce very strict typing to ensure reliability in critical programs. This is a guide for
certain issues that can come up when writing strongly typed Raku code.
=head1 Basic typing
@alabamenhu
alabamenhu / Perl files
Created April 29, 2019 01:58
Using selective import/export for modules
============ Inside a module file ============
unit module Sustenance;
sub eat-apples is export(:apples, :eat) { … }
sub eat-oranges is export(:oranges, :eat) { … }
sub eat-bananas is export(:bananas, :eat) { … }
sub drink-water is export(:water, :drink) { … }
sub drink-coke is export(:coke, :drink) { … }
=========== Inside your main script ==========