Live data from Hacker News

Anonymous recursive functions in Racket

github.com

31–40 of 65 posts

Re: Anonymous recursive functions in Racket

#31
post #7

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!

Thanks! I haven’t really publicized it, my goal is to get it finished first, but I will be presenting on it at the scheme workshop at ICFP/SPLASH

Re: Anonymous recursive functions in Racket

#32

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.

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

#33

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. 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…

For formatting code blocks on HN, prefixing each line with 4+ leading spaces works:

    (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

#35

Earlier 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…

Shriram invoking Shriram ... (λ.x (x x) λ.x (x x)) forever \m/ :)

Re: Anonymous recursive functions in Racket

#36
post #13

Earlier quoted context omitted.

https://en.wikipedia.org/wiki/Shriram_Krishnamurthi

Don't see Y-combinator mentioned anywhere on that page.

But I do see that page mentioned on Y Combinator's page.

The joke can go on forever...

Re: Anonymous recursive functions in Racket

#37

Earlier 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…

This reminds me of when John Nagle showed up in a thread about his algorithm on here.

Re: Anonymous recursive functions in Racket

#39

In 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?

Re: Anonymous recursive functions in Racket

#40

In 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?

Without the explicit recur it's far too easy to misidentify a tail call and use recursion where it's not safe.

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?

Post reply on HN