
Racket: Lisp for Learning - chmaynard
https://lwn.net/SubscriberLink/795385/d7f8fe54132b2013/
======
jimbob45
Carmack is a huge fan of Racket. He was going to use it as the scripting
language for VR until the Oculus execs made him use JavaScript instead
(boooooo)

[https://twitter.com/id_aa_carmack/status/807797812700348416](https://twitter.com/id_aa_carmack/status/807797812700348416)

~~~
sdegutis
Last week I tried writing a new Love2d mode for Emacs in Emacs Lisp, but it
was on Windows so my muscle memory for Paredit wasn't helpful. Editing
s-expressions is a nightmare without some kind of automatic help. Last night I
wrote the same plugin for VS Code which used JavaScript, and naturally it was
effortless. It got me thinking about how s-expressions are inherently hostile
to non-customized setups, whereas JavaScript just uses arrow keys.

A former employer was led by huge Clojure fans, who requested that the backend
be Clojure, and highly encouraged me to use ClojureScript and something like
Reagent for the front-end, which I recently noticed that they finished after
my departure. But the more I think about it, the more I can't think of a
single feature of ClojureScript that's inherently better than JavaScript,
whereas s-expressions are inherently hostile and also have no real-world
benefits. JavaScript has destructuring, closures, a flexible module system,
object/array spread, basically every syntactical feature Clojure has, but
without the s-expressions.

The commonly touted benefit of s-expressions is homoiconicity (code is data),
which lets the developer customize the language via macros without needing to
wait on the compiler/interpreter authors. But we have this exact same benefit
in JavaScript with compilers like Babel. Maybe it's pushed onto another layer
of development, but it's in no way less legitimate or useful. The slight
benefit you get by being able to do this transformation _at runtime_ is
negated by the inconvenience of s-expressions. (Although at first glance, it
seems like we could use a better Babel API that lets us transform our code
more conveniently. But I think they're working on that?)

The main other benefit I commonly see from people using Clojure or
ClojureScript is _live development_. I saw technomancy made some blog posts
about how he used Fennel (a Lisp that compiles to Lua) to do live-coding stuff
in Love2d. I was impressed, until I realized that _none of these features were
specific to Lisp_. So I borrowed the same underlying concept he utilized, and
started to make a really cool Love2d live development thing just like he had,
but in pure Lua.

Now I have the ability to press Cmd-E in VS Code while editing some Lua file,
and if I have any code selected, it'll be sent to the live Lovd2d game that's
running, to be eval'd, and if there's no selection, the whole current file
will be sent. It's the coolest setup ever, almost identical to the awesome
setup I had with CIDER + Clojure + Emacs, but without Emacs or s-expressions.

~~~
jmiskovic
I've also came upon Clojure after investing much time in Lua/Love2d, but my
takeaways are different from yours.

I enjoyed Lua's simplicity, portability and execution speed. It shares much of
JS strengths, with fewer quirks. I was productive after a weekend of reading
Programming in Lua book.

Clojure took some more time because I had to unlearn some habits. It's for the
best, I think. It's not just about homoiconicity and REPL. In Clojure it's
hard to do the wrong thing, compared to JS or Lua. The language makes it easy
to isolate a small piece of functionality, develop and test it, and then and
put it together into coherent whole. Clojure may be harder to learn, but the
cognitive load is smaller and it scales better for large projects.

Persistent data structures are also huge step forward. They eliminate whole
class of errors and allow for traceability and reproducibility.

As for s-expressions, yes, they can be a nuisance in editor without proper
support. I'm getting by with SublimeText + zprint auto-formater. For REPL I
found no better than Atom's proto-repl. Also I hated Lua's
"if..then..else..end" and other verbose constructs. I'd say s-expressions are
more consistent and compose better. Still, your frustration is familiar to me.

~~~
NikkiA
Have you seen/tried fennel[1] or Urn[2] ?

[1] [https://github.com/bakpakin/Fennel](https://github.com/bakpakin/Fennel)

[2] [https://urn-lang.com/](https://urn-lang.com/)

~~~
jmiskovic
I've evaluated both (and also lumen) briefly. I disliked the half-way approach
that doesn't isolate Lua's messy state handling from lisp model.

Clojure also interacts with Java, but it feels like CLojure is the host that
runs Java methods as needed. The separation is clean and you know exactly when
you are crossing the boundary into stateful territory.

I see the value of those languages for lispers wanting to script the platforms
where Lua can run, but not really as a core language for modelling your
domain.

------
uxp100
Racket is a mixed bag for me.

I've found a little quirks in the standard library, with simple fixes, but
annoying. Stuff like decimal->string (?) producing odd output. (It was a tiny
fix on my end, but it's a little subjective, maybe the behavior was intended)
Not a big deal, but maybe a little impediment for learners compared to python.

The article mentions Scribble, which I use as a static site generator for a a
page with a leader board for EDH games (and maybe adding 9 ball lol). Some
small CSS changes made it OK for cell phones (basic changes to make it
responsive so it's ugly but readable), but as is it sucks, and the maintainers
have no interest in changing that.

Dr. Racket is unfortunate. If I remember correctly it has a tabbed interface,
but right clicking on the tabs does not bring up a menu, and the tabs might
not have close buttons either? It's not bad, but inferior to any dedicated
editor.

OTOH, I keep using it for little tasks, I like the language, and I seem to be
one of the few people who are excited about the Racket2 syntax, so I think I
will stick with it. I had been considering switching my lisp use to clojure.

~~~
paroneayea
Apparently we've had very different experiences.

\- Yes, there are some quirks in the standard library, but overall most of it
seems very well designed. Having spent a bunch of time in Python, which also
has a standard library with I'd argue even _more_ quirks. But most Racket
libraries seem very carefully thought out IME; I'm not sure that something
this old can not have some weird oddities though. \- We used DrRacket to teach
a class to students who had never programmed before. What's amazing is that a)
the students picked it up quickly and immediately... what other lisp can claim
having something like that? and b) it's the only editor that I myself am happy
to use other than Emacs. That's an interesting and unusual overlap, and
deserves a pat on the back.

Yes, Racket has its quirks, but what doesn't? It's still an extraordinary
project, community, development environment IMO.

~~~
snazz
What kind of machine do you have where DrRacket functions at an appropriate
speed? Does it run better on Windows, maybe? It's noticeably laggy on my
desktop with 5GB RAM free, a fast quad-core processor, and a fast SSD.

I like the design and the ideas it has for teaching, but I can't imagine it
being usable performance-wise on the kind of machines that schools usually
purchase.

~~~
laszlokorte
Turning off „background code expansion“ in the settings helps alot

------
acbart
Well, I'm pretty sure this is going to go badly for me in the end, but I might
as well leave this here:

[https://ihateracket.com](https://ihateracket.com)

~~~
acbart
And before any says it, yes, I do love the idea of students EVENTUALLY
learning a Lisp/Racket kind of language before they graduate. I would even be
happy with an entire course dedicated to it. But I don't want that to be the
CS1. I've just seen it go so wrong for so long now.

~~~
badsavage
I had a beautiful beginning with a lisp like programming language when I was 8
or something. Every other languages have been disappointments until I found
Clojure a few years ago. I hope you will get it some day.

~~~
acbart
And I hope you will learn some empathy some day and understand the perspective
of others. We all have some growing to do, it seems.

~~~
emptysongglass
The only way I was able to grok programming was through Racket. I owe my
confidence and understanding to Gregor Kizcales’ How to Code, which makes
clear to this art student what a dozen other language tutorials in a dozen
other languages could not. I deeply love Racket and give thanks to its makers.

~~~
acbart
Great! I'm glad you found a path to computing, that is truly wonderful! And
I'm not surprised that this approach worked so well for someone.

Now, let's make sure we're finding ways that can generalize. It's an important
problem in the world today.

------
AlexeyBrin
I really like Racket, but the potential breaking massive syntax change in
Racket2 makes me really uncomfortable in using or recommending Racket to other
people, at least until the situation is clarified.

~~~
jkxxkxjkjx
What?! parenthesis are a feature not a bug. Parenthesis is part of what makes
lisps so nice to use. Such a stupid decision. Makes no sense at all. Maybe
they are on drugs or something or just bored.

~~~
hnbroseph
what about parentheses has turned you into such a fan?

------
gaze
Who are the current major users of Racket? Are there any large commercial
codebases written in it?

~~~
neilv
It's mostly used in various education projects, and various commercial and
research projects that are largely done by a single strong programmer (e.g.,
Carmack-ish people).

There's at least one large-codebase complex Web-based production system in it,
which incidentally accomplished a first on AWS, but you've never heard of it,
since it's internal-ish. It was a happy accident of history, that grew out of
a lone super-productive programmer starting a complex data science
infrastructure that I'd say few teams could've pulled off in a non-Lisp.

I've been waiting for another startup to decide they're going to do their
first version in Racket, to do something non-cookiecutter. (It turned out
neither myself nor my own startup co-founder had any interest in doing the CEO
side of things, or I would've launched such a startup already.) But anything
Scheme-related has a terrible curse for perception: students associate it with
academic oddities in first-year classes, and then they focus on whatever
"real" tools they hear employers or other companies are using.

~~~
jcadam
Next time I get an idea for a side project, I'm thinking of giving Racket a
go. I've used Clojure on past personal projects (and currently at work), but
I'm starting to grow weary of the JVM.

If the next idea that comes to me happens to be/involve a web app, perhaps a
Racket backend with a cljs frontend might be fun.

------
ballpark
Any good article recommendations that explain the reasoning to the switch to
Chez Scheme as a platform for Racket?

~~~
samth
[https://blog.racket-lang.org/2019/01/racket-on-chez-
status.h...](https://blog.racket-lang.org/2019/01/racket-on-chez-status.html)
and the links at the top should provide the explanation. This paper:
[https://www.cs.utah.edu/plt/publications/icfp19-rddkmstz.pdf](https://www.cs.utah.edu/plt/publications/icfp19-rddkmstz.pdf)
has more details.

Basically, Chez is a now-open-source runtime that's very close to what Racket
needs, while also being written mostly in Scheme instead of in C (as the
original Racket runtime & compiler is). Building on Chez allows us to cut the
amount of C by a factor of ~10 while getting a better architecture.

~~~
ballpark
Perfect, thanks!

------
baristaGeek
I got into 'purely' functional programming with Racket. It's really fun to
use, and you can truly understand the functional paradigm if you dig deep into
it.

Along with it, I would recommend reading Structure and Interpretation of
Computer Programs.

~~~
alexbanks
SICP is an awesome book.

------
tombert
Does Racket support "real" multithreading yet? I remember looking at their
documentation a few years ago and it only had support for a green-threading
thing, which (along with the first-class hashmaps) steered me towards Clojure.

~~~
samth
Yes, Racket support using multiple cores/OS threads. There are two mechanisms
-- shared memory parallelism that is limited in what operations the threads
can execute in parallel (called futures in Racket) and shared-nothing
parallelism with message passing, more like Erlang (called places in Racket).
Most real work using parallelism in Racket uses places.

~~~
tombert
I guess I was confused by this [1], specifically:

    
    
        Racket supports multiple threads of evaluation. Threads run concurrently, in the sense that one thread can preempt another without its cooperation, but threads currently all run on the same processor (i.e., the same underlying operating system process and thread).
    

Is this documentation out of date or am I looking in the wrong place?

[1] [https://docs.racket-lang.org/reference/eval-
model.html#%28pa...](https://docs.racket-lang.org/reference/eval-
model.html#%28part._thread-model%29)

~~~
samth
That's about the `thread` construct specifically, which as it says is green
threads. Mostly people who are spreading work across multiple cores will have
a few places that communicate, each of which has multiple threads to handle
internal concurrency.

~~~
tombert
Fair enough! That's what I get for giving up after the first piece of
documentation.

Maybe I'll give Racket another try....

------
salusbury
I'm glad that the Lisp language has so many derivatives.

