
Racket Is an Acceptable Python - paroneayea
https://dustycloud.org/blog/racket-is-an-acceptable-python/
======
kazinator
I've been making a language called TXR for ... oh, ten years this coming
August now. It combines a Lisp dialect ("TXR Lisp") with a whole-document
pattern-based extraction language ("TXR Pattern Language"). It takes the form
of a simple executable with a few satellite files in your /usr/share.

Lots of "batteries" are included in TXR Lisp: object system with static and
instance slots, single inheritance, GC finalization and a form of RAII,
exception handling, delimited continuations, byte code compiler for virtual
machine, file compilation, macros (of course), regexes, built-in lazy lists, a
fantastic set of macros for partial application, a comprehensive declarative
FFI, good amount of POSIX wrapage built-in, a decent REPL with history,
completion, multi-line editing, visual copy-paste, ...

TXR Lisp has a concept similar to CL's "generalized places" implemented
differently. It supports Lisp-1-style evaluation (higher order functions used
without a _funcall_ operator), in the middle of a Lisp-2 substrate.
Traditional list operations are generalized so they work on other sequences;
you can _mapcar_ over a string and such.

Link: [https://nongnu.org/txr](https://nongnu.org/txr)

~~~
6thaccount2
First of all, thanks for doing this and making it free.

I do a lot of shell based work (Linux commands, Awk, Python, Perl, and
Powershell) and Lisp has always interested me, so this may scratch an itch.

How easy is this to get setup? Just a few binaries?

Also, one barrier to me has always been learning lisp as it is very different
from most traditional scripting languages. I took a look at your examples and
it looks neat, but a little complex. Is there a tutorial document that goes
over the main functionality and commands. Like with Linux, knowing grep,cut,
sort, uniq, cat, and a few others can take you a long way. I should add that
although I haven't coded enough lisp to get competent, I've read two books on
Common Lisp and have played with Chez Scheme, Racket, and Clojure...so I get
the concepts with CONS/CAR/CDR...macros...etc.

~~~
kazinator
> _How easy is this to get setup? Just a few binaries?_

From sources, just unpack, ./configure (with --prefix=/your/dest/dir if you
don't want it in /usr/local/bin), make, make tests, make install if you're
going from source. The dependencies are very low. But one of them is libffi;
./configure doesn't complain about it missing, but you get a build with
reduced functionality (which doesn't pass certain tests).

For every release I make tarball packages for for older Debian 5.x (64 bit),
Ubuntu 12 (32 bit), Mac OS 10.7.4 (64) and Solaris 10 (x86, 32 bit) as well as
Cygwin (32 and 64).

For native Windows, I make a installer. It registers TXR into your PATH
environment variable and associates .txr and .tl file associations.

TXR installations are relocatable: TXR discovers its own path and then finds
the satellite files relative to its own location; if you keep the relative
locations of the pieces as they are, you can move it anywhere in your
filesystem. That's also useful for deployment. In the TXR executable there is
a 128 byte space where you can embed command-line arguments to the executable.
There is a helper function for this called _save-exe_.
[https://www.nongnu.org/txr/txr-
manpage.html#N-02850687](https://www.nongnu.org/txr/txr-
manpage.html#N-02850687)

If you've read books on Common Lisp, you're in pretty good stead. My own Lisp
background is heavily Common Lisp, and the CL influences in TXR Lisp are
clear; yet it's not CL and will probably mess with your head if you know a bit
of CL in ways that it wouldn't if you didn't know CL. The reference manual has
some dialect notes in relation to CL, far and few between though.

I don't have a newbie tutorial, unfortunately; I'm hoping someone else will
write that. Keeping the documentation complete and at a good level of quality
has been a big effort; it's pushing close to 700 pages now if PDF-ed.

~~~
6thaccount2
Thanks for the lengthy reply. I'll have to give it a try at some point.

Even as a current non user I'm always super stoked by the large effort put
into these projects and wish you the best!

------
epr
Racket is great if you are looking for a high quality general purpose
language, but if you want to use important python libraries for pythons's
popular use cases: numerical/scientific computing, data science/ai, etc., then
Hylang is a drop-in replacement with the added benefit of Metaprogramming
facilities (Lisp-2 macros) and Clojure-like semantics.

Python and Hy have 100% interoperability. Python can call Hy out of the box,
and Hy can call Python out of the box.

Any Python programmer can pick up Hy basics in minutes, and will be productive
in a matter of hours. If you are an intermediate level Python programmer and
have experience with Lisp macros, you will be writing macros in no time as
well. Writing macro wrappers for numerical/scientific applications can
increase your code's signal to noise ratio by quite a lot.

docs: [http://docs.hylang.org/en/stable/](http://docs.hylang.org/en/stable/)

github: [https://github.com/hylang/hy](https://github.com/hylang/hy)

get it:

    
    
      pip install hy

~~~
nonbirithm
Actually Hy is mentioned in the article, though the author found it didn't fit
his usecase.

> Alas, Hy didn't really reach my dream. That macro expansion made debugging a
> nightmare as Hy would lose track of where the line numbers are; it wasn't
> until that when I really realized that without line numbers, you're just
> lost in terms of debugging in Python-land. That and Python didn't really
> have the right primitives; immutable datastructures for whatever reason
> never became first class, meaning that functional programming was hard,
> "cons" didn't really exist (actually this doesn't matter as much as people
> might think), recursive programming isn't really as possible without tail
> call elimination, etc

~~~
epr
Debugging macro expanded code is definitely the number one pain with Hy,
although a somewhat workable solution is to view the output of hy2py (comes
with hy).

As far as the lack of functional programming semantics go (no tail call
elimination is very sad indeed), there is no denying that either, but
considering the applications I am recommending (c/c++ inter-op with python
wrappers), you are hardly working in a functional domain in the first place.

------
lkirk
A big use case for python is glue for high performance c/c++ code. How is
racket at this? Also, is there a cython alternative for racket? I would also
argue that, though racket may have more batteries included, there are
definitely not as many externally developed libraries. Especially important
are numpy/scipy/pandas/pysam, the list could go on... That's not to say that
I'm against racket, I really like the language and its level of design and
documentation.

~~~
pavpanchekha
I've used the Racket FFI for some important tasks, and it's very easy to use.
However, it's not as fully baked as the Python one (I've found bugs due to GC
interactions) and it's weirdly slow (a few too many levels of wrapping). That
said, I still use Racket extensively and enjoy it.

~~~
yomly
This is the write up I was looking for as this is the use case I've had in
mind for Racket of late after reading Felleisen's LOP paper.

Would love to know more about your experiences with doing Racket FFI. How hard
were the bugs around GC to discover and workaround? What were you building in
Racket?

~~~
pavpanchekha
See my responses to a sibling comment for Github bug reports. I had a great
experience with them: very fast triage and fixes, plus a lot of help
developing a workaround so we could target a range of Racket versions.
(Distros still ship some old versions!)

These bugs were found while working on Herbie
<[http://herbie.uwplse.org/>](http://herbie.uwplse.org/>). We use the FFI to
bind to your machine's math libraries so we can properly evaluate how accurate
a floating-point expression is on your machine.

------
lunchladydoris
Since we're talking about Racket, don't forget that it's RacketCon this
weekend: [https://con.racket-lang.org/](https://con.racket-lang.org/)

~~~
darkpuma
I hope this year it's videoed well. In past years except the last it's been
fine, but last year I'm guessing whoever normally does it wasn't available for
2018.

~~~
paroneayea
It's one person doing the recordings and has been the same the last few years
iiuc. They were just under-resourced I believe, and last year especially.
They're doing a damn good job given the constraints they've been putting
things together under I think.

------
regularfry
While I'm impressed with racket on the whole, I can't quite agree to be
impressed by the GUI bits. They're extremely limited, and once I got away from
"how do I put a button on the screen" I didn't find the underlying
implementation lent itself to being extended. In particular the drag and drop
system only goes as far as file drops, and I quite quickly hit a brick wall
trying to add anything more interesting.

~~~
copperx
Being inexperienced with modern Python, that leads me to ask, what's the story
with GUI work on Python? Are there any good libraries?

~~~
darkpuma
Tk from python is pretty damn convenient, being as it's always there. Not the
most modern toolkit for sure, but always being there is a pretty compelling
feature for some GUI projects.

~~~
aidenn0
FWIW, ubuntu python3 does not install Tk by default.

~~~
usbseeker
Don't use system python. Use a virtualenv and install your own python. I would
expect system python to only install what is needed.

~~~
JadeNB
I think aidenn0 was just replying to the claim that "it's always there".

------
inputcoffee
I am always confused when people talk about the language itself.

In my experience, python is used for Tensorflow, or Pandas, or Django, or
Flask, or pytorch or something else that runs on top of it. Sometimes it is
even more specialized and I need a wrapper for an API to let me talk to some
web data. Maybe I need a crawler/scraper and a parser. There is a specialized
language on top of the language.

So when someone says, oh this language is better with objects, or has some
syntax thing or the other, or I can reason about it I am left confused.

Its like if I were talking to a professional shoe designer and I ask for
hiking boots and they tell me that they're really into having at least two
tones to offset the lace and the heels or something.

What am I missing? I want to reason about the language too, but doesn't that
pale in comparison to being able to run a specialized library?

~~~
kazinator
You're missing that people write mountains of code in Python and similar
languages; they are not always just for a small amount of glue to gain access
to some specialized libraries.

~~~
inputcoffee
Well, I assume people write mountains of code in the library. If you're making
a machine learning product, that is still a lot of work.

However, writing your own Tensorflow interface would take several human
lifetimes to get it right, and Google already has provided it. So it seems
that is not the part you would re-write no matter how good the language is.

------
trurl
While I prefer my languages statically typed, if you're going to use a
dynamically typed language, Racket is far superior to Python.

~~~
paroneayea
Racket also supports several statically typed languages... look up Turnstile,
Typed Racket, and Hackett

~~~
pavpanchekha
I've found that Typed Racket is still fairly hard to use. For example, type
classes aren't there, and type polymorphism interacts poorly with general-
purpose functions like "equal?". I would guess that ML or Haskell code
translates fairly naturally, but there aren't the guide-rails those languages
have to keep you in the subset of the language that type-checks well.

~~~
spdegabrielle
Typed Racket has type classes: [https://docs.racket-lang.org/ts-
reference/Typed_Classes.html](https://docs.racket-lang.org/ts-
reference/Typed_Classes.html)

~~~
pavpanchekha
Uhh, sorry, I meant type classes in the Haskell sense (similar to interfaces),
not typed classes (like in Java).

------
F-0X
An _acceptable_ python!? More like Python is an unacceptable Racket.

Racket is an absolute joy to use.

------
sriharis
> "Lisp is too hard to learn" is a lie; if middle schoolers can learn it, so
> can more seasoned programmers.

Please, some famous, authoritative figure, say this out loud. I'm running out
of ideas to convince people of this.

~~~
tomp
Lisp, like Reverse Polish Notation, is definitively _not_ too hard to learn.

But, like Reverse Polish Notation, I don’t _want_ to use it.

------
leanthonyrn
What are the best library's for data science in Racket? -Finding it hard to
step away from Julia when operate on a amazing large data file and not kill
the CPU.

How about packages to convert Racket to WASM?

~~~
seisvelas
I'm a data engineer and avid Racketeer. Racket is not at all a satisfactory
replacement for Julia if you are doing data science. Specifically if you use
Flux, you should know deep learning tools are basically non-existent on
Racket. Someone once made a paper called DeepRacket and a Github repo, but it
hasn't been touched since.

If someone out there knows more than I do please let me know because I'd love
to be wrong. There is some decent linear algebra stuff, at least:
[https://docs.racket-lang.org/math/matrices.html](https://docs.racket-
lang.org/math/matrices.html)

Racket is both helped and harmed by it's popularity in certain academic
circles. Harmed, in that a lot of graduate students make a thesis of creating
some badass library in Racket only to completely abandon it. But I'm still
really rooting for Racket, it deserves more hype.

~~~
neilv
> _Racket is both helped and harmed by it 's popularity in certain academic
> circles._

Exactly, in a few ways. One way is that a number of Felleisen's original grad
students got professorships and kept doing systems research (and development)
with Racket. But most contributors who don't get professorships, nor the
handful of researcher jobs, end up working on other systems where the jobs
are, academic or industry. Industry use tends to be one-person projects, often
because you have a smart person doing something that can't be done with off-
the-shelf (e.g., Naughty Dog's video game narrative DSL, a think tank
researcher's work, some complicated data science server stuff that I worked
on, and various indie moonlighting projects), and so one-person efforts aren't
posting jobs. Bigger industry use would mean more contributors, but top
programmers are generally ill-equipped for enterprise sales, so I'd bet on
startup success stories to jumpstart greater popularity (even if you use
Racket to beta, and then whatever you figured out gets rewritten in a popular
commodity-worker platform).

------
thothamon
For my money, to be an acceptable Python, you have to be able to use the
Python numeric, scientific and machine learning libraries -- or have other
libraries that are just as good or better. That is the number one reason I
would use Python in the first place.

------
Y_Y
It would be remiss not to mention that it's (somewhat) possible to write
python in racket as a "hashlang"

[https://pkgs.racket-lang.org/package/python](https://pkgs.racket-
lang.org/package/python)

------
pera
Pyret is an even more acceptable Python:
[https://www.pyret.org/](https://www.pyret.org/)

~~~
skybrian
It's designed for teaching, but I don't think it runs anywhere other than in a
browser?

~~~
zem
it doesn't :( it would have been my instant new favourite scripting language
if it ran on the command line.

~~~
AlexeyBrin
Actually it does, you can run it from Node.js
[https://github.com/brownplt/pyret-lang](https://github.com/brownplt/pyret-
lang) and use it as a scripting language.

------
zmmmmm
> But I missed parentheses. I longed for parentheses. I dreamed in parentheses

I'm honestly kind of scared to ever learn a Lisp because it seems it
permanently alters your brain to the point where it damages your ability to
program in other languages (aka ones that you can responsibly use in an
organisation can't rely on niche skill sets).

~~~
darkpuma
My friend offered to grill me a hamburger last Saturday when we were hanging
out in his backyard, but I politely declined. His burgers look desirable, but
I explained my concern that tasting one of his burgers might permanently
diminish my appreciation of Big Macs. And besides, I can buy a big mac
anywhere in the world except north korea, so really that's a more pragmatic
preference.

Well I thought I was being diplomatic, but my friend just shook his head and
called me a moron. Can you believe the nerve of some people?

(I don't think Lisp damages your _ability_ to program in other languages. But
I do think it puts those other languages into context and that context often
makes other languages worse than they did before.)

~~~
ASoothingEbb
If I were forced to live in Plato's cave, I would rather have no knowledge of
anything outside of it.

Many people are locked into an ecosystem by, for example, employment. Why make
yourself less happy with the tools you need to use if doing so is for no other
benefit? Ignorance can be bliss.

~~~
memling
> Why make yourself less happy with the tools you need to use if doing so is
> for no other benefit? Ignorance can be bliss.

It teaches you how to think about problems in your specific domain more
critically, and perhaps more effectively, even if you can't directly translate
idioms into another language.

------
mx06v
It might be off-topic. I see there's racket in techempower framework
benchmarks [1] but I can't find racket from round 18 results [2], is it too
slow?

[1]
[https://github.com/TechEmpower/FrameworkBenchmarks/tree/mast...](https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/Racket)
[2]
[https://www.techempower.com/benchmarks/#section=data-r18](https://www.techempower.com/benchmarks/#section=data-r18)

------
mac_was
What is the purpose of Racket? Is there any use for web development?

~~~
tosh
I'd say Racket is a general purpose multi-paradigm language that is well
designed.

Good for use cases where you otherwise might find code written in JavaScript,
Python, Clojure or Ruby.

You can do web development with Racket [https://docs.racket-
lang.org/continue/](https://docs.racket-lang.org/continue/)

One thing that makes Racket somewhat special is that it can be used to build
your own languages (e.g. domain specific languages) with it as it comes with
the tools and a community that has experience in it.

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

There also is a great introduction to programming online course with Racket by
Gregor Kiczales [https://www.edx.org/course/how-code-simple-data-ubcx-
htc1x](https://www.edx.org/course/how-code-simple-data-ubcx-htc1x)

~~~
JadeNB
> There also is a great introduction to programming online course with Racket
> by Gregor Kiczales [https://www.edx.org/course/how-code-simple-data-ubcx-
> htc1x](https://www.edx.org/course/how-code-simple-data-ubcx-htc1x)

Probably anyone who would be interested knows it without its needing to be
pointed out, but I mention in case it entices anyone that Gregor Kiczales is
one of the authors of "The Art of the Meta-Object Protocol"
([https://www.amazon.com/Art-Metaobject-Protocol-Gregor-
Kiczal...](https://www.amazon.com/Art-Metaobject-Protocol-Gregor-
Kiczales/dp/0262610744) ; edited to remove abbreviation).

~~~
jimhefferon
> The art of the MOP

Please, what does that mean? I program in Racket, and have enjoyed the vidoes
but googling this phrase suggests either Prof Kiczales likes to clean floors
in an innovative way, or else he is a member of Hip-Hop group. I'm not finding
either terribly credible.

~~~
dreamcompiler
The MOP is the Meta Object Protocol, which is the meta-language for
controlling how CLOS operates internally. How exactly are classes,
inheritance, instances, slots, method dispatch, method combination, etc
implemented? In most object-oriented languages, you have very little insight
into these issues and certainly no control over them. In CLOS you have both,
thanks to the MOP. Just one more reason why CLOS is the most powerful OO
system ever devised.

------
nixpulvis
I'm quite glad my freshman material was in Racket and not Python. I'm sad to
hear some educational programs like MITs are moving the wrong direction here.

~~~
neilv
I think MIT people had their reasons for "rethinking" and trying out Java, and
then Python. One of the factors I recall was a perceived changing nature of CS
practice (moving to assembling from components, rather than
understanding&building from the ground up), but I can't properly represent all
of the rationales here.

Fortunately, the MIT SICP authors made the book freely available, so anyone
can continue to work through it, as a complement to our other learning
opportunities.

And Racket's `#lang` support is helping to keep the particular Scheme dialect
and library used by MIT SICP running on all the currently popular desktops
(Unixes, Macs, and Windows): [https://pkgs.racket-
lang.org/package/sicp](https://pkgs.racket-lang.org/package/sicp)

~~~
nikofeyn
> I think MIT people had their reasons for "rethinking" and trying out Java,
> and then Python. One of the factors I recall was a perceived changing nature
> of CS practice (moving to assembling from components, rather than
> understanding&building from the ground up), but I can't properly represent
> all of the rationales here.

i really don't fully understand their rationale. as i understand it, just at
the time that abelson and sussman grew tired of teaching the course, mit felt
the need to restructure their curriculum to meet modern demands and changes in
software engineering. of course, things have transitioned from building things
up to "poking", but i feel many of the principles of sicp remain unchanged.
but even ignoring that, i feel mit made a crucial mistake, in my opinion.

mit is a research and education institute. as a programming language, python
is not uniquely suitable for computer science research other than its machine
learning and data science library support. i feel it is also not suitable for
education either, especially not in the same way a lisp or scheme is. python
is what is given to you and thus makes it difficult to explore and implement
other paradigms of programming and other ideas in the same language like lisp
and scheme can do, and certainly not in the way racket can. now, right next
door to mit is northeastern, one of the major racket hubs. racket is a re-
envisioned scheme and programming language. it is very much suited to computer
science research, building languages for teaching and education (for example,
pyret was originally implemented as a racket language), and comes with plenty
of library support for general purpose programming. so other than having a
lack of libraries for machine learning, data science, and scientific
computing, it beats python in every category of comparison. and mit's own
language, julia, takes care of those missing components. there's no reason why
mit couldn't have developed libraries and teaching packages in racket for
their courses.

so imagine if mit had chosen racket as their language. that would bolster
racket development and popularity. it could have created a bridge between
northeastern and mit and would have taught racket to the thousands of mit
students and online students. it could have been a huge leap for racket in
terms of popularity and use. and mit could have grown to be an additional hub
for racket research and development right next door. and also, racket is an
evolution of the scheme language, which would have been a perfect segue from
the old curriculum.

but no, mit chose a language that was invented over a period of a couple weeks
by a stubborn guy who wanted to replace perl. i strongly suspect that there
were political and monetary reasons to choose python. and mit probably has a
chip on its shoulder, like it does with everything. mit has also become a
university driven by the need to raise money, and i think it has gone all in
on taking all the machine learning and "ai" money it can. that later point is
probably the real reason.

~~~
neilv
I agree that SICP is valuable, and years ago, I tried to help make it
accessible to people on low-powered computers [1], and to help preserve
software support for it [2].

I don't know all the rationale for MIT's moves to other things, but the
decision we can see seems plausible to me. (Python is a lingua franca at the
moment, popular in ML and data science, still somewhat popular in Web, and
very easy to pick up. Even language-nerd me wrote some production Python code
that moves large amounts of important data around.)

I agree that modern Scheme (perhaps starting with Racket) seems like a great
platform for much of CS-ish education, and for a lot of research and
development. I also agree that putting substantial MIT resources behind
building out Scheme/Racket seems like it would've been huge. Maybe that will
happen.

A lot of MIT behavior emerges from that of individual faculty members and
senior research staff, who have some degrees of autonomy. MIT has also prided
itself on being big on "experiments", and not having rules that might get in
the way of someone exploring ideas. If you have the opportunity, you can try
to use that to help make things happen.

[1] [https://www.neilvandyke.org/sicp-texi/](https://www.neilvandyke.org/sicp-
texi/)

[2] [https://pkgs.racket-lang.org/package/sicp](https://pkgs.racket-
lang.org/package/sicp)

------
taloft
If racket is an acceptable python and python is an acceptable lisp, then
racket must be an acceptable lisp?

~~~
hatmatrix
python's not an acceptable lisp - no metaprogramming; no macros

~~~
ZephyrP
He's making reference to Steve Yegge's riff on Eric Kidd's post, which kicked
off the whole "Are Xs acceptable Ys" blogpost template.

------
nimmer
I find Nim to be much closer to a statically typed Python - with the speed of
C.

~~~
treeofwife
Not really sure how this is relevant here, judging by your post history and
username you seem to have a one track mind...

Maybe if you provided some examples of how Nim compares to Python or Racket,
weighing the pros and cons, etc, I wouldn't assume you're only here to shill
Nim.

Edit: Anyone care to explain why my post is flagged and the parent comment
isn't? I would like to keep the discussion on topic...I didn't think I was
being too harsh.

~~~
dang
Your comment broke several of the site guidelines. That's why comments get
flagged here. Would you mind reviewing them and sticking to the rules when
posting to HN?

[https://news.ycombinator.com/newsguidelines.html](https://news.ycombinator.com/newsguidelines.html)

------
charlieflowers
Say your task was to read metadata about rest api endpoints and generate an
sdk in c#.

Would racket’s LOP features make it compelling? Or would you be more inclined
to build it in c# since that is the target language?

------
nafizh
How is the scientific computing/machine learning ecosystem for Racket? Looking
for suggestion from people who are experienced.

------
nickmain
Python runs on iOS, Racket does not. The need for a JIT to make Racket
performant also makes it unlikely that it ever will.

~~~
darkpuma
If you want a _lisp on mobile_ kick, I've heard good things about
lambdanative. It would still be cool to have racket mobile apps though.

~~~
mark_l_watson
I have only looked at the code and built the demos for lambdanative, but from
what I have seen if I had to write mobile apps then I would seriously consider
it. It is built in the excellent Gambit Scheme.

