clojure-gamedev

2021-11-15T15:52:13.091400Z

https://github.com/IGJoshua/cljsl This is still pre-alpha, but it's useful in its current state and I'm building stuff in my game engine with it. I'd love for others to check it out. It's a way to write shader code in Clojure (and I'll probably update it to work in CLJS too in future) for OpenGL, OpenGL ES, and technically WebGL, although as I said, it doesn't quite work in CLJS yet. It supports a good subset of the Clojure syntax, basically only lacking if expressions and lambdas, but that's because the compilation technique is a very naive recursive descent expression translator, and both of those features would require manipulation of the parsed AST before emitting the GLSL code.

❤️ 2
2021-11-15T15:53:19.092800Z

It has some significant advantages over writing in GLSL because it includes namespaced identifiers and built-in dependency tracking, so you never need to worry about whether or not some library function you write for your shaders is being included (so no need for #include directives or anything), and the shader code is just inside your regular Clojure namespaces, living along side normal code.

2021-11-15T15:53:36.093Z

Oh and it supports macros.

2021-11-15T15:54:38.093700Z

is there any way to have conditional expressions?

2021-11-15T15:54:53.094100Z

Oh absolutely, it has if statements and cond statements, but they're statements, not expressions.

2021-11-15T15:56:07.095900Z

Sorry, mistook your meaning. When I was looking last time I didn't find the ternary operator, but it's in there, but it's more limited than what you'd get out of proper clojure-style if expressions.

2021-11-15T15:56:08.096Z

my apologies, i interpreted your lacking if expressions to mean you can’t have conditionals in the clojure side

2021-11-15T15:56:19.096200Z

definitely can have conditionals.

2021-11-15T15:56:31.096500Z

okay, cool. this is very very cool

2021-11-15T15:56:56.097Z

I might just throw in a ternary operator on the ? symbol since that's the normal syntax for it and that way it's clear that it's not as powerful as if

2021-11-15T16:00:37.097300Z

There we go, now there's a ternary operator

2021-11-15T16:02:45.099Z

Thanks! Yeah, I put in a reasonable amount of work on it. I really want to be working on a "v2" of the prototype that's a compiler that actually has intermediate steps between parsing (the clojure reader) and code generation (this library) that allows more complex things like type inference, monomorphization of generic functions and hof, defunctionalization, and more. But for now this does everything I need to make games because I'm perfectly comfortable having the sub-language be less powerful than Clojure for now.

2021-11-15T16:03:23.099500Z

although in theory all those extra compilation steps could be done by sufficiently advanced macros on top of my code generation functions.