Racket is 25
blog.racket-lang.org
blog.racket-lang.org
Even a simple thing like concatenation of two lists, that in Prolog it could be done purely declaratively, without expressing how it needs to be performed, seems levels more magical than how it is done in lisps.
Not to argue with the claim—Prolog does feel magic sometimes—and maybe I'm not sufficiently idiomatic in Prolog, but I would express them similarly: something like
concat([], Bs, Bs).
concat([A|As], Bs, [A|Cs]) :- concat(As, Bs, Cs).
I don't have Lisp code at my fingertips, but that's quite like how I'd do it in Haskell: concat [] bs = bs
concat (a:as) bs = a:(concat as bs)
(I just looked up a Scheme primer to refresh myself, and I think there I'd do (define (concat as bs)
(if (null? as)
bs
(cons (car as) (concat (cdr as) bs))))
… but don't hold me to it. Certainly not using pattern matching makes the Scheme more verbose, but I think the algorithms are the same.)Is one of these an un-idiomatic way to do it? (If you downvote, of course that's your right, but I'm not being sarcastic or dismissive; I really would like to know, as not a professional programmer in or fluent speaker of any of these languages, if I'm not writing idiomatically, so I'd be grateful if the downvote came with a comment!)
[eclipse 2]: concat(A,[_,_],[0,1,2,3,4]).
A = [0, 1, 2]
Yes (0.00s cpu, solution 1, maybe more) ? ;
No (0.00s cpu)
Or iterate over all lists that concatenate as [0,1,2] [eclipse 3]: concat(A,B,[0,1,2]).
A = []
B = [0, 1, 2]
Yes (0.00s cpu, solution 1, maybe more) ? ;
A = [0]
B = [1, 2]
Yes (0.00s cpu, solution 2, maybe more) ? ;
A = [0, 1]
B = [2]
Yes (0.00s cpu, solution 3, maybe more) ? ;
A = [0, 1, 2]
B = []
Yes (0.00s cpu, solution 4)- The head function (with X unknown and L known): concat([X],_,L).
- Produce all splits of a list (with X and Y unknown): concat(X,Y,L).
- Does this list start with the prefix [a,b]? If yes, let Y be the tail (Y unknown): concat([a,b],Y,L).
... and many more.
From my functional/imperative programming experience, when originally picking up Prolog, I conceptualized the kind of operations you describe (e.g., “all splits”) as “running the function backwards” — going from output L to inputs X, Y.
But as you write, the truth is that Prolog is modeling the relation of concatenation.
I think the Scheme version might be considered unidiomatic due to the inefficiency: because it's not tail recursive, you're building a huge stack of cons calls (whose depth is the length of `as`) which only resolve once you reach the end of `as`.
On the other hand, the version with accumulator would need to traverse as and bs in full, twice (once for the accumulation and once for the terminal reverse).
> At the same time, recursion does not lead to particularly
> bad performance in Racket, and there is no such thing as
> stack overflow; you can run out of memory if a computation
> involves too much context, but exhausting memory typically
> requires orders of magnitude deeper recursion than would
> trigger a stack overflow in other languages. These
> considerations, combined with the fact that tail-recursive
> programs automatically run the same as a loop, lead Racket
> programmers to embrace recursive forms rather than avoid
> them.
https://docs.racket-lang.org/guide/Lists__Iteration__and_Rec...AFAIK the Scheme standard doesn't specify either behaviour. So, with regards to the standard both Racket and other Scheme implementations are free to implement this in whichever way they prefer. And the Scheme implementations that I'm using (Gambit-C, Chicken and Guile) all work the same as Racket. I only know of Bigloo (of about 10 years ago, maybe it changed?) as a Scheme implementation that uses the machine stack to implement Scheme continuation frames, and Bigloo (again back then) doesn't (didn't?) implement call/cc efficiently either. Arguably to implement the Scheme standard including call/cc efficiently the machine stack can't be used, thus any 'proper' Scheme implementation will behave like Racket.
I've written lots of non-Racket Scheme code and my code always assumes that it won't run out of stack before running out of heap. Some Scheme implementations allocate stack frames more efficiently than cons cells thus the straight-forward solution (recursion, not iteration then reversion) is also the more efficient one.
There is a tendency of claiming Racket is somehow fundamentally different from Scheme which sometimes feels a bit like a racket. I'm not opposed to Racket but think it would be better to take it as what it is, Scheme plus extensions and tooling, which most other Scheme implementations are as well. Racket may be doing that more extensively but I think it calling itself a different language should primarily be understood as a marketing ploy, or maybe as a move to justify moving ahead with own ideas without caring about the rest of the Scheme community.
It is difficult to use the machine stack and have a fast call/cc. But I think Chez Scheme proves it's possible.
If you want to have code work everywhere and thus code defensively, yes. Of course you're not coding defensively when coding for Racket, either. But I guess I may have misunderstood you--Racket simply gives you a guarantee; as do some (other) Scheme implementations, so you get the same benefit with some/many other Scheme implementations as well--but even those "differ from Scheme (the standard)", by giving such a guarantee outside of the standard. It's not "Racket vs. Scheme implementations", it's "the (Racket|Scheme) implementations vs. Scheme (the standard)". Apologies then for my inappropriate rant about false claims.
> It is difficult to use the machine stack and have a fast call/cc. But I think Chez Scheme proves it's possible.
Chez doesn't seem to be using the machine stack either. I've tested with this code and "ulimit -s 1000" on Linux and it runs fine:
(define (conc a b)
(if (null? a)
b
(cons (car a)
(conc (cdr a) b))))
(define (iot n)
(if (negative? n)
'()
(cons n (iot (- n 1)))))
(display (length (conc (iot 10000000) (iot 10000000))))
(newline)
Note that it can still be using a stack built from "machine" or C style arrays as building blocks--that's what I meant with "Some Scheme implementations allocate stack frames more efficiently than cons cells". Gambit falls into this category as well. But you can't have a single uninterrupted C style array as the stack (with no copying during GC like Chicken does) and implement call/cc efficiently. So I'd still say that implementing Scheme including call/cc efficiently means moving away from the stack controlled by ulimit -s, and once that is done it's easy/natural for an implementation to also offer unbounded stacks like Racket does.I don't know whether Chez still uses the same strategy, but a major part of Dybvig's thesis (very readable) was dedicated to explain the details of a possible implementation strategy.
(define (concast as bs)
(match as
['() bs]
[(cons a as) (cons a (concat as bs))]))https://mitpress.mit.edu/books/reasoned-schemer-second-editi...
Racket and Perl 6 are the only small userbase languages in the last 8-10 years to amaze me with their feature sets and to make me want to learn them just for the sake of experiencing them.
> A logic programming library for Clojure & ClojureScript. core.logic offers Prolog-like relational programming, constraint logic programming, and nominal logic programming for Clojure.
Minikanren seems to be closer to the mark, and I thank the commenters who pointed it out!
That is, saying that minikanren seems to be closer to the mark than core.logic is a little bit nonsensical (please read that in a good sense!)
I don't want to do logic programming in clojure (or whatever other language), I want to do logic programming in Prolog and drop it into my clojure project and have to do as little plumbing as possible.
The nearest analogy I can come up with is LINQ. In the examples in [1] the experience of the developer is closer to writing SQL in the middle of a C# or VB file, rather than having a good C# database query library.
[1] https://docs.microsoft.com/en-us/dotnet/csharp/programming-g...
That's super common, both as bridges to Prolog systems from other host languages and as implementations of Prolog semantics (or a subset like Datalog) as libraries in other host languages; also MiniKanren is available for many host languages.
Ain't that the truth. Scheme/Racket, ML and other primarily academic functional languages are fun, but rarely used in business/industry. It's great for learning programming language ideas like scope, thunks, closures, etc but very little opportunity beyond that. But maybe that's why it was a joy to program with racket. No pressure to create anything practical with it. Just tinker and learn using it.
I still need to pick up SICP again :)
Racket produces standalone applications that can be codesigned using Apple's tools, in preparation for their App Store.
Best regards to the Racket team.
Can you elaborate on how this works? I've been wanting to try something similar.
Build an application, unpack the .dmg file, add my own data files, create a new subdirectory with same name and move all files into it, discard the dmg, use Disk Utility to build a new .dmg and sign it:
codesign --force --deep --options runtime -s mark@mydomain.com -v New.dmg
Note: my app had required data files, which complicated the process.
https://github.com/cjdev/aws-access/blob/master/Makefile#L26
The manifest file used is here:
https://github.com/cjdev/aws-access/blob/master/dmg.json
It’s a bit annoying because it requires having a working node installation, but I found the whole process of building and configuring a dmg much too manual and undocumented to not use some kind of utility for.
Could you give a quick overview of the reasoning behind your final decision?
I usually recommend Racket when someone, at least right now, wants to learn Lisp. Racket is an effective gateway drug to the Lisp world :-)
They offer the full development experience as having your own Lisp Machine, with optimizing compilers, IDE, frameworks, debugging tools.
Racket is nice and all that, but the commercial CLs are just that: commercial, aimed at people writing large programs with very high demands.
Anecdote: I once hit a weird bug when trying to get a very old CL program running. Nothing big, but once in a blue moon I would get the wrong result. I spent 3 days banging my head angainst it, trying to find a way to trigger it reliably. I inspected the live environment, did print-debigging. A friend encountered the same bug when running the program in Allegro CL and managed to debug it within minutes.
Does anyone have recommendations of how to learn to think recursively? Sure, using the language more and more does it, but what about a more general recursion as a problem solving paradigm pattern? I'm enjoying doing recursive code exercises and got into Backtracking problems. Creating things like Sudoku solvers, Knight's Tour grid etc was quite fun. I still can't develop recurrences easily though.
Any books/exercises that people here found helpful?
https://eprints.soton.ac.uk/254242/1/p_by_numbers.pdf
And the "The Little Schemer" book has a series of exercises that expose recursive thinking:
https://www.amazon.com/Little-Schemer-Daniel-P-Friedman/dp/0...
Hope this helps!
1: https://en.wikipedia.org/wiki/Essentials_of_Programming_Lang...
also, the coursera course programming languages by dan grossman is an excellent course on doing things recursively. in part a, you learn sml, and in part b, you learn racket and build a simple interpreter.
Thanks all for the suggestions! :)
* avoid the iteration constructs that Racket added to Scheme,
* avoid mutating operations, such as `set!` and those that operate on mutable data types,
* embrace named-`let` for iteration/recursion (using `let` with a name, like `(let loop-for-foo (` rather than `(let (`, which effectively makes it like an embedded function that can be called from within its own definition), and
* embrace immutable data for collections, like immutable pairs and immutable hashes.
You can do that for real-world development, or for interview-oriented Leetcode-type exercises. Whichever motivates one more; with the above suggestions, both will present many opportunities to practice recursion this way, without exercises that are selected or contrived to need recursion.
I think that situation is unfortunate for some aspects of learning, whether or not the compiler can make some use cases of the constract just as fast (or faster).
Edit: the loops actually got more powerful recently: The for/foldr was a great addition where you can replace most non-tail-recursive functions with it, even though I probably wouldn't use it for tree transversal :)
But Clojure is also built on top of immutable data structure, recursion and more, but also provides features for mutation of various things, both for pragmatism and sometimes performance. Clojure also lives like a hosted language (on top of JVM/browser engines/more), most of them being mutable by default, so providing those constructs help with interop as well.
Racket slowly added some immutable data types to Scheme, which was a nice fit for some other Scheme features that had been there from the start, and better for software engineering (e.g., enforce that a user of a module couldn't go and mutate data you were sharing with them).
In the past 25 years, I think we've seen quite clearly that programming language popularity depends on many different factors, and "quality of he underlying paradigm" is way down on that list -- if it's even a factor at all.
Just a quick glance at any list of most-used-languages will tell you that 50% of popularity is "is it being pushed by a big company?", and 25% is "is it the primary interface for a popular platform?"
Take away those two factors and there's maybe only about 3 languages left in the top 25 (Python, Ruby, PHP?).
Where quality shines is in being able to stay a viable niche for a long period of time. That's Scheme.
- Supporting higher order functions in programming languages. Check.
- Usual operations on higher-order functions like currying? Check.
- Functional reactive programming. Check. Rx was a big thing a few years ago.
- Purely functional data structures. Check. Even Java has a few reasonably popular libraries that support such data structures.
- Using referential transparency whenever we can. Check.
- Using CPS (continuation-passing style) in daily programming. Check.
- Using recursion in production. This is not functional programming per se, but given that so many people mention recursion whenever they mention functional programming, it's worth listing recursion here. And mutual recursion and tail recursion, two of the hallmarks of entry-level functional programming techniques? Check and check. For instance, RxJava implements trampoline just to support tail-recursion, as it is necessary to implement cleanly some of RxJava's operators.
- Common techniques seen in functional programming, particularly the ones that involve map, reduce, scan, left-fold and right-fold. Check.
This is just the items that are on top of my mind. I'm sure I missed plenty. The gist is that people have been adopting functional programming. They just don't necessarily move to a purely functional programming language for practical reasons: platform, support, community, ecosystems, or even marketing. Programming paradigm is just one factor among many when people choose their programming languages.
A CPS transform for a computation of type `X` gives a computation of type `forall A. (X -> A) -> A`. That is, instead of evaluating to ("returning") a value of type `X`, you take a function that you deliver a valid of type `X` to, and return whatever it returns.
CPS-transforming a sum type `X + Y` gives `forall A. (X + Y -> A) -> A`, and if you distribute over the sum you get `forall A. ((X -> A) * (Y -> A)) -> A`. The visitor is the pair of functions you pass in, `(X -> A) * (Y -> A)`, and the value decides which method to call. In either event, it returns whatever the chosen visitor method returns.
(Dropping into Java syntax, this is the type of the `visit` method: `<A> A visit(Visitor<A> visitor)` -- and the Visitor is `interface Visitor<A> { A onX(X x); A onY(Y y); }`.)
The only ones I can think of are Java and C#, which are very big languages, but combined they're dwarfed by these languages, which follow the second rule:
C (Unix), C++ (compatible with C), JavaScript (browser), Objective C (OS X and iOS), Kotlin (Android), bash (first program to run on the Linux kernel)
Java is a primary interface to the Android platform (2008). When it was originally made decades ago (1996), it was supposed to be the first language for cross platform development (compile once run anywhere), it may not be one platform per se but it is equivalent in a way.
So basically the point is that the first reason is a special case of the second... Marketing alone does a little bit for a language, but having the platform is more important.
People choose platforms and not languages. Big companies are the ones that own platforms (Linux being an exception).
I don't recall Solaris ever being any significant, so must have been a good argument that Java could run on the many Unix/Linux variants besides Solaris.
I learned Unix and C on a SparcStation, and to this day I prefer workstations to other computers.
Even if Apple is the only one still making them...
But I'll try to answer anyway: Go. Dart. Maybe Rust (depending on whether nonprofits count). Delphi. All of these are in the TIOBE top 25 today.
Furthermore, languages like Kotlin, Swift, and C# became a primary interface to their respective platforms, but didn't necessarily start out that way. They got popular, and then became first-class platform citizens. It may have been the plan for them to eventually become that from the start, but I would claim they would have become popular even without the platform. So I put them in the first group.
You can write Windows programs in C# today, and many developers do, but I bet even more are using it for web development. And in a popularity contest (Zipf's Law), losing even half of your fans won't change your list position much.
Delphi was pushed by Borland, the InteliJ from the 90's, everyone doing indie development on MS-DOS and Windows early days was using Borland compilers, not Microsoft's.
Most Web development with C# is done on Windows anyway.
Ruby only has some popularity in the silicon valley. Never heard of companies really adopting Ruby outside of there. It's open to debate whether it can qualify as one of the popular languages.
Early on its key feature was easy hosting, there were a lot of shared host sites where using anything other than PHP or maybe a bit of Perl was difficult.
The "LAMP platform" is defined by the set of people using PHP/Perl, so I wouldn't call it "pushed" by that. It's not the native platform of Linux, Apache, MySQL, or the web, and there wasn't exactly any big company pushing it (Facebook famously uses it but it had already cemented its popularity by then).
Nobody (hyperbole) gives a damn about math, even though they'll all end up using the very same ideas in mainstream clothing.
It might not be obvious to half the dev crowd but most thing they're talking about since 5 years is basically 80s academic FP. Destruct, patterns, lambdas, folds ..
- Cantor: smh
PHP do have its great niche.
Namely it's the only programming language where whole ecosystem lives and dies by the "build and burn the whole world on each request" mantra. It have significant advantages compared to other models of computation. (Granted even PHP devs often misplace "developer friendliness" of PHP, so you are not alone ;))
If the tool lives on beyond prototype then I have to rewrite it in a native language or restrict it to the subset of Scheme that can run in Gambit on iOS.
I really hope that Racket can evolve and adapt to a world where more computing and even development is going to happen on mobile and web.
I suspect Racket would be a lot more popular as a development environment if the team did away with Dr Racket and put those resources into maintaining a very solid Emacs, Vim and VS Code integration.
Magic racket is very bare bones and can't compare to integrations like Calva [3].
So I saw someone down voted me... just to be clear, I use Racket despite having to work against a poor tooling experience, when comparing to say, CL or Clojure.
I want Racket to succeed in industry, so is not like I'm complaining. I'm pointing out what I think is a weakness, maybe a blind spot by the team, since they seem to be very attached to Dr Racket!
My point is that would be ideal if the core Racket team also participated in polishing the IDE integrations, other than Dr Racket.
1: https://www.greghendershott.com/2019/07/future-of-racket.htm...
On the third hand, I spent all that time, so wrt "bus factor 1", there will be no pleasing you. :)
Thanks for all your work on the racket ecosystem!
But on the other hand, many things from DrRacket can be reused as modules in the language server, so the work that goes into it is not “lost” for the ones that don’t use it directly.
Also, what’s the biggest feature you miss from Magic Racket (and the language server by extension)? As far as I’m aware, the language server project doesn’t have a fixed set of goals and it grows rather organically. Maybe they would make use of this kind of feedback.
Should MR work fine with other langs? I don't think it is stated on the docs anywhere if this is a supported feature. For instance, if I open a .scm (Scheme) file, Ctrl-P to switch to lang (MR mode) and launch a REPL, is it supposed to work fine?
what i was thinking of is most languages. having used various ides for python, elixir, and f#, i have been rather unimpressed with IDE offerings from these languages. dr. racket is indeed nice and easy to use but is rather frustratingly un-performant. clojure's IDEs look so nice and clojure is very enticing, but i just don't want to live on the jvm and in java land.
Just download the 'Minimal Racket' build instead. ~10MB instead of 100+
> I suspect Racket would be a lot more popular as a development environment if the team did away with Dr Racket and put those resources into maintaining a very solid Emacs, Vim and VS Code integration.
I think racket/gui would suffer if they stopped working on Dr Racket, which would be a shame.
I wish either Racket was more widely used in industry or I had more time/energy/excuses to use it.
Looking forward to Racket CS as main implementation.
The talks done by the Racket team are always interesting to watch.
Though Racket was not created for that purpose, it's unsurprising that many others from that era were linked to the Web.
Probably the best way to think about the two of them is that Clojure is a focused language design, and the assumption is that you stay in the language and extend it with macros. Racket is an environment for generating languages. The assumption is that you will build language variants to do various tasks.
The big customer of my consulting business (public sector) did amazing "force multiplier" things with Racket and my help, even when many general-purpose libraries had to be built in-house. But there were virtually no other prospective clients in that niche after over a decade.
There are a few organizations who use Racket to great production effect. But two problems for consulting&employment for those:
* Their generally one-person teams could usually do everything that's needed, and perhaps some developers prefer that;
* When they would like additional help, they generally didn't have the money/authority to pay HCOLA developers.
I tried half-heartedly for a few years to promote the idea of doing one's startup prototype with Racket. But the browser-side and iOS&Android app stories aren't there yet. And my own startup, I self-funded too long before my co-founder and I realized we should've found a CEO to court funding months earlier.
The startup where I currently lead engineering uses (for historical reasons) Python for server backend and for device interfacing on a light embedded system, and framework-like JS on one frontend, and interfaces with a SaaS for a different frontend. All the Python bits could've been done in Racket, and Racket would've been more productive and fun to work with, but it's not worth rewriting at this time. I recently prototyped a new embedded system frontend in Kivy, and was able to get a running GUI mockup nice in a few hours, but realized afterwards it would've been better with Racket's GUI toolkit.
When I recently had to pick a method to do an iOS app that wasn't consumer-facing, I was tempted to use Gambit Scheme. But I decided on Swift and SwiftUI, to be safe, and so we'd have more experience with it for the next iOS app (consumer-facing, for a high-quality/prestige brand) that was more likely to need a more-native toolkit and APIs.
That said, if someday I have a startup that uses Racket or another Scheme (or another fringe platform), I expect the platform appeal to help me attract a larger pool of higher-powered developers than I otherwise could.
If you're considering using Racket for making money, one start is to participate in this low-traffic email list (which has some unusual conventions): https://www.neilvandyke.org/racket-money/
Some of the more famous cases are game development for PS4, specifically Uncharted series and related from Naughty Dog studio. Some other places also do internal tooling in it (including John Carmack at Oculus)
A Call by Need Lambda Calculus.
Zena Ariola, Matthias Felleisen, John Maraist, Martin Odersky, and Philip Wadler. 22'nd Symposium on Principles of Programming Languages, ACM Press, San Francisco, California, January 1995.
There is a humorous story about how the paper and collaboration came about, which Felleisen discusses in an interview [1].
[1] —> https://www.cs.cmu.edu/~popl-interviews/felleisen.html