This isn't specific to racket, any implementation of R6RS scheme should fully support this, although the define-syntax form is slightly different. I checked this with my R6RS implementation and it works just as you would expect ( https://github.com/maplant/scheme-rs )
Wow — scheme-rs is such a neat project! Hadn't heard of it before!
Anonymous recursive functions in Racket
31–40 of 65 posts
Re: Anonymous recursive functions in Racket
#32All the languages I like have niche ecosystems which have a lot of drawbacks
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.)
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.)
Re: Anonymous recursive functions in Racket
#33I 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. 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: #lang racket (require "anon-rec.rkt") (require rackunit) (struct mt ()) (struct nod…
(define sum-tree
(lam/anon (t)
(cond ((mt? t) 0)
((node? t) (+ (node-v t)
($MyInvocation (node-l t))
($MyInvocation (node-r t)))))))Re: Anonymous recursive functions in Racket
#34 ((fn [xs ret]
(if (empty? xs)
ret
(recur (rest xs)
(+ ret (first xs)))))
(range 5) 0)
=> 10
nb. Clojure doesn't have automatic tail call optimisation. We need to explicitly emulate it with`recur`.Re: Anonymous recursive functions in Racket
#35Earlier quoted context omitted.
If you look at the code, you'll be (unpleasantly) surprised, I think. The author does not seem to have known what Y combinator is.
If it helps, you will find the Y-combinator described (indeed, derived) in the first edition ( https://cs.brown.edu/~sk/Publications/Books/ProgLangs/2007-0... ) of the author's programming languages book ( https://www.plai.org/ ). (Page 228, if that helps, though the derivation begins on page 223.) For added fun, the day he teaches it in class, he wears a t-shirt from Y-combinator the startup accelerator (and explain…
Re: Anonymous recursive functions in Racket
#36Re: Anonymous recursive functions in Racket
#37Earlier quoted context omitted.
If you look at the code, you'll be (unpleasantly) surprised, I think. The author does not seem to have known what Y combinator is.
If it helps, you will find the Y-combinator described (indeed, derived) in the first edition ( https://cs.brown.edu/~sk/Publications/Books/ProgLangs/2007-0... ) of the author's programming languages book ( https://www.plai.org/ ). (Page 228, if that helps, though the derivation begins on page 223.) For added fun, the day he teaches it in class, he wears a t-shirt from Y-combinator the startup accelerator (and explain…
Re: Anonymous recursive functions in Racket
#38Re: Anonymous recursive functions in Racket
#39In Clojure... ((fn [xs ret] (if (empty? xs) ret (recur (rest xs) (+ ret (first xs))))) (range 5) 0) => 10 nb. Clojure doesn't have automatic tail call optimisation. We need to explicitly emulate it with`recur`.
Re: Anonymous recursive functions in Racket
#40In Clojure... ((fn [xs ret] (if (empty? xs) ret (recur (rest xs) (+ ret (first xs))))) (range 5) 0) => 10 nb. Clojure doesn't have automatic tail call optimisation. We need to explicitly emulate it with`recur`.
Do the clojure folks still insist this is a feature, as opposed to an incomplete compiler leaking limitations into their world?
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?