I have no idea why I didn't try this in over a year (!!!) of working on alv, but after playing with glisp (glisp.app, it's excellent! try it out!), I added some basic graphics to alv (wrapping love2d)... and it's great!


I really need to implement the clojure threading macros (-> / ->>) now...

· · Web · 1 · 0 · 0

actually, maybe I want a reverse threading macro? I guess it would be called <-, so that

(draw (<-
(rect 20 20)
(rotate (ramp twopi))
(translate x y)))

can be equivalent to

(translate x y
(rotate (ramp twopi)
(rect 20 20))))

haha happy you caught that, I wrote it out as "import love time math" first but then I felt this change was in order

@s_ol yeah! that's a very useful thing, I'm also implementing is as a "mu" function, it has a lot of potential (currying, or even potentially returning multiple values at once and piping them to the next function)
Also Haskell's >>= operator does something similar. But with...lotsa quirks LoL

@nff hm, what does that mu function look like?

@s_ol I'm still fine-tuning it, but right now it looks like this:
(dd is for define, and \ is lambda)
dd double \x,mul x 2
dd triple \x,mul x 3
dd halve \x,div x 2
dd avg \ a b,mu sum a b..halve
dd mynum 3
mu mynum..double..triple -- OK, it's 18
mu mynum..double..avg -- ERROR: function arity mismatch
mu 7 3..avg -- OK, it's 5

this would be a simple distortion function, currying mul and then piping to tanh
dd dist \x, mu x..mul 5..tanh

@s_ol returning multiple values and piping:
dd fseq f100 300 2000 500 1000 --sequence of frequencies
dd lohi \s th, s|lt th, s|ge th --split low and high frequencies on threshold
mu fseq..lohi.., dist..sin1..o0, sin1..o0 --mu parallel piping, distort only low freqs

and also
dd seqavg \a b, mu a, b..add../2
dd s1 f400 234 5454 944 548 70
dd s2 f332 4394 854 2342 544
mu s1, s2..seqavg..bpm95..sin..o1
resulting sequence: 2314 3154 1642 546 2232 544 3898 744...


ah, so with your syntax "mu a..b..c" is equivalent to "c(b(a))" (but it supports multiple arguments as well)?

@s_ol yepp exactly!
and also, lambdas/functions are able to return multiple values. That can be done without all of this of course:

dd mylist 1 2 3 4 5 6 7 8 9 10
dd evenodd \x, x|iseven, x|isodd
mu mylist..evenodd..add -- 3 7 11 15 19

--without mu and multiple return values would be:
dd evens iseven mylist
dd odds isodd mylist
dd newlist add evens odds

--or even
dd newlist add iseven mylist isodd mylist

but yeah, I guess it's just a question of "ergonomics" for me :)

Sign in to participate in the conversation

Merveilles is a community project aimed at the establishment of new ways of speaking, seeing and organizing information — A culture that seeks augmentation through the arts of engineering and design. A warm welcome to any like-minded people who feel these ideals resonate with them.