News for hackers. Stuff that matters.
Re:Developing a Space Flight Simulator in Clojure by MathMonkeyMan on Friday September 05, 2025 @10:09PM (#45145968)
Guile has [multi-methods][1] and [fast hash maps][2], but not yet [dynamic vectors][3].

Clojure's data structures are easier to use, though.

[1]: https://www.gnu.org/software/guile/manual/html_node/Methods-...

[2]: https://www.gnu.org/software/guile/manual/html_node/Hash-Tab...

[3]: https://lists.gnu.org/archive/html/guile-devel/2022-01/msg00...

Re:Developing a Space Flight Simulator in Clojure by exabrial on Friday September 05, 2025 @10:19PM (#45146023)
Clojure is such a departure for me, coming from C-Like languages. I have absolutely no idea whats going when looking at the code.
Re:Developing a Space Flight Simulator in Clojure by JoshCole on Friday September 05, 2025 @11:36PM (#45146395)
Lisps (like Clojure) treat code as data (lists), so you write: `(if x (y) (z))` instead of Python’s `y() if x else z()`. So the code is more concise, but does less to walk a novice through it.

This gains a huge advantage, which allows even more concision: all code is data, so its easy to transform the code.

In Clojure if you want to add support for unless, a thing like if, but evaluating the opposite way you could do this: `(defmacro unless [p a b] `(if (not ~p) ~a ~b))`. Obviously if you wanted to do the same thing in Python you would in practice do `z() if x else y()`. However, you would do it that way because Python isn't as powerful a language. To actually do the same thing in Python you would need to...

1. Add __future__ support.

2. Update the Python language grammar.

3. Add a new AST type.

4. Add a new pass stage to the compiler.

5. Add a python library to integrate with this so you could use it.

Then you could do something like:

    from __future__ import macros

    defmacro unless(pred, then: block, else_: block = []):
        return q[
            if not u(pred):
                u*(then)
            else:
                u*(else_)
        ]

So in the trivial case its just hundreds of lines harder plus requires massive coordination with other people to accomplish the same feat.

This sort of, wow, it takes hundreds or thousands of lines more to accomplish the same thing outside of Lisp as it does to accomplish it within Lisp shows up quite often; consider something like chaining. People write entire libraries to handle function chaining nicely. `a.b().c().d().map(f).map(g)`. Very pretty. Hundreds of lines to enable it, maybe thousands, because it does not come by default in the language.

But in Lisp? In Clojure? Just change the languages usual rules, threading operator and now chaining is omnipresent: `(->> a b c d e (map f) (map g))`. Same code, no need to write wrapper libraries to enable it.

Re:Developing a Space Flight Simulator in Clojure by roenxi on Saturday September 06, 2025 @12:45AM (#45146690)
That doesn't look like a factor in the article though, he isn't using many if any macros that aren't part of the core language. And the one macro I do spot (defcfn) is pretty mild in context.
Re:Developing a Space Flight Simulator in Clojure by sabellito on Saturday September 06, 2025 @03:55AM (#45147448)
I've programmed in Clojure professionally.

People like GP often repeat that talking point: "code is data so that's amazing because of macros".

In practice, by and large, with very few exceptions, macros are frowned upon in the same way that using metaprogramming in ruby is. Macros are only fun to the person writing them (and not even the author when they have to maintain it). Macros can almost always be expressed with a simple function and remove all the unexpectedness without losing anything. Again, there are some exceptions.

Re:Developing a Space Flight Simulator in Clojure by vkazanov on Saturday September 06, 2025 @04:38AM (#45147634)
Dunno about the Clojure communtity but for Emacs Lisp and Common Lisp there are certain broadly accepted idioms where macros are accepted:

1. "with-context", where there is a need to control resource allocation/deallocation or things in the context of code in question. 2. use-package dsl that simplify configuration in a predictable way 3. object definition helpersresource

Then, there are core language extensions and std libraries suggested for the main implementation. This is where macros are fine as they always get good documentation and plenty of additional eyeballs.

Re:Developing a Space Flight Simulator in Clojure by sabellito on Saturday September 06, 2025 @05:26AM (#45147838)
Fully agreed with your examples. As a rule of thumb macros should be kept inside libraries, not application code.
Re:Developing a Space Flight Simulator in Clojure by prerok on Saturday September 06, 2025 @04:52AM (#45147684)
Thank you for posting this.

I always looked at these features of being able to extend the language beyond some commonly accepted practices as detrimental to the language. I've spent way too much time debugging issues with operator overloading or complex templates (C++), or obscure side effects in DSLs. So, (re)defining language constructs in a project seems nightmarish to me to support in production and therefore I never even attempted anything serious in a functional programming language.

But... looks like the professional community knows this and so maybe it's time to take a deeper dive :)

Re:Developing a Space Flight Simulator in Clojure by diggan on Saturday September 06, 2025 @09:42AM (#45149203)
> So, (re)defining language constructs in a project seems nightmarish to me to support in production and therefore I never even attempted anything serious in a functional programming language.

It can be, but also not. If you isolate them into libraries with clear interfaces, you can kind of avoid that. I think clojure.core.async is an excellent showcase in something you couldn't do in other languages, where asynchronous channels were possible to add to the core language without changing anything in the core compiler itself, and because of the small interface, you can still use it without ending up with nightmares :)

Re:Developing a Space Flight Simulator in Clojure by prerok on Monday September 08, 2025 @02:52AM (#45165325)
Understood. I was more referring to a case where a project would start defining its own language constructs and if each project would do that then every single project would come with a very high cognitive load.
Re:Developing a Space Flight Simulator in Clojure by diggan on Saturday September 06, 2025 @09:40AM (#45149191)
> In practice, by and large, with very few exceptions, macros are frowned upon in the same way that using metaprogramming in ruby is. Macros are only fun to the person writing them (and not even the author when they have to maintain it).

I'm not sure "frowned upon" is the right expression, but I'm not a native speaker.

The way I've internalized it, is basically "Avoid macros unless there is no other way", which basically means use functions/anything else whenever you can, but if you absolutely have to use a macro for something (like you wanna read the arguments before they're parsed), then go for it.

Re:Developing a Space Flight Simulator in Clojure by wedesoft on Monday September 08, 2025 @03:02PM (#45172415)
I use a few macros for creating contexts (i.e. with-texture, with-stencil, with-scissors, with-tar). Also I have macros for rendering (onscreen-render, offscreen-render). However I try not to overuse macros.
Re:Developing a Space Flight Simulator in Clojure by exabrial on Saturday September 06, 2025 @08:14AM (#45148602)
This was incredibly useful
Re:Developing a Space Flight Simulator in Clojure by roenxi on Friday September 05, 2025 @11:21PM (#45146335)
Fun fact: the big difference isn't the syntax. Lisps only go from foo(bar baz) to (foo bar baz) which is a change but not really much of one. The change is actually the immutable and high performance basic data structures. Clojure can do something that something like C can't do - cheaply create a copy of something with a small change. That leads to a completely different preferred code style in the Clojure community that is a big departure from C-like languages which make heavy use of variables. The code is doing something practically different from what a C-like language can ergonomically handle.
Re:Developing a Space Flight Simulator in Clojure by Zambyte on Saturday September 06, 2025 @01:16AM (#45146800)
Clojure has a bunch of other syntactic structures not found in other lisps that makes it a lot more visually noisy. I'm very comfortable with Scheme and I can very quickly absorb Scheme code when reading it, but I have to very slowly decipher the code in the article.
Re:Developing a Space Flight Simulator in Clojure by iLemming on Saturday September 06, 2025 @05:35PM (#45153068)
> not found in other lisps that makes it a lot more visually noisy

I disagree. It only feels that way, until you learn how destructuring works in Clojure. Once you grok that, you'd understand why the vector syntax for function arguments was chosen, and not a simple list like in other Lisps. In general, Clojure is highly pragmatic - if something done certain way, most-likely it's for good reasons, and not by accident.

Also, Clojure-maps are just freaking amazing. I wish others, e.g., Elisp had them.

Clojure is extremely and nicely readable, just requires some getting used to it. At some point, I completely replaced my API-testing workflows, switching from JSON to EDN - it's almost twice more compact and much better visually, not to mention that it's incredibly nice to be able to just explore and visualize any given data through the REPL.

Re:Developing a Space Flight Simulator in Clojure by Zambyte on Monday September 08, 2025 @09:04AM (#45167756)
> It only feels that way, until you learn how destructuring works in Clojure

Well... yes. The original comment was about how Clojure code looks very foreign. The reply to that was that Lisp code is not actually that foreign because it's just taking the common foo(bar baz) and making it (foo bar baz). My comment was that Clojure is more foreign to most programmers than other Lisps, because it's not simply mapping foo(bar baz) to (foo bar baz).

Of course when you learn the things that make it unique, it becomes familiar.

Re:Developing a Space Flight Simulator in Clojure by rufusthedogwoof on Friday September 05, 2025 @10:27PM (#45146080)
it's not code it's data. :) -macro
Re:Developing a Space Flight Simulator in Clojure by iLemming on Saturday September 06, 2025 @12:31AM (#45146634)
That's just existing muscle memory. Nothing is wrong with you and nothing is wrong with Clojure. I had the same feeling when I started with Lisp. Give it some time, it's absolutely worth it. Interestingly, every single programmer I introduced to Clojure as their very first programming language had no issues picking it up. Later, they complained about difficulties getting used to Javascript and Python.
Re:Developing a Space Flight Simulator in Clojure by pjmlp on Saturday September 06, 2025 @07:40AM (#45148401)
Many of Lisp ideas are possible in C++, but I guess that depends how much you know it.
Re:Developing a Space Flight Simulator in Clojure by wedesoft on Monday September 08, 2025 @04:14PM (#45173350)
Yes, I forgot. Clojure multi methods are more generic in that the function computing the dispatch value can also be defined.