pastagang blog

This is just a copy paste from this mastodon thread

More docs are here now: https://codeberg.org/pastagang/basil

Cheat sheet here: /blog/basil/docs.html

Posts

#pastagang just soft launched a new hydra language :o #basil

These two are the same semanticaly.

Basil is just a veeeeery thin syntax sugar layer over hydra, its literly being translated into hydra JS code, and then its just normal hydra (or well hydro!) code.

Lots of bugs probably, lots of caveats. no special array syntax (yet?)

in this language # and \n are the same. (well most of the time; there are places where new lines are ok, but # isn’t)

Both (usually) are the “chaining operator”

so o # r becomes o().r() arguments, are space delimited () denote sub-chains (and its the only way to start one, you always need them in add/layer/mod)

<: and :> sourond “javaScript literal”. everything in between will not be modified or parsed. Only way to do dynamic arguments currently.

all aliases are here (currently) https://nudel.cc/basil/basil.js Or see the code here: https://codeberg.org/pastagang/basil/src/branch/main/src/basil.ts

Note that some also reshuffle the arguments! rs .2 becomes .rotate(0, .2)

I still struggle with a basil-native lambda syntax. If I try to not parse JS I need a syntax that is invalid in JS, so somthing like: h (> fft(0,1) <) (just a bit different from what works currently: <: () => fft(0,1) :> )

But it feels a bit weird. also having to ways of interleaving JS, with slightly different semantics is also not ideal.

Another direction would be to have real native lambdas somehow.

But that means we need to enable expressions such as fft() * 2 + .5 (ignoring the current aliases for * and +), the most native basil solution would be: + (* (fft) 2) .5

A better looking basil solution would probably be fft # * 2 # + 5

We do need to handle this chain completely differently then the other ones though.

Wich is not my favorite thought (normaly this would be transpiled to fft().*(2).+(5)

That is not valid JS, even if we aliases the * & + to mult and add. (but we /could/ patch the number prototype maybe)

(> fft # * .2 # + .2) works now.

That was easier then I thought.

Mostly because I hacked + and * (or rather plus and mult) to be functions on the number prototype in nudel lol

ahh but (> time # / 10) does not. it gets translated to () => time().diff(10)

but time isn’t a function 🙃

h (> <:time:> / 10)

weirdly this works.

By accident lol

it will be translated to ` () => time.diff(10)`

I think @j_g00da was also correct. It’s turning more and more into lisp lol.

If I add an „id“ (for identity) function, h (> (id time # / 10 ) would work.

(Even better a top level deffinition, so this becomes h (> / time 10))

The more I work on basil, the more exploration ideas I get, example:

go deep the minimal syntax road, make it so osc x 1 y 2 rot 2 mod (n 2) out is valid (get rid of the #, by distinquishing between “functions” and “values” this will reduce the possible expressions by a lot (variables are impossible with this?)

This syntax doesn’t really vibe with me. I know its just lisp style expressions (/ s-exrressions if I’m not mistaken), but I just never got the appeal.

rot (> * (Math.sin ( / time 3)) Math.PI)

I find it harder to read then Math.sin(time / 3) * Math.PI The * and the arguments it operates on are so far appart. So far I haven’t found a way to reconsile a syntax that works within the basil system, that bridges this hmm

s0 # initImage ( spag "logo")

This works now! I added an identify function: id = (it) => it With this I can “simply” alias “s0” to “id s0”.

And now this works! =D (all s1-3 and time are aliased currently, and a bunch of Math functions as well just “sin” works now!)

Added propper error mapping to nudel for basil. Parsing and JS errors should properly be shown in the editor now! Should make writing in basil a better experience!

🤔 ((P "<1 0>")) IIFE (Immidate Invoked Function Expression)

It looks super whacky, but it slots right into the basil syntax so far (we call the first thing in the S expression)

Correction:

((P "<1 0>")) Calling functions that are returned by other functions (P returns a function)

Propper IIFE would be: ((> * 3 time)) and with arguments: ((x> * x times) 3)

For a minute I thought range 0 10 # (x> x + 2) is now possible too.

But then it emited range(0, 10).(x) => add(x, 5)() chain items need special handling for the lambda case lol

Ahh tbf range 0 10 # map (x> + x 5) works correctly, and tbh maybe thats the cleaner way anyway!

Why have this in the first place you ask?

It’s a side effect of the goal to allow some for loop kind of thing, to make it be possible to add 10 of a thing. (This goal still needs variable declarations top level though, and I currently don’t have a nice syntax for it)

basil still is hold back by it current transpilation concepts :/ (I could also just add these function in the underlying JS, but I also want to push the envelop of basil further!) In a world where chains are evaluated as currying , this would be easier lol.

Maybe have a dedicated hydraFun thing?

This works!

Its a bit of a weird syntax (heck, what isn’t in this language haha). Also only works because if the JS escape, definetly not native basil

hydraFunc "xy" (thiz x y> id thiz # x x # y y) // best "syntax ever"

Intended behaviour 🙃 (this works, beucause the first x/y are actually translated to “.scrollX”)