clojure-europe

Ludger Solbach 2025-11-30T10:03:13.179839Z

Morning!

mccraigmccraig 2025-11-30T05:20:59.849399Z

månmån

mccraigmccraig 2025-11-30T05:23:02.216259Z

have fallen down the Algebraic Effects 🐰-hole

mccraigmccraig 2025-12-01T13:59:01.469559Z

you could use multimethod with methods with match-all varargs, right ? (it's been a while - can you use varargs in defmethod?) and then run the pattern a second time to get bindings but you'd have to run the patterns twice - once to find the dispatch value, and again for bindings

mccraigmccraig 2025-11-30T08:08:33.073229Z

pattern looks great... has you seen anything which uses it to match function parameter lists and bind variables ? i.e. choose from a list of function implementations based on which has matching parameters ?

Ben Sless 2025-11-30T08:11:16.987209Z

No but I've seen a library that did that with core.match

Ben Sless 2025-11-30T08:12:33.890999Z

Another username I remember, killme2008, hmm,, let's check out his Github oh, the CEO of greptime db, neato cheeto https://github.com/killme2008/defun

Ben Sless 2025-11-30T08:13:59.543669Z

First thing I did on my first Clojure job was hack on his carmine extension library

mccraigmccraig 2025-11-30T08:18:31.555589Z

> https://github.com/killme2008/defun that could work!

Ludger Solbach 2025-11-30T10:07:42.491579Z

choose from a list of function implementations based on which has matching parameters? multimethods?!?

mccraigmccraig 2025-11-30T10:21:03.295009Z

hmm... well multimethods dispatch on a single value, so you could use a pattern match to get that value and then dispatch the multimethod and destructure in the params for bindings - but then you've effectively got two patterns of different syntaxes for each function, which feels quite awkward and error prone

mccraigmccraig 2025-11-30T10:24:02.809949Z

I do find Elixir's pattern matching function heads (and case) much easier to use (and comprehend when reading code) than multimethods... but there's no particular reason clojure can't have something very similar

Ben Sless 2025-11-30T10:25:42.130639Z

I think it becomes an issue with method order resolution, where in regular pattern matching implementations collisions are resolved in order while Clojure will just barf at you or exhibit inconsistent behavior

Ben Sless 2025-11-30T10:27:56.239279Z

You'll also run into some difficulties with parsing and default values. Pattern matching complects the dispatch values with the shape of the parsed object but with mm you'll have to work twice (I think)

Ludger Solbach 2025-11-30T19:27:07.628559Z

multimethods dispatch on the value of a function of any parameters, not on a single value, so they could be what you need.

mccraigmccraig 2025-11-30T19:31:27.471619Z

it has to evaluate a function to get that dispatch value, which would be a pattern-match - then, it has to bind variables in the implementation - which would be another run of the same pattern-match - so I think it would have to run the match twice

mccraigmccraig 2025-11-30T19:32:45.347909Z

the killme2008/defun approach seems simpler

Ben Sless 2025-12-01T07:05:00.435719Z

You can try implementing it with multimethods, but the second you get to destructuring patterns you're going to have a bad time. Or even wildcards with two args. Give it shot

➕ 1
Ben Sless 2025-11-30T06:07:57.711129Z

Unison?

mccraigmccraig 2025-11-30T06:51:46.413069Z

no, I followed the 🐰 even deeper, and rolled my own 😬

mccraigmccraig 2025-11-30T06:56:35.797199Z

in https://github.com/mccraigmccraig/freyja rather than Clojure, 'cos that's where the dayjob is atm, but Elixir is sooooo similar to Clojure I'm wondering how easy an automatic port would be - Elixir has hygienic macros, pesistent data-structures, protocols... the main challenge would probably be around pattern-matching, which Clojure doesn't have

Ben Sless 2025-11-30T07:38:19.806859Z

We have pattern matching as five libraries. Pick one 😁

Ben Sless 2025-11-30T07:41:33.937979Z

I'm curious, will read your lib

Ben Sless 2025-11-30T07:42:45.463459Z

Something in algebraic effects always reminds me of the free monad

mccraigmccraig 2025-11-30T07:44:19.303649Z

there is both a Free monad (for the higher-order effects) and a Freer monad (for the first-order effects) hiding inside that lib 🙂

mccraigmccraig 2025-11-30T07:45:30.355989Z

but the first rule of monad club (in both Elixir and Clojure land) is: we don't talk about monads 🙂

😁 2
mccraigmccraig 2025-11-30T07:49:08.030819Z

> We have pattern matching as five libraries. Pick one I've only tried core.match and didn't really get on with it - and iirc it doesn't support function-head matching... have you found a pattern match lib you like ?

Ben Sless 2025-11-30T07:51:58.683069Z

Pattern is nice but don't use it for job interview take him tasks 😉 Wow, I even remembered the author https://github.com/pangloss/pattern

👀 1
Ben Sless 2025-11-30T07:52:05.464529Z

Gem library tbh