Some horribly hacky Raku code that pretends to be a barely functional logic language
use lib 'lib';
use Logos;
enum < tom sally bob mark floppy book >;
fact :person(sally);
fact :person(mark);
Some horribly hacky Raku code that pretends to be a barely functional logic language
use lib 'lib';
use Logos;
enum < tom sally bob mark floppy book >;
fact :person(sally);
fact :person(mark);
use v5.36; | |
use warnings FATAL => 'all'; | |
use Path::Tiny qw< path >; | |
my $v = qr{ ( [A-Za-z][.:] | [0-9][:] | [^ A-Za-z0-9()] )+ }nx; | |
my $p = qr{ \( ($v \s+ $v)+ \s+ $v \) }nx; | |
my $iter = path('code/aoc')->iterator({ recurse => 1 }); | |
my %seen; |
nixlib =. '/usr/local/lib/libraylib.so' | |
winlib =. jpath '~/raylib/lib/raylib.dll' | |
raylib =: IFUNIX {:: winlib;nixlib | |
Uh =: 0 {:: ] f. NB. Unbox head | |
NB. Window-related functions | |
InitWindow =: (raylib,' InitWindow n i i *c') cd ] | |
CloseWindow =: (raylib,' CloseWindow n') cd ] | |
WindowShouldClose =: Uh (raylib,' WindowShouldClose i') cd ] |
A "partition" adverb in J (similar to APL's ⊆)
P =: {{ (1, 2 </\ x) u;.1&((0 < x)&#) y }}
Partition on delimiter (à la (≠⊆⊢)
)
',' (~: <P ]) 'comma,separated,values'
┌─────┬─────────┬──────┐
require 'media/imagekit/color_space' | |
require 'graphics/png' | |
require 'graphics/pplatimg' | |
coinsert 'pplatimg' | |
ParseDiff =: {{ | |
'p d' =. (}: ; {:) ];._2 y | |
t =. ". '/%' rplc~ d | |
c =. (+./@(' ' ~: ]) {{ (1, 2 </\ x) <;.1&(x&#) y }}"1 ]) p | |
a =. {. ($ #: I.@,) > 'X' +./@e.~L:0 c |
#!/usr/bin/env jconsole | |
NB. No space before these tokens | |
bef =: ;: ') @ @. @: & &. &: &.: " ` ;. !. !: / /. \ ~ }' | |
NB. No space after these tokens | |
aft =: ;: '( @ @. @: & &. &: &.: " ` ;. !. !:' | |
Cont =: {{ +./ ((dltb > x) (-: ;)"1 0 y) }} | |
Fmt =: {{ |
Just an exploration of parsing this days input without regex.
Given the following code
c =. Parse;._2 fread 'input'
echo +/ (* #\) 12 13 14 *./@:>:"1 c
echo +/ */"1 c
if exists('b:current_syntax')|fini|en | |
sy clear|sy case match |sy sync fromstart |if&l:syn==#'k'|setl com=:/ isk=a-z,A-Z,48-57 |en | |
" sy clear|sy case match |sy sync fromstart |if&l:syn==#'k'|en | |
sy match k_e /\i\+\|\S/ | |
sy match k_s /\(`\(\I\i*\>\|:[A-Za-z0-9.:/]*\)\=\)\+/ nextgroup=@k_vw |hi link k_s constant | |
sy match k_w /[\\\/']:\=/ nextgroup=k_w contained |hi link k_w operator | |
sy match k_c1 /.\+/ contained |hi link k_c1 special | |
sy match k_c0 /\\\(\w\+\|\\\|$\)/ nextgroup=k_c1 |hi link k_c0 statement | |
sy match k_c0 /\\[tw]\>\(:\d\+\)\=/ | |
sy match k_e /"/ nextgroup=k_es |hi link k_e error |
Here's a rundown of definitions in my .jprofile.ijs
, which get loaded in all J sessions.
Some of these are so simple they don't need names, but sometimes I just put things in here so I don't forget how to spell them.
Not all the functions are the most efficient, they're just there for playing with data. Often in a script, I will copy a function in, or re-write one that is more specific to the given problem domain.
An implementation of "Rock Scissor Paper" in Raku.
The "robot" will make a weighted random choice based on your previous moves.
use Term::ReadKey;
use Terminal::ANSIColor;
enum Choice « :Rock(1) :Paper(2) :Scissors(3) »;
enum Outcome « :WIN(1) :DRAW(0) :LOSE(-1) »;