Live data from Hacker News

Anonymous recursive functions in Racket

github.com

21–30 of 65 posts

Re: Anonymous recursive functions in Racket

#21
post #18

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

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: https://cs.brown.edu/~sk/Publications/Papers/Published/fffkb... 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;

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?

>A LOP-based software system consists of multiple, cooperating components, each written in domain-specific languages.

and

>cooperating multi-lingual components must respect the invariants that each participating language establishes.

So basically you're enforcing rules/checks at the language level rather than compile time?

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.

Also how would one navigate the complexity of multiple abstractions while debugging?

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.

Thank you again for taking the time to respond, and please do forgive me for these naive questions.

Re: Anonymous recursive functions in Racket

#22

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 node (v l r))

(define sum-tree (lam/anon (t) (cond [(mt? t) 0] [(node? t) (+ (node-v t) ($MyInvocation (node-l t)) ($MyInvocation (node-r t)))])))

(define t (node 5 (node 3 (mt) (mt)) (node 7 (node 9 (mt) (mt)) (mt))))

(check-equal? (sum-tree t) 24)

Re: Anonymous recursive functions in Racket

#24
post #21

Earlier quoted context omitted.

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: https://cs.brown.edu/~sk/Publications/Papers/Published/fffkb... 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; 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? >A LOP-based software system consists of multiple, cooperating components, each written in domain-specific languages. and >cooperating multi-lingual components must…

These are great questions!

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.

Two references I like to point to:

https://www.hashcollision.org/brainfudge/

https://beautifulracket.com/

They will give you a sense of how one uses LOP productively.

You do not need to write a "web server language"! To the contrary, the Web server provides 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.

Re: Anonymous recursive functions in Racket

#25
post #21

Earlier quoted context omitted.

Thank you for the response professor, really appreciate it from one of the creators of the language itself; 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? >A LOP-based software system consists of multiple, cooperating components, each written in domain-specific languages. and >cooperating multi-lingual components must…

These are great questions! 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. Two references I like to point to: https://www.hashcollision.org/brainfudge/ https://beautifulracket.com/ They will give you a sense of how one uses LOP productively. You do not need to write a "web server language"! To the contrary, the Web server provides s…

Understood. Will dive deeper into Racket to get a proper understanding since it's created an itch because I still don't understand it :)

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.

Thank you for taking the time to respond, have a great day!

Re: Anonymous recursive functions in Racket

#26

can we implement this in Python?

The Y combinator in Python: https://eli.thegreenplace.net/2016/some-notes-on-the-y-combi...

(scroll down, after the concept is explained using Clojure)

A bit crazier, in Go with generics: https://eli.thegreenplace.net/2022/the-y-combinator-in-go-wi...

Re: Anonymous recursive functions in Racket

#29

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.

These are my favorite types of comments on hn

The HN guidelines suggest assuming the strongest interpretation of what someone said, so obviously the commenter was making a joke. :)

Re: Anonymous recursive functions in Racket

#30

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…

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.
Post reply on HN