Skip to content

Instantly share code, notes, and snippets.

View lokedhs's full-sized avatar

Elias Mårtenson lokedhs

View GitHub Profile
∇ d iterateValues content {
c ← content
i ← 0
while((i < 12) ∧ 1<≢c) {
col ← c[;i]
b ← ⍞d (2÷⍨≢col) ≤ +/col
c ← c[(col=b)/⍳≢col;]
i ← i+1
}
2⊥,c
∇ solvePart1 {
⍝ Construct a 2-column array with the first column being the command
⍝ and the second being the distance.
list ← ⊃ {(d n) ← ⍵ ⊂⍨ ⍵≠↑" " ◊ d (⍎n)}¨ io:read "/home/elias/prog/advent-of-code2021/part02.txt"
⍝ Convert each direction instruction into a vector (up, down or right)
directions ← { ⊃ ((0 1) (¯1 0) (1 0))[(⊂¨ "forward" "up" "down") ⍳ ⊂⍵] }¨ list[;0]
⍝ Multiply each direction with the distance and sum the results
⍝ and finally multiply the individual values
$ ./waf configure
reinitialized logger
subdirectories dir = ['wscript']
extensions subdirs = []
Running init() - this constructs the matrix of legal waf operation names
Setting top to : /home/elias/src/clasp
Setting out to : /home/elias/src/clasp/build
cfg.options.enable_mpi = None
configure()
wscript.config option LLVM_CONFIG_BINARY = /home/elias/src/llvm-project/dist/bin/llvm-config
[ 35/196] Compiling src/clbind/class_registry.cc
In file included from /home/elias/src/clasp/src/llvmo/builtins.cc:29:
In file included from ../../include/clasp/core/core.h:555:
../../include/clasp/core/mpPackage.fwd.h:58:14: error: no template named 'shared_ptr' in namespace 'std'
const std::shared_ptr<array_slock_t> shared_locks_array_ptr; // 0 - unregistred, 1 registred & free, 2... - busy
~~~~~^
../../include/clasp/core/mpPackage.fwd.h:107:10: error: no template named 'shared_ptr' in namespace 'std'
std::shared_ptr<array_slock_t> array_slock_ptr;
~~~~~^
../../include/clasp/core/mpPackage.fwd.h:108:34: error: no template named 'shared_ptr' in namespace 'std'
use("standard-lib.kap")
namespace("mastodon")
∇ urlEscape (s) {
s
}
∇ mkParams (p) {
↑,/¯1↓,((⊂"="),(⊂"&"),urlEscape¨ p)[;2 0 3 1]
Monadic single argument ∇ foo x {
Dyadic single argument ∇ x foo y {
Destructuring ∇ (x0;y0) foo (x1;y1) {
Monadic op, monadic arg ∇ (fn foo) x {
Monadic op, dyadic arg ∇ x (fn foo) y {
Dyadic op, monadic arg ∇ (f0 foo f1) x {
Dyadic op, dyadic arg ∇ x (f0 foo f1) y {
Destructuring ∇ (x0;x1) (f0 foo f1) (y0;y1) {
Fn parens optional:
Monadic single arg: ∇ (foo) x {
a←⌽ 1 2 3 4 5 6 7 8 9 "foo" "bar" "test" "abc" "longerstringhereijwoqdjwioqjdowiqdoiwqjddjdwiojdd"
b←a,⌽ 1 2 3 4 5 6 7 8 9 "foo" "bar" "test" "abc" "longerstringhereijwoqdjwioqjdowiqdoiwqjddjdwiojdd"
c←a,⌽ 1 2 3 4 5 6 7 8 9 "foo" "bar" "test" "abc" "longerstringhereijwoqdjwioqjdowiqdoiwqjddjdwiojdd"
c←a,⌽ 1 2 3 4 5 6 7 8 9 "foo" "bar" "test" "abc" "longerstringhereijwoqdjwioqjdowiqdoiwqjddjdwiojdd"
c←a,⌽ 1 2 3 4 5 6 7 8 9 "foo" "bar" "test" "abc" "longerstringhereijwoqdjwioqjdowiqdoiwqjddjdwiojdd"
c←a,⌽ 1 2 3 4 5 6 7 8 9 "foo" "bar" "test" "abc" "longerstringhereijwoqdjwioqjdowiqdoiwqjddjdwiojdd"
c←a,⌽ 1 2 3 4 5 6 7 8 9 "foo" "bar" "test" "abc" "longerstringhereijwoqdjwioqjdowiqdoiwqjddjdwiojdd"
c←a,⌽ 1 2 3 4 5 6 7 8 9 "foo" "bar" "test" "abc" "longerstringhereijwoqdjwioqjdowiqdoiwqjddjdwiojdd"
c←a,⌽ 1 2 3 4 5 6 7 8 9 "foo" "bar" "test" "abc" "longerstringhereijwoqdjwioqjdowiqdoiwqjddjdwiojdd"
c←a,⌽ 1 2 3 4 5 6 7 8 9 "foo" "bar" "test" "abc" "longerstringhereijwoqdjwioqjdowiqdoiwqjddjdwiojdd"

Why the Dyalog-style assignment is problematic

In Dyalog, a function can be assigned like so:

foo ← { ⍵+1 }

Now, compare this with a very similar form:

(define-g-boxed-cstruct pango-rectangle "PangoRectangle"
(x :int :initform 0)
(y :int :initform 0)
(width :int :initform 0)
(height :int :initform 0))
(defcfun ("pango_layout_get_pixel_extents" %pango-layout-get-pixel-extents) :void
(layout (g-object pango-layout))
(ink-rect (:pointer (:struct pango-rectangle-cstruct)))
(logical-rect (:pointer (:struct pango-rectangle-cstruct))))