The Racket Discourse thread on this: <a href="https://racket.discourse.group/t/illustrate-anonymous-recursive-functions-a-la-powershell/3932" rel="nofollow">https://racket.discourse.group/t/illustrate-anonymous-recurs...</a><p>(Just me suggesting other alternatives right now)
This isn't specific to racket, any implementation of R6RS scheme should fully support this, although the define-syntax form is slightly different.<p>I checked this with my R6RS implementation and it works just as you would expect (<a href="https://github.com/maplant/scheme-rs" rel="nofollow">https://github.com/maplant/scheme-rs</a>)
How close are you to getting a "full" implementation of R6RS?
I've been thinking of picking either your project or Steel[0] for a Rust Scheme thing<p>[0] <a href="https://github.com/mattwparas/steel" rel="nofollow">https://github.com/mattwparas/steel</a>
I’m hoping by the end of the year. All of the “difficult” things are finished (control flow, syntax transformers, call/cc, dynamic wind, exceptions, libraries, etc) and it’s just a matter of filling missing base library functions. If there’s something in particular that you need you’re welcome to file and issue or post a message on the discord and I’ll prioritize it.<p>That being said, Steel is excellent and I highly recommend it if you just need R5RS with syntax transformers
Wow — scheme-rs is such a neat project! Hadn't heard of it before!
In Clojure...<p><pre><code> ((fn [xs ret]
(if (empty? xs)
ret
(recur (rest xs)
(+ ret (first xs)))))
(range 5) 0)
=> 10
</code></pre>
nb. Clojure doesn't have automatic tail call optimisation. We need to explicitly emulate it with`recur`.
It's not the same thing. `recur` in Clojure must be in tail-position. This program<p><a href="https://news.ycombinator.com/item?id=45154253">https://news.ycombinator.com/item?id=45154253</a><p>would therefore not work.
Do the clojure folks still insist this is a feature, as opposed to an incomplete compiler leaking limitations into their world?
Without the explicit recur it's far too easy to misidentify a tail call and use recursion where it's not safe.<p>Recur has zero inconvenience. It's four letters, it verifies that you are in a tail position, and it's portable if you take code to a new function or rename a function. What's not to love?
Tangential, but I've been wanting to dive back into FP for quite sometime; for context I used Haskell at a payments corp ~10 years back, working mostly with Typescript, Zig and Nim for the past couple of years, realizing I am basically trying to do FP in most of these languages.<p>Is Racket a good language to pick up and re-learn my concepts + implement some tools? Or are there some other languages that would be better to both brush up and learn the syntax of, I do not want to fight the syntax but rather express functions as seamlessly as I can.
Racket is a rich and powerful language, but it is also designed with certain specific ideas in mind. You can learn more about the "zen" of Racket here:<p><a href="https://cs.brown.edu/~sk/Publications/Papers/Published/fffkbmt-programmable-prog-lang/" rel="nofollow">https://cs.brown.edu/~sk/Publications/Papers/Published/fffkb...</a><p>That might help you decide whether Racket will help you with what you're trying to brush up on.
Thank you for the response professor, really appreciate it from one of the creators of the language itself;<p>I did give your document a read and my (naive) understanding is you basically create DSLs for each sub-part of the problem you're trying to solve?<p><i>>A LOP-based software system consists of multiple, cooperating components, each written in domain-specific languages.</i><p>and<p><i>>cooperating
multi-lingual components must respect the invariants that each
participating language establishes.</i><p>So basically you're enforcing rules/checks at the language level rather than compile time?<p>How would you recommend a complete novice attain this sort of state of mind/thought process while working in this language? Because my thoughts go simply to creating types and enforcing type-checking coupled with pure functions to avoid successful-fail at runtime programs.<p>Also how would one navigate the complexity of multiple abstractions while debugging?<p>The paper also mentions a web-server language (footnote 27), if I use racket will I be productive "out of the box" or is the recommended path to take is writing a web server language first.<p>Thank you again for taking the time to respond, and please do forgive me for these naive questions.
These are great questions!<p>Yes, what you're describing is the "extreme" version of LOP. Of course you don't have to do it that aggressively to get working code.<p>Two references I like to point to:<p><a href="https://www.hashcollision.org/brainfudge/" rel="nofollow">https://www.hashcollision.org/brainfudge/</a><p><a href="https://beautifulracket.com/" rel="nofollow">https://beautifulracket.com/</a><p>They will give you a sense of how one uses LOP productively.<p>You do <i>not</i> need to write a "web server language"! To the contrary, the Web server <i>provides</i> several languages to give you a trade-off between ease and power in writing server-side Web applications. So you can just write regular Racket code and serve it through the server. The server also comes with some really neat, powerful primitives (orthogonal to LOP) — like `send/suspend` — that make it much easier to write server-based code.
Understood. Will dive deeper into Racket to get a proper understanding since it's created an itch because I still don't understand it :)<p>Even if I don't go fully into it as a production language, hopefully it'll open some avenues of thought that I do not yet possess.<p>Thank you for taking the time to respond, have a great day!
You could try Purescript, with the book¹ written by Charles Scalfani.<p>It focuses exclusively on FP and does not deviate from it.<p>¹ <a href="https://leanpub.com/fp-made-easier/" rel="nofollow">https://leanpub.com/fp-made-easier/</a>
A relevant article to the domain name of this site.
Probably worth noting that there's already an SRFI for this. [0] And that macro will work on any Scheme implementing the standard since about '98.<p><pre><code> (define-syntax rec
(syntax-rules ()
((rec (NAME . VARIABLES) . BODY)
(letrec ( (NAME (lambda VARIABLES . BODY)) ) NAME))
((rec NAME EXPRESSION)
(letrec ( (NAME EXPRESSION) ) NAME))))
</code></pre>
[0] <a href="https://srfi.schemers.org/srfi-31/srfi-31.html" rel="nofollow">https://srfi.schemers.org/srfi-31/srfi-31.html</a>
All the languages I like have niche ecosystems which have a lot of drawbacks
In such ecosystems, for long-term, evolving production work (when you don't know all your eventual needs upfront), you need to have the institutional capability to build from scratch whatever components you might need. Just in case whatever you need later doesn't yet exist in the ecosystem.<p>Then you need to retain the personnel who give you that capability. Because they are rare, in a field in which 99%+ of developers only glue together NPM or PyPI packages. (And many use Web search or, now, Claude Code to do the glue part.)<p>If I founded a startup doing mostly Web-like server backend work, I'd consider doing it in Racket or another Scheme, and then using that as a carrot to be able to hire some of the most capable programmers. (And not having to bother with resume spamming noise from hardly any of the 99%+ developers, who will be pounding the most popular resume tech stack keywords instead, because their primary/sole goal is employability.)
The correlation is likely causal in both directions.<p>They're niche because they're doing weird, interesting things. Like creating their own VMs to support funky features. So nobody wants to depend on them: low bus-factor.<p>They can do weird, interesting things because they don't have a large user-base that will yell at them about how they're breaking prod.
can we implement this in Python?
The Y combinator in Python: <a href="https://eli.thegreenplace.net/2016/some-notes-on-the-y-combinator/" rel="nofollow">https://eli.thegreenplace.net/2016/some-notes-on-the-y-combi...</a><p>(scroll down, after the concept is explained using Clojure)<p>A bit crazier, in Go with generics: <a href="https://eli.thegreenplace.net/2022/the-y-combinator-in-go-with-generics/" rel="nofollow">https://eli.thegreenplace.net/2022/the-y-combinator-in-go-wi...</a>
I would rather use a loop so I can debug it.
This isn't meant to be a good programming mechanism, it's meant to be an illustration of how to use the macro system.<p>But also, if you're processing non-linear data, you're going to want to do with a recursive function anyway. E.g., when dealing with a tree. Code below; can't seem to get multi-line code-formatting so it looks hideous:<p>#lang racket<p>(require "anon-rec.rkt")
(require rackunit)<p>(struct mt ())
(struct node (v l r))<p>(define sum-tree
(lam/anon (t)
(cond
[(mt? t) 0]
[(node? t) (+ (node-v t)
($MyInvocation (node-l t))
($MyInvocation (node-r t)))])))<p>(define t (node 5
(node 3 (mt) (mt))
(node 7
(node 9 (mt) (mt))
(mt))))<p>(check-equal? (sum-tree t) 24)
For formatting code blocks on HN, prefixing each line with 4+ leading spaces works:<p><pre><code> (define sum-tree
(lam/anon (t)
(cond ((mt? t) 0)
((node? t) (+ (node-v t)
($MyInvocation (node-l t))
($MyInvocation (node-r t)))))))</code></pre>
Recursion just ends up using the call stack as a stack data structure. I would much rather use an actual stack data structure, that will be easier to debug and have better locality since there isn't an entire call frame overhead to put one value into the stack.
Tail-recursive functions in Racket are optimized down to essentially for loops.