Perchance to Scheme (2016)
hardmath123.github.io
hardmath123.github.io
The greatest strength of Racket is its documentation. Secondly the way Racket actually teaches you how to be a better programmer. I personally grew the most due to "How to Design Programs" https://htdp.org/2018-01-06/Book/ Third the executables for cross platform is its reason why I use Racket at work. I can make it and create an executable with raco.
I feel like Racket is the most general purpose language I have ever used. I grew up on C64 Assembly, Pascal and Forth. When I learned Python I felt like I could do anything. That was until I wanted my Python code to be used on a computer that wasn't my own computer.
Python was my go to language for everything at work but I ended up moving to R about 6 years ago. I felt my R was rough around the edges and picked up Racket to learn about R's Scheme roots. It was a night and day difference. I have several pet programs that saves me hours every week.
My Racket programs are much more readible than my Python Scripts. The libraries are certainly not all there but it is actually easy and fun to create your own implementations in Racket and a library for your own use.
As an academic, it makes me very sad to hear these qualities, that I feel describe my work, used as the opposite of 'academic'.
Agreed!—but the use of the term 'academic' in this way suggests it's a universal experience. (I've never heard anyone use 'academic' to mean exciting and invigourating intellectual exploration!) I don't argue with it, as I know that's the way language goes; it just makes me sad, and, I imagine, shapes the expectations, and then to some extent even the experiences, of my students.
Define - Academic
1. c: very learned but inexperienced in practical matters 1. d: based on formal study especially at an institution of higher learning 3. a: theoretical, speculative 3. b: having no practical or useful significance
https://www.merriam-webster.com/dictionary/academic
Couldn't find a positive way to spin Academic as used by the article.
For anyone who doesn't know - a big difference that Common Lisp brings to the table is that it has separate namespaces for variables and functions. This may not sound like much but it makes it much easier to write macros (code that writes code) and facilitates compile-time computing.
Another big difference between Scheme and Common Lisp is that the Common Lisp specification is _much_ larger and it comes with a much larger collection of standard built-in functions and macros and a standard object-oriented programming facility, among many other things.
I know this because I've spent the last six years implementing Clasp (github.com/clasp-developers/clasp) - a Common Lisp that interoperates with C++ and uses LLVM as the backend. There are several excellent implementations of Common Lisp - Steel Bank Common Lisp is a great place to start.
A little more detail here: it has a lot more namespaces than that. Indeed, you can attach arbitrary different namespaces of things to symbols if you want to.
It turns out that when you're writing macros in Lisp, the majority of what you use from outside the macro are functions and the majority of symbols that you bind and use within the macro are variables, so if you put them in different namespaces, you get rid of the majority of cases where symbols don't do what you were expecting in a macro.
Now, it's not quite all of the cases, and when it does happen, it's a pain to track down. Which is why the Scheme folks spent the effort and complexity on hygienic macros (where the system rewrites all symbols internally to make variable capture impossible). At the time of Common Lisp's creation, multiple namespaces and unhygienic macros were the obvious choice for production code, since there weren't hygienic systems available. Today you can go either way. In terms of research, hygienic is the route to go, as the work over the last couple of years on strongly typed, hygienic systems has shown.
And I don't think the function/value split is even the most important namespacing it does with regards to macro hygiene ("functions are less likely to be shadowed" always struck me as a kind of weak argument). Symbols being namespaced under packages is a much more robust solution:
CL-USER> (defmacro m (x) `(car ,x))
M
CL-USER> (defpackage :p)
#<PACKAGE "P">
CL-USER> (in-package :p)
#<COMMON-LISP:PACKAGE "P">
P> (cl:macroexpand '(cl-user::m x))
(COMMON-LISP:CAR X)
CL:CAR isn't accessible in P, so (car x) by itself would signal
UNDEFINED-FUNCTION, but the macro works correctly. Defining a P::CAR function
wouldn't change anything.That isn't just for functions, either, eg if you do:
(defmacro awhen (pred &body body)
`(let ((it ,pred))
(when it ,@body)))
(where you want to leak IT), and then import AWHEN but not IT, you'll get an
error that YOUR-PACKAGE::IT isn't bound to anything when you try to use it; it
doesn't matter that AWHEN-PACKAGE:IT is bound.I don't disagree with anything you said, I just think it made CL macros look flimsier than they are.
Even if I'm in my own package, I can't do this:
(flet ((car (x) ...)))
(m arg))
because in order to have a hassle-free Lisp coding experience in my package, I brought in all the public symbols from the common-lisp package. So my flet is in fact shadowing cl:car.Even if I just import the specific common-lisp things I need, and car is not one of them, that could change. Today, that car above is mypkg:car. Tomorrow, someone edits the defpackage to import car (because they needed it in a function they added), and now when that file is re-read, car is cl:car.
Packages have a theoretical solution to the hygiene problem that will not be air-tight in practice due to use/importation.
Another problem is that programmers aren't going to define a large number of packages to protects parts of their program from each other. A common practice is just to make one package for an entire project.
You need fine-grained package use to achieve near perfect hygiene. Ideally, each module that provides macros should have its own package, and use only symbols from that package in the macro expansion. If module A uses a macro from package B, and that macro generates a local function F, that will be B::F, not interfering with the A::F function. If the modules are in the same master project package, the clash is not averted, obviously.
Isn't this a non-issue in scheme as it has hygienic macros?
Note: my only exposition to lisp is via elisp, so I might not know what I'm talking about.
Hygiene solves the issue of namespacing macros, but at the cost of a very complex implementation. Implementing hygiene is HARD and I don't think it can even be called a solved problem. The current systems have issues that have proven to be hard to resolve.
[1] as opposed to the alledged 'worse is better' of the unix world.
far from it. CLers know that Scheme has zillions of different macro systems. Which makes the whole topic highly confusing and intellectually interesting.
I understand the complaint that this isn't portable. It isn't. R6RS tried to standardise it. Hopefully r7rs does better in that regard.
or the equivalent of Lisp's DEFMACRO. There are tons of options. But it's a bit disappointing that such a central feature hasn't found acceptance of a main solution in the Scheme world. R7RS small has only syntax-rules AFAIK, and something like syntax-case is planned (?) for the R7RS large (which does not yet exist, AFAIK). It's not even clear to me whether 'syntax-case' is universally seen as 'solved problem'.
Anyone who has a basic idea of Scheme should know that syntax-rules is not the only option - a short look into a manual of an existing Scheme implementation should be sufficient...
R6RS standardised syntax-case, so any r6rs scheme already has it, but due to many things r6rs was a huge controversy and many implementations never started using it. Guile, chez, racket, Kawa, jscheme, larceny all support it. I expect syntax case in one form or another to make it into r7rs large, but you never know. Lots of cool things are making its way into r7rs large, including HAMT-based maps. There must of course be a vote, but that is just too good to not have :)
What CL brings over scheme is a fantastic object system. The Scheme copies are half-assed in comparison, especially considering how well-integrated CLOS is.
Maybe I don't understand what the alternative is when you want to write client side code for the browser - js?? I use Clojurescript and find clear benefits.
By way of example I often found the general setTimeout functionality to be a nightmare for scheduling delays. Most of the time it works, but periodically I find it blocks or fails (via a dependancy chain) and then have to spend time arranging code abnormally to mitigate. In clojurescipt I use core async.
(defn timeout [ms]
(let [c (async/chan)]
(js/setTimeout (fn [] (async/close! c)) ms)
c))
Never looked back. Never had a delay problem - Ever.cljs core.async and many other features have made it so much more enjoyable to write client side code. Don't even get me started on callbacks.
> Oh, and one last thing. I feel it’s obligatory at this point for me to say, please don’t spend too much time researching Scheme dialects. Just pick Racket and start coding
I've had the opposite experience so thanks, but no thanks.
I moved on to Clojure.
Implementing a language that resembles Scheme is quite easy. Implementing call-with-current-continuation and hygienic macros AND getting the tricky little details correct is not.[0] An analogy might be someone offering "ability to write SQL" for their fly-by-night database without stating up front that joins are not supported.
[0] Old test suite run against old Schemes: http://sisc-scheme.org/r5rs_pitfall.php
(tangential) and this is where most "build your own compiler" style books fall down.
They teach you to implement ultra simple languages, but don't tackle memory management/garbage collection, concurrency, production grade typecheckers, and for lisplikes, macro systems, etc.
Have a look at http://t3x.org/s9book - it covers a Scheme implementation including GC, call/cc, low-level macros, type checking, tail call elimination, etc.
Hygienic macros are not hard to implement [1]. I can't speak to the efficiency of my implementation though.
[0] https://www.goodreads.com/book/show/1168500.LISP_in_Small_Pi...
[1] https://github.com/eatonphil/bsdscheme/blob/master/examples/...
Hygienic macros are however never trivial. It is so many kinds of tricky, and together with the nice debugability of macros you find yourself in a nice place.
http://blog.racket-lang.org/2018/01/racket-on-chez-status.ht...
1) Gambit. Compiles to C. Interesting tools built on top are Termite (Erlang-like concurrency framework) and Lambdanative
2) TinyScheme - super minimalist embeddable scheme.
3) Kawa Scheme - on JVM. Much smaller and faster than Clojure when I used it last.
4) Bigloo - can compile to C & Java bytecode.
Note ChezScheme is now open source and has very good documentation.
There was a port of one of PicoBit predecessors, Bit Scheme, to the XMOS architecture, with realtime GC and support for the native XMOS features http://soft.vub.ac.be/~cderoove/publications/master_thesis_r...
Hell no. The linked website, http://wiki.c2.com/?LispSchemeDifferences lists differences between Common Lisp and Scheme. Clojure is not a Common Lisp implementation.
Generally Clojure has very little in common with LISP dialects, besides some concepts. It has no linked lists, almost no functions are the same, almost no macros are the same, no special forms are the same, similar named operators often do something different, ... Think ATOM, CONS, CAR, CDR, APPEND, SETQ, NULL, DOLIST, DOTIMES, ... basically the original core of LISP is not present in Clojure. Literally no Clojure code runs in LISP dialects and no LISP code runs in Clojure dialects -> without completely rewriting it. Some Scheme ran in LISP - with more or less effort to do so. Nowadays that's not very common.
Clojure may in abstract terms be a LISP dialect, but the expectation that anything from LISP can be applied directly to Clojure is not the case. You can't take any LISP book and execute the examples in Clojure , nor would it make much sense.
It's opinionated in a good way (IMHO).
[1]. https://cons.io/
(define lst '(4 5 6))
(set! (car lst) 3)
(display (car lst))
;; 3
That's a pretty serious semantic departure. It's at least as different from RnRS as Racket, which insists it is not Scheme.See here: 'is a branch of GNU Emacs that replaces Emacs’s own EmacsLisp engine with the Elisp compiler of Guile.'
The word is 'ENGINE'. That's the underlying language runtime.
It's neither GNU Emacs right now, nor will Emacs Lisp be replaced.
Smalltalk wound up being quite loosely specified. This, combined with the small "core," enabling single developers rolling their own, resulted in a high degree of fragmentation of the overall language community.
Odd thing to call RnRS Scheme loosely specified. The RnRS spec is extremely well-written - and it even includes a semantics.
Now "Scheme" used to mean "a Scheme like language" is of course loosely specified - but that's another story.
Are there any R6RS-conformant Schemes that are recommended?
> Oh, and one last thing. I feel it’s obligatory at this point for me to say, please don’t spend too much time researching Scheme dialects. Just pick Racket and start coding.
It actually compiles to C and then to binaries for your specific platform.
Check it out: https://www.call-cc.org/