# 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:** 1

<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 4, 2017, 12:46pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/1 "2017-02-04T12:46:06Z")

</div>

Hii Julians,

I was wondering about the exact usage of `femtolisp` in `julia`. I’ve Googled around but the nothing exact came up, though there were some references in the old archives.

I know that the `julia-parser` has a native implementation now so, If anyone could please explain to me the exact usage and reason for using `femtolisp` within the source-code and the reason for it’s inclusion in the executable.

- Thanks

---

<div class="post-metadata">

### Author: ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)
#### Post date: [February 4, 2017, 1:17pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/2 "2017-02-04T13:17:57Z")

</div>

Syntax lowering is also in femtolisp (julia-syntax.scm), and has not yet been ported. There are some bootstrap issues which would need solving, and not a strong-enough reason to do so at this time.

See also:

> [@What exactly code lowering is an how to do "unlowering"?](https://discourse.julialang.org/t/what-exactly-code-lowering-is-an-how-to-do-unlowering/1315):
>
> I’ve seen a number of snippets produced by code\_lowered and have rough intuition of what it does, but what’s exact definition of code lowering? Does “lower” means “more low-level”? In my package I need to get an expression of a function. I do it using the code at the end of this post, but essentially I get it using Base.uncompressed\_ast which, as far as I understand, returns lowered code that is a bit hard to work with. Is there a way to “undo” lowering or get function expression exactly as…

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 4, 2017, 4:33pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/3 "2017-02-04T16:33:24Z")

</div>

Lisp is great for writing parsers. Femtolisp is a neat (actually, closer to Scheme than CL), self-contained dialect and its implementation. It is included in the executable since it is an interpreter, and it runs the parser code.

Basically, you can ignore it unless you want to modify the parser (for new surface syntax).

---

<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 5, 2017, 12:39pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/4 "2017-02-05T12:39:31Z")

</div>

Hmm, interesting. But why only femtolisp?

And apart from the source is there any blog/article you know of that’d help me distinguish various aspects of the compiler system.

Say, we know that Julia has intentionally done away with TCO and Mutual Recursion techniques etc and there’s good reasoning behind it. The point is, at which layer does one need to work on to create such extensions.

**Does `femtolisp` only translates the julia surface syntax to this pseudo-typed-scheme syntax or something more? I see that the base is defined in Julia itself so what exactly does the `C/C++` part does?**

I’ve gone through the code\_lowered thing, seems useful.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 5, 2017, 1:34pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/5 "2017-02-05T13:34:38Z")

</div>

> [@abhi18av](#):
>
> But why only femtolisp?

Sorry but I don’t understand what you mean here. Why would you need anything else?

AFAIK the femtolisp intepreter is just used for parsing, ie maps strings to ASTs. That’s all it does. Some C functions (eg `jl_parse_string`) are glue to call it.

> [@abhi18av](#):
>
> I see that the base is defined in Julia itself

Well, _most_ of it, of course not everything.

Again, you could be a very advanced Julia programmer without having to touch either femtolisp or C code. I mostly read the femtolisp part out of curiosity (I like Lisp), not because of solving an practical problem.

---

<div class="post-metadata">

### Author: ![ihnorton](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihnorton/32/26_2.png) [@ihnorton](https://discourse.julialang.org/u/ihnorton)
#### Post date: [February 5, 2017, 2:12pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/6 "2017-02-05T14:12:19Z")

</div>

> [@abhi18av](#):
>
> And apart from the source is there any blog/article you know of that’d help me distinguish various aspects of the compiler system.

[http://docs.julialang.org/en/stable/#devdocs](http://docs.julialang.org/en/stable/#devdocs)

> [@abhi18av](#):
>
> at which layer does one need to work on to create such extensions.

All of them.

> [@abhi18av](#):
>
> Does femtolisp only translates the julia surface syntax to this pseudo-typed-scheme syntax

Yes.

> [@abhi18av](#):
>
> I see that the base is defined in Julia itself so what exactly does the C/C++ part does?

Among other things: i/o primitives, memory allocation/gc, JIT compile to machine code via LLVM.

See also:

> [@Examining an older and simpler version of Julia](https://discourse.julialang.org/t/examining-an-older-and-simpler-version-of-julia/1142/2):
>
> I haven’t been around quite that long, but here are a few interesting points to look at: the first 10-20 commits: basic parser beginning of codegen: [https://github.com/JuliaLang/julia/commit/17f383fec059f](https://github.com/JuliaLang/julia/commit/17f383fec059f) beginning of dlopen / ccall support: [https://github.com/JuliaLang/julia/commit/18f456233b280f](https://github.com/JuliaLang/julia/commit/18f456233b280f) beginning of ast translation to C: [https://github.com/JuliaLang/julia/commit/89247a6bf2eeb](https://github.com/JuliaLang/julia/commit/89247a6bf2eeb) beginning of interpreter: [https://github.com/JuliaLang/julia/commit/6c2b43c2b3e2986b](https://github.com/JuliaLang/julia/commit/6c2b43c2b3e2986b) You can get a nice…

---

<div class="post-metadata">

### Author: ![kevin.squire](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevin.squire/32/62_2.png) [@kevin.squire](https://discourse.julialang.org/u/kevin.squire)
#### Post date: [February 5, 2017, 3:18pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/7 "2017-02-05T15:18:26Z")

</div>

For a slightly related tangent, a while ago there was an attempt to switch from femtolisp to Chicken Scheme, which compiles scheme to C. It was deemed too resource intensive in the end, I think. Anyway, see [https://github.com/JuliaLang/julia/issues/7977#issuecomment-52172600](https://github.com/JuliaLang/julia/issues/7977#issuecomment-52172600).

---

<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 5, 2017, 5:10pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/8 "2017-02-05T17:10:52Z")

</div>

Aha, thanks everyone for the wonderful resources!

So, if I want to try out features like **mutual recursion** or have a stab at **tail call recursion** , the post `femtolisp` parser and lowered code generator, it’s basically the `codegen.cpp` that’s takes over and communicates with the `llvm`.

I know that this has been debated to death but I’d like to ask that as mentioned in the [llvm5 docs](http://llvm.org/docs/CodeGenerator.html#tail-call-section) there’s clearly a tail call optimization in place. So, if not julia than other, theoretically speaking, other languages might still leverage it.  
[https://github.com/rust-lang/rfcs/issues/271](https://github.com/rust-lang/rfcs/issues/271)

> **[Pre-RFC: explicit proper tail calls](https://internals.rust-lang.org/t/pre-rfc-explicit-proper-tail-calls/3797/14)**
>
> Oh, thanks. I’d totally misunderstood how return actually worked. Hmm, I guess I made a false implication from this note in the book that’s right before a return-with-a-semicolon example: but with a semicolon, it would return () instead ...

Another thing being, would it be of any performance gain if julia switched from **`femtolisp+cpp`** to **`chez+Rust`**. I mean, how does one really measure that objectively?

---

<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 5, 2017, 5:12pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/9 "2017-02-05T17:12:37Z")

</div>

I meant that, as @kevin.squire mentioned about chicken-scheme - how about using something like plain old racket or chez or xyz. Why does femtolisp fit the internals well?

---

<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: [February 5, 2017, 5:13pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/10 "2017-02-05T17:13:38Z")

</div>

A good test might be simply building Julia itself (at least in it’s current, very large form), and measuring the time from when it starts compiling all the Julia code.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [February 5, 2017, 5:43pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/11 "2017-02-05T17:43:03Z")

</div>

AFAIK it does not need to “fit” the rest of the “internals” beyond parsing. Once it generates the AST, its job is done. Anything that would parse and generate the same AST could be a replacement (given other features, like easy maintenance, being self-contained, fast enough, friendly license, etc). But it works, so apparently its replacement is not a high priority.

Also, removing femtolisp would violate Greenspun’s 10th law even more blatantly. The fact that femtolisp is neither bug-ridden nor slow is already pushing it.

---

<div class="post-metadata">

### Author: ![johnmyleswhite](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnmyleswhite/32/31_2.png) [@johnmyleswhite](https://discourse.julialang.org/u/johnmyleswhite)
#### Post date: [February 5, 2017, 6:27pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/12 "2017-02-05T18:27:15Z")

</div>

> [@abhi18av](#):
>
> Why does femtolisp fit the internals well?

The important question is: is it useful building something on top of a Lisp that Jeff Bezanson entirely controls and can modify as needed to suit Julia’s needs?

---

<div class="post-metadata">

### Author: ![swissr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/swissr/32/208_2.png) [@swissr](https://discourse.julialang.org/u/swissr)
#### Post date: [February 6, 2017, 10:31pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/13 "2017-02-06T22:31:20Z")

</div>

[quote=“abhi18av, post:4, topic:1902”]  
And apart from the source is there any blog/article you know of that’d help me distinguish various aspects of the compiler system.  
[/quote]There is also an old (2014) Juliacon video about Julia Internals: [Introduction to Julia Internals - YouTube](https://www.youtube.com/watch?v=osdeT-tWjzk)

---

<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 7, 2017, 4:08am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/14 "2017-02-07T04:08:57Z")

</div>

@swissr , Yes, I did find it through some of the links mentioned here earlier. Much appreciated 🙂

---

<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 7, 2017, 4:10am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/15 "2017-02-07T04:10:44Z")

</div>

@johnmyleswhite, I read in the old archives that there’s a definite plan to have julia self-hosted. Do you reckon it’ll happen post-1.0 releases?

---

<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 7, 2017, 4:12am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/16 "2017-02-07T04:12:11Z")

</div>

@Tamas_Papp Yup, I’ve read the devdocs - it’s explained pretty clearly over there. I usually just download the pdf and I can’t remember seeing those there. Still, the docs have satiated much of my curiosity.

---

<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 7, 2017, 4:12am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/17 "2017-02-07T04:12:43Z")

</div>

@ScottPJones Thanks 👍

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [February 7, 2017, 4:22am UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/18 "2017-02-07T04:22:57Z")

</div>

> [@abhi18av](#):
>
> I read in the old archives that there’s a definite plan to have julia self-hosted.

I’m not sure where you read about a “definite” plan. There are certainly people who expressed an interest, but e.g. as @JeffBezanson [wrote](https://groups.google.com/d/msg/julia-dev/dOAwcwm5iEA/dJFqob5HfNYJ):

> [@](#):
>
> The main problem is that this involves lots of tedious work, after  
> which you end up with the same thing you started with, just  
> implemented differently. I’m not even sure I want to use LLVM in any  
> language but C++, since that’s the language it’s documented in and C++  
> APIs tend to be highly coupled to the language.

The fact is that no one appears to be seriously working on making Julia self-hosting right now. There are far too many more interesting problems to work on.

---

<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: [February 7, 2017, 1:30pm UTC](https://discourse.julialang.org/t/the-role-of-femtolisp-in-julia/1902/19 "2017-02-07T13:30:13Z")

</div>

I think there’s still interest in moving the parsing and lowering code from Scheme to Julia - if we could reap some performance gains (which I feel we could) by doing so.  
Currently, isn’t most all of the compilation time spent in those two phases?  
Speeding that up could make a big difference for people who’d like to use Julia as their scripting language also.  
Also, having the parsing and lowering code in Julia would greatly expand the number of people who would be able to improve it.

There are a few things in C (such as most of the stuff in utf8proc) that could be done in Julia, and made more efficient also.  
Changing any of the parts that are currently in C++ to Julia, I agree with what Jeff said.

---

<div class="post-metadata">

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

</div>

The idea of a static compiler for FemtoLisp bytecode to LLVM IR has also been thrown around, which would help with parser performance.

If you’re interested in seeing the current effort toward a Julia parser written in Julia, see [JuliaParser.jl](https://github.com/JuliaLang/JuliaParser.jl) and [Tokenize.jl](https://github.com/KristofferC/Tokenize.jl).

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