# The role of femtolisp in Julia?

**URL:** https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902
**Category:** Internals & Design
**Tags:** question, history
**Created:** [February 4, 2017, 12:46pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902 "2017-02-04T12:46:06Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![ZacLN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/zacln/32/2748_2.png) [@ZacLN](https://discourse.julialang.org/u/ZacLN)
#### Post date: [February 8, 2017, 10:48pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/21 "2017-02-08T22:48:15Z")

</div>

I’m working on a version of a parser using Tokenize that lints as it parses, tracks variable declarations and is round-trippable (i.e. holds whitespace/punctuation in the syntax tree) and in its early formulation it’s ~4 times as fast as the scheme version even with the extra work. I’m sure a proper attempt at speed could do better than an order of magnitude faster.

---

<div class="post-metadata">

### Author: ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)
#### Post date: [February 8, 2017, 11:35pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/22 "2017-02-08T23:35:41Z")

</div>

> [@abhi18av](#):
>
> Hmm, interesting. But why only femtolisp?

After reading through this thread, perhaps this piece of missing information for @abhi18av (and anyone else interested) is this:

If you are asking “But only - why femtolisp in particular?” the answer would be, as I understand ([see this](https://github.com/JeffBezanson/femtolisp/graphs/contributors?from=2008-06-29&to=2017-02-09&type=c)), Jeff Bezanson wrote femtolisp before beginning to work on Julia. So it was the right tool for the right person at the right time, and there has been no strong need or effort to change since.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [February 9, 2017, 12:48am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/23 "2017-02-09T00:48:14Z")

</div>

There was a while very early on where we were using [Guile](https://www.gnu.org/software/guile/manual/html_node/The-Scheme-Compiler.html) (IIRC – but it could have been some other Scheme implementation) instead, on the premise that a mature, well-tested Scheme – and one that can compile to C code at that – would be better and faster. But we found that it was pretty crashy and that more time was being spent debugging Guile issues than working on Julia itself, so we switch to Femtolisp, which was totally smooth change, only 2x slower, took zero compilation time, and of course has the huge benefit that any bugs in the implementation get fixed immediately by the guy who wrote it – namely, @jeff.bezanson.

So ultimately the reasons for Femtolisp are:

1. Scheme is excellent for writing parsers since trees (aka S-expressions) are its forte.
2. Femtolisp is a small, simple, highly embeddable and remarkably fast Scheme.
3. We control it (and by “we” I mean Jeff) and can fix any bugs we encounter.

Tangentally related, but we also used the [Boehm collector](https://www.hboehm.info/gc/) as our GC for a while very early on but also found that to be crashy. It could have been our usage of it which was at fault, but we switched to a simple custom mark-and-sweep and that was much more reliable.

---

<div class="post-metadata">

### Author: ![abhi18av](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhi18av/32/5698_2.png) [@abhi18av](https://discourse.julialang.org/u/abhi18av)
#### Post date: [February 9, 2017, 3:43am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/24 "2017-02-09T03:43:53Z")

</div>

Mm hmm, thanks everyone for the wonderful resources! I’ve learned a lot from this thread 🙂

---

<div class="post-metadata">

### Author: ![abhi18av](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhi18av/32/5698_2.png) [@abhi18av](https://discourse.julialang.org/u/abhi18av)
#### Post date: [February 9, 2017, 3:49am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/25 "2017-02-09T03:49:05Z")

</div>

That’s interesting, using Guile initially. I think that after Andy Wingo got involved, the language got a VM and wonderful S-exp based `assembly`. I’m really starting to grok compilers and language design.

Could you tell me more about why mark-and-sweep and not some other GC? And, I thought people prefer not having a GC so they can fine tune their applications more so how does that work out with `julia`.

---

<div class="post-metadata">

### Author: ![abhi18av](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhi18av/32/5698_2.png) [@abhi18av](https://discourse.julialang.org/u/abhi18av)
#### Post date: [February 9, 2017, 3:50am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/26 "2017-02-09T03:50:26Z")

</div>

Yes @andyferris, I did come to know about `femtolisp` by this [femto-emacs](https://github.com/FemtoEmacs/Femto-Emacs). Only then did I become really interested it the use of femtolisp in julia.

---

<div class="post-metadata">

### Author: ![abhi18av](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhi18av/32/5698_2.png) [@abhi18av](https://discourse.julialang.org/u/abhi18av)
#### Post date: [February 9, 2017, 3:51am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/27 "2017-02-09T03:51:36Z")

</div>

The Tokenize.jl - I wouldn’t have found it myself! Appreciate it, @ararslan

---

<div class="post-metadata">

### Author: ![abhi18av](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhi18av/32/5698_2.png) [@abhi18av](https://discourse.julialang.org/u/abhi18av)
#### Post date: [February 9, 2017, 3:53am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/28 "2017-02-09T03:53:21Z")

</div>

@ScottPJones and @stevengj Regarding this thing about C++, then how does it work out with other LLVM targetting languages like Rust etc? Isn’t LLVM supposed to be a level platform to build upon.

---

<div class="post-metadata">

### Author: ![iamed2](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamed2/32/215082_2.png) [@iamed2](https://discourse.julialang.org/u/iamed2)
#### Post date: [February 9, 2017, 9:06pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/29 "2017-02-09T21:06:08Z")

</div>

> [@abhi18av](#):
>
> I thought people prefer not having a GC so they can fine tune their applications more so how does that work out with julia.

In Julia, certain types in certain situations can be statically allocated on the stack (I _think_ this maps to isbits-types but I’m not sure). An algorithm that doesn’t allocate any heap memory can avoid the GC.

For example:

```julia
function fib_rec(n)
    (n == zero(n) || n == one(n)) && return n

    fib_rec(n - 2) + fib_rec(n - 1)
end

```

If you benchmark this function, you’ll find it never triggers the GC, even for a composite type like `Complex{Int64}`.

---

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [June 27, 2022, 9:51pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/31 "2022-06-27T21:51:41Z")

</div>

> [@dennis-t-peasant](#):
>
> document FemtoLisp’s role in the compiler more formally

It’s as far as I know only used in the Julia parser (and easteregg `julia --lisp` not even documented with --help-hidden). I don’t think it’s going away in the any time soon (since I read, it’s not "speed-critical), but it’s been discussed getting rid of FemtoLisp, there’s already a parser for Julia written in Julia-only code, but I’m not sure it’s always in sync, since Unicode symbols occupationally get added to the parser.

> [@Parsing Julia code](https://discourse.julialang.org/t/parsing-julia-code/61599/2):
>
> Use Base.Meta.parse(str)

And a different parser (currently done in C mostly I believe):

> **[GitHub - JuliaData/Parsers.jl: fast parsing machinery for basic types in Julia](https://github.com/JuliaData/Parsers.jl)**
>
> fast parsing machinery for basic types in Julia. Contribute to JuliaData/Parsers.jl development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)
#### Post date: [June 27, 2022, 10:04pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/32 "2022-06-27T22:04:32Z")

</div>

Femtolisp does parsing and lowering of the julia code. There is interest in bringing the parser to julia in order to give better errors

---

<div class="post-metadata">

### Author: ![Iulian.Cioarca](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iulian.cioarca/32/30166_2.png) [@Iulian.Cioarca](https://discourse.julialang.org/u/Iulian.Cioarca)
#### Post date: [June 30, 2022, 9:09am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/36 "2022-06-30T09:09:03Z")

</div>

Well, before Javascript existed, Scheme was the proposed language for web. Too bad management stepped in and said they would like something catchy like Java so [Brendan Eich](https://en.wikipedia.org/wiki/Brendan_Eich) had to quit on the idea 😅 I sometimes wonder how the world would look like if Scheme/LISP would have been used.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [June 30, 2022, 2:38pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/37 "2022-06-30T14:38:57Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/8/2/82970783bd4ad45b532e79023ffa767fd245bace.jpeg)

---

<div class="post-metadata">

### Author: ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)
#### Post date: [June 30, 2022, 8:29pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/38 "2022-06-30T20:29:16Z")

</div>

You sound like Gerald Sussman (creator of Scheme), who said at Jeff’s thesis defense that he really wanted to program Julia using S-exprs 🙂

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [June 30, 2022, 8:38pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/39 "2022-06-30T20:38:53Z")

</div>

I think it’s actually possible that at some point we will add a Julia S-expression mode. It would be a relatively reasonable way to allow for Julia’s parsing and lowering to be written in pure Julia without bootstrapping issues.

---

<div class="post-metadata">

### Author: ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)
#### Post date: [July 1, 2022, 3:10pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/42 "2022-07-01T15:10:10Z")

</div>

Not the only Mona Lisa there (and none in Julia; well, except for that FemtoLisp dependency?), part of this commit:

> one good way to bloat a piece of software is to add several  
> ASCII pictures of the mona lisa

> <https://github.com/JeffBezanson/femtolisp/commit/e7e5677d51c0c3bf605ecf35ca4e0ab8af3c90bf>
>
> better text representation of infs and nans
> 
> removing construction of low-level …numeric types directly from strings
> 
> adding hash function corresponding to equal
> 
> better way to initialize builtins
> 
> moving advanced bitvector ops to separate compilation unit
> 
> rearranging hash table code so it can be specialized for different
> comparison functions
> 
> one good way to bloat a piece of software is to add several
> ASCII pictures of the mona lisa

---

<div class="post-metadata">

### Author: ![chris-b1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chris-b1/32/14165_2.png) [@chris-b1](https://discourse.julialang.org/u/chris-b1)
#### Post date: [July 1, 2022, 3:53pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/45 "2022-07-01T15:53:03Z")

</div>

> **[The World If](https://knowyourmeme.com/memes/the-world-if)**
>
> The World If is a series of image macros in which an illustration of a futuristic utopia is captioned with a variation of the phrasal template "The world if X" had happened.

---

<div class="post-metadata">

### Author: ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)
#### Post date: [July 11, 2022, 5:51pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/50 "2022-07-11T17:51:18Z")

</div>

I think you’d have to ask @jeff.bezanson about it.

---

<div class="post-metadata">

### Author: ![jeff.bezanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff.bezanson/32/48_2.png) [@jeff.bezanson](https://discourse.julialang.org/u/jeff.bezanson)
#### Post date: [July 11, 2022, 7:21pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/51 "2022-07-11T19:21:53Z")

</div>

If you’re feeling motivated to do it, documentation is always great of course. I do think many if not most Julia users and developers would prefer more of the compiler to be written in Julia. So I don’t see high active demand for detailed femtolisp documentation, e.g. you won’t find it on our roadmap. It’s entirely up to you.

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [July 11, 2022, 8:14pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/53 "2022-07-11T20:14:01Z")

</div>

> [@dennis-t-peasant](#):
>
> . It seems like FemtoLisp could run on a small microcontroller and communicate with Julia through FemtoLisp with “\* ‘human-readable’ bytecode with self-hosted compiler” as a line protocol.

Shameless self plug, but I hope that you know julia can (with a bit of effort) [run on microcontrollers as well](https://seelengrab.github.io/articles/Running%20Julia%20baremetal%20on%20an%20Arduino/), right? If using julia on microcontrollers is the goal, I’d pursue that route instead of using femtolisp directly, since that’s really only used for the parser right now. Aside from that, it’s not a core component of the compiler or the stdlib.

[Previous page](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902.md?page=1)

[Next page](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902.md?page=3)
