Immutable, persistent data structures give a program certain superpowers that it's very hard to have in any other way: they allow the program to "time travel" (view previous application state); they allow let the program share data across threads or asynchronously save it to disk without needing locks; they enable a much more purely functional style of programming – which results in code that many software developers find much easier to reason about. Because of these benefits, many languages with strong support for functional programming (Clojure, Elm, Haskell, etc) offer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
⎕IO←0 | |
intcode←{ | |
⍺←0 ⋄ i←⍺ ⋄ s←⍵ ⋄ instr←'0'(,⍣{4<≢⍺})⍕⍺⌷⍵ ⋄ opcode←⍎¯2↑instr ⋄ p_modes←⍎¨⌽3⍴instr | |
p←{mode←p_modes[⍵-1] | |
mode=0:s[i+⍵] | |
mode=1:i+⍵ | |
'ERR: Unknown parameter mode',mode} | |
i≥≢s:'ERR: no HALT opcode' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
intcode←{ | |
⍺←0 0 ⋄ (i rb)←⍺ ⋄ val←⊃⍵[0] ⋄ addr←⊃⍵[1] | |
get←{ ⍵<0: ⎕←'ERR: invalid negative index' | |
(addr⍳⍵)<(≢addr):(addr⍳⍵)⌷val | |
addr,←⍵ ⋄ val,←0 ⋄ ∇ ⍵ } | |
set←{ (addr⍳⍺)<(≢addr):((addr⍳⍺)⌷val)←⍵ | |
addr,←⍺ ⋄ val,←⍵ } | |
instr←(10 10 10 10 10)⊤(get i) ⋄ opcode←(10 10)⊥¯2↑instr ⋄ p_modes←⌽3↑instr | |
p←{mode←p_modes[⍵-1] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in←↑⊃⎕nget '10.input' 1 ⋄ p←'#'=in | |
can_see←{⍺≡⍵:0 | |
0=+/¯1↓{p[⍵[0];⍵[1]]}¨⍺ els_btwn ⍵ } | |
els_btwn←{ ⍺≡⍵:⍬ | |
n←⍺+(⍺ slope_btwn ⍵) | |
(⊂n),(n ∇ ⍵) } | |
slope_btwn←{{⍵÷(∨/⍵)}-⍺-⍵} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub postfix:<‽>($a) { $ = $a}; | |
class A { method n { Nil }; | |
method fine { self } | |
method non-nil { 42} | |
}; | |
say A.new.fine‽ | |
.non-nil; | |
say A.new.n‽ | |
.non-nil; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $result = do try { | |
# some code that may throw X::This | |
… | |
# some code that may throw X::NotSpecified (default) | |
… | |
# some code that may throw X::Something | |
… | |
# some code that may throw X::This or X::That | |
… |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
constant gcd = &[gcd]; | |
constant collect = *.bounds; | |
constant extrema = &minmax; | |
my &find_gcd = gcd ∘ collect ∘ extrema; |
This list was generated using the Citation Indices module by Richard Hainsworth (finanalyst) and lists the 30 most-often-depended-modules in the Raku ecosystem as of 2021-11-24 (including both direct and transitive dependencies). For more info, see the ModuleCitation module; thanks, Richard!
Module Name | Recursive Citation Index | Module Description |
---|---|---|
JSON::Fast | 42.37 | |
MIME::Base64 | 31.45 | Encoding and decoding Base64 ASCII strings |
File::Directory::Tree | 30.89 | Port of File::Path::Tiny - create and delete directory trees |
URI | 28.44 | A URI implementation using Raku grammars to implement RFC 3986 BNF |
OpenSSL | 24.11 | OpenSSL bindings |
File::Temp | 23.35 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
role Subgrammar[::G :$grammar, :$actions] { | |
multi method slag(G) { | |
my $old-actions = self.actions; | |
self.set_actions: $actions; | |
my @wrapped = G.^methods(:local).map: -> &m { | |
with self.^methods.first({.name eq &m.name}) { | |
next if $_ === &m or .name eq 'BUILDALL'; | |
.wrap: method (|c) { m self, |c } } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Grammar::Handles | |
my module Grammar::Handles::Helpers { | |
class X::Grammar::Can'tHandle is Exception { | |
has $.type is required; | |
multi method CALL-ME(|c) { die self.new(|c)} | |
method message { q:to/§err/.trim.indent(2); | |
The `handles` grammar trait expects a Grammar, the name | |
of a Grammar, a Pair with a Grammar value, or a list of | |
any of those types. But `handles` was called with: |