
Gerbil – An opinionated dialect of Scheme designed for systems programming - cmpitg
https://github.com/vyzo/gerbil
======
xfer
Here is some context on Racket vs Gerbil by a well-known Common-lisp
Programmer, François-René Rideau :
[https://fare.livejournal.com/188429.html](https://fare.livejournal.com/188429.html)

~~~
e12e
Some excellent comments there.

Looking around a bit, I came across a couple of implementations that might be
of interest for those wanting to mash up "some kind of system programming" and
"scheme": Bigloo (interpret / compile to executables, java byte code or
experimentally dot.net) and larceny (interpret / direct compile to machine
code / optionally via c):

[http://www-sop.inria.fr/mimosa/fp/Bigloo/](http://www-
sop.inria.fr/mimosa/fp/Bigloo/)

[http://www.larcenists.org/](http://www.larcenists.org/)

~~~
cat199
Chicken Scheme

[https://www.call-cc.org/](https://www.call-cc.org/)

is another good one - compiles to binary, many libraries (eggs)

~~~
ClFromEmacs
And can't compete in speed. But does have more libraries.

------
kovrik
Can anyone explain why there are so many implementations of Scheme written in
Scheme? What is the point of doing that (apart from learning purposes)?

I know, for example that people want Racket VM to be implemented in Chez
Scheme because Chez is super fast. But what about all other implementations?

Also, as I'm currently writing R5RS/Clojure hybrid in Kotlin, can anyone
please share any _simple_ standard algorithm of implementing r5rs macro system
and macro expander?

The only thing I could find is [https://www.cs.indiana.edu/chezscheme/syntax-
case/](https://www.cs.indiana.edu/chezscheme/syntax-case/)

~~~
jbclements
I'm afraid I literally laughed out loud at your request for a _simple_
standard algorithm for r5rs macro systems. However, it's a sympathetic laugh.
Macro Hygiene is still very hard, principally because (I claim) there's not
yet a clean and widely accepted model for it. Matthew Flatt's "sets of scopes"
model is (IMNSHO) the current leader. Time will tell whether he or anyone else
comes up with a simpler and more widely accepted model. But yes: as an
implementor, it "feels" _very heavy_ , and you keep thinking that there must
be a simpler solution to this problem (aside from just throwing the problem
out and giving up on hygiene and language composability).

~~~
kovrik
Yeah, you are right. I've already implemented everything from r5rs, but macro
system. And I don't know where to start, just can't wrap my head around it.

And people say that Scheme has a very minimalist design and is easy to
implement...

~~~
groovy2shoes
You may find this paper helpful [1]. As noted there, syntax-rules consists
really of two different parts: (1) the hygiene-preserving macro expander and
(2) the pattern-matching facility. Once you wrap your head around the two
pieces, it's actually pretty straightforward to implement them both. It's
_very_ common to write some "low-level" macro facility as a stepping-stone to
syntax-rules (such as explicit-renaming macros or syntactic closures): the
implementation of syntax-rules then becomes a composition of the pattern-
matcher and the low-level facility. A tutorial implementation of an
appropriate pattern-matcher can be found at [2],[3].

There's lots of good reading to be found at the ReadScheme Library [4]. Most
if not all of the references in [1] can be found there.

Tangentially: yeah, syntax-rules kinda flies in the face of the oft-mentioned
minimalism of Scheme, but there's a reason for it: at the time syntax-rules
was standardized, there was no consensus on which (if any) low-level facility
should be standardized (and, really, there _still_ isn't any such consensus).
The reason syntax-rules operates as a pattern-template rewriting system rather
than as a procedural system is that such a system is able to _guarantee_ that
the macros it produces are hygienic in a (comparably) simple and intuitive
way. The idea was to standardize on a high-level system so that Scheme could
have a standard macro facility, whilst leaving the low-level systems open for
further exploration and experimentation. The two main contenders are still,
after all these years, syntax-case and syntactic closures: the latter being
easier to implement and arguably easier to grok, the former being potentially
more powerful (in that an implementation of syntactic closures within syntax-
case is known, but not vice-versa (last I checked)).

\--

[1]: [http://mumble.net/~jar/pubs/scheme-of-things/easy-
macros.pdf](http://mumble.net/~jar/pubs/scheme-of-things/easy-macros.pdf)

[2]:
[http://blog.theincredibleholk.org/blog/2013/02/11/matching-p...](http://blog.theincredibleholk.org/blog/2013/02/11/matching-
patterns-with-scheme/)

[3]:
[http://blog.theincredibleholk.org/blog/2013/02/12/patterns-w...](http://blog.theincredibleholk.org/blog/2013/02/12/patterns-
with-ellipses/)

[4]: [http://library.readscheme.org/](http://library.readscheme.org/)

~~~
kovrik
Hey, thank you so much for that! Haven't seen some of those papers. Looks
promising. Cheers!

------
WindowsFon4life
[https://ecraven.github.io/r7rs-benchmarks/](https://ecraven.github.io/r7rs-
benchmarks/) recent addition to the charts, and is doing quite well.

~~~
nextos
Yes, Chez & Stalin are the fastest in these benchmarks, which seems to match
what the community usually answers when asked about quick implementations.

Sadly Stalin is unmaintained. Its whole program optimization techniques were
really advanced. I remember it even got my ivory-tower professors, who were
big in the static analysis field, excited.

Now, a tricky question. I'm mostly unfamiliar with Scheme for writing real-
world code. Will the ongoing merger of Chez with Racket make the latter a
clear winner in the Scheme camp? How are libraries and FFI?

A problem with Scheme is excessive fragmentation. Having a clear winner would
be cool for library support. Racket is great due to multiple paradigms and
DSLs [1]. I hope it eventually becomes a very practical Lisp with all
Mozart/Oz semantic goodies.

I am trying to do all my projects in a Lisp. Lately this is either Clojure or
SBCL. Both have good libraries and decent FFIs. Clasp (Common Lisp on LLVM)
[2] has gotten me excited, as good interfacing with C++ will be great to
access a lot of quick numerics code.

[1] [https://beautifulracket.com/appendix/domain-specific-
languag...](https://beautifulracket.com/appendix/domain-specific-
languages.html)

[2] [https://github.com/drmeister/clasp](https://github.com/drmeister/clasp)

~~~
ClFromEmacs
R7RS ftw.

~~~
Johnny_Brahms
I feel that not standardising a low level FFI for r7rs large is a mistake.
They should at least recommend some reasonably low level stuff that can be
used to build abstractions.

~~~
cat199
Agree with the sentiment, but at the same time understand the rationale - FFI
implies alot of GC/memory internal interfacing stuff, and to some extent
expects a c-based implementation (not e.g. JVM,CLR,etc).

If r7 & library interface are widely adopted, some flavors of FFI could evolve
within the library/srfi process and gradually become defacto standards..

Probably hoping too much.. but in any event..

~~~
dleslie
That didn't happen with R5RS, why would it happen now?

Face it, by refusing to be opinionated they ensured Scheme will remain a toy.

~~~
Johnny_Brahms
Because r7rs large is an effort that probably is bigger than common lisp. It
is very much not a toy language.

~~~
dleslie
If it doesn't have an ffi it will remain a toy that relies on implementations
to make it useful.

------
jbclements
(Mostly just hoisting Noel Welsh's comment to the top level) How will the
expected upcoming move of Racket to the use of Chez affect the comparison
between Gerbil and Racket? I'm trying not to set my expectations too high.
BTW: RacketCon! This weekend!

~~~
baldfat
I am super excited for Chez. If we see the speed we are look at a possible
doubling in speed.

There is certainly a reason why he has stuck with Gambit and not my beloved
Racket. This seems perfect for using Racket's macros. I just don't know
Gambit's Macros well enough to compare them to Racket.

Here is the Bench Marks for Chez, Racket and Gambit
[https://ecraven.github.io/r7rs-benchmarks/](https://ecraven.github.io/r7rs-
benchmarks/)

~~~
WindowsFon4life
Gerbil is there as well.

------
nemoniac
Already a handful of "how does this compare...?" postings but the standard for
a systems-programming scheme is scsh, a find abstraction layer over POSIX
dating from the nineties.

[https://scsh.net/](https://scsh.net/)

~~~
Naac
I think maybe there is a different interpretation of the words "systems
programming"?

I took it to mean a scheme used for developing close to the hardware programs,
where as maybe others are taking it to mean a language which can be used to
write common scripts and tools used by Systems Engineers.

~~~
xfer
Close to the hardware can also be done with scheme and indeed has been done in
the past. Look at all the smartcards, running a JVM. For scheme, it just
requires some engineering effort and there is not much demand for it. Btw,
there is
picobit([https://github.com/stamourv/picobit](https://github.com/stamourv/picobit))
which can be run on micro-controllers.

~~~
mschaef
PreScheme serves the same sort of role within the Scheme48 ecosystem. It's
been a while since I've looked at Scheme48, but if I remember right, the VM is
written in PreScheme, which is usually compiled down to either C or machine
code. However... you can also run PreScheme code within Scheme48, so that it's
possible to test/update the VM semantics without actually compiling down to C
for each dev cycle.

------
zitterbewegung
How does this compare to prescheme from scheme48?

[http://www.s48.org](http://www.s48.org)

[https://en.wikipedia.org/wiki/PreScheme](https://en.wikipedia.org/wiki/PreScheme)

------
ClFromEmacs
The link should have been to [http://cons.io](http://cons.io) See Freenode
#gerbil-scheme for active development and help. So far it is very nice and
about twice as fast as sbcl.

------
roma1n
For the uninitiated, how does this compare to guile?

~~~
ratboy666
Based on Gambit-C: A scheme to C (or javascript... and I think there may be
other targets) compiler. Comes with a Scheme->target compiler, then compile
that code, and deploy. So, you write in Scheme, and deliver in C...

Comes with an interpreter. Supports macros, etc. and Gambit supports easy C
FFI, option for infix syntax, massive threading, full numeric tower

Easy to hack on (in my opinion), and performs very well. Gambit-C has been my
"goto" Scheme for the past decade.

Could be used as an "extension language", but not its main purpose. Mostly, a
way to deliver Scheme code that runs fast.

Racket has a better IDE -- but I like the simplicity of Gambit-C.

~~~
WindowsFon4life
Gambit is amazing. And gerbil brings a lot of batteries to it.

------
jblow
Why do people keep thinking they can use a garbage-collected language for
“systems programming”?

~~~
CoolGuySteve
I always wonder exactly what kind of "systems" these people are programming,
clearly not any with real-time constraints. It almost seems like "systems
programming" got co-opted to mean "not interpreted". At least that's what I
noticed with Go's marketing.

There are a few HFT firms, most notably Virtu, that use Java. But my
understanding from having interviewed people that worked there is that it's so
convoluted to avoid GC pauses that you might as well be using C++.

~~~
astrobe_
It seems to md that systems (with a 's') programming was a term lntroduced by
Go, and I always understood it has something with a wider scope than system
programming - actually "intermediate level" applications for which a GC is
acceptable both time-wise and space-wise. Yet for system (without 's')
programmers (kernel, driver or embedded systems devs for instance) a GC is
still a no-go.

~~~
cat199
> lntroduced by Go

no. further popularized perhaps, but no.

perhaps a shorthand for 'distributed systems' programming, idk.

Definately heard the phrase applied in this area 10+ years ago, by people who
had been around for 10+ years (see also go authors)

------
dogruck
Can anyone briefly summarize the points of debate and optimization? I'm not
familiar with the competing kit, and the primary goals.

