Skip to content

Instantly share code, notes, and snippets.

@slmjkdbtl
Last active September 12, 2024 23:29
Show Gist options
  • Save slmjkdbtl/a11d87dee7f6908bcb6d2e93e22b638e to your computer and use it in GitHub Desktop.
Save slmjkdbtl/a11d87dee7f6908bcb6d2e93e22b638e to your computer and use it in GitHub Desktop.
a different way of typing & composing behaviors

dirty lang supports currying:

$ arr = import("arr")
$ lst = [1 5 3 6 4]

lst : arr.insert(1, 8)

lst
: arr.map(~ (i) i + 10)
: arr.sort()
: arr.each(print)

: basically treats the left operand as the first argument of the following function call

but you can also do

$ arr = import("arr")
$ lst (arr) = [1 5 3 6 4]

lst : insert(1, 8)

lst
: map(~ (i) i + 10)
: sort()
: each(print)

to declare lst is* a arr, and everytime : will know the left operand is a arr and can use all its functions

this allows some flexible behavior composition like

$ pos = {
    move: ~ () {}
}

$ scale = {
    shrink: ~ () {}
}

$ sprite = {
    render: ~ () {}
}

$ froggy (pos + scale + sprite) = {
    x: 10
    y: 30
    name: "froggy"
}

froggy
: move(10, 20)
: shrink
: render()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment