
LispY C - signa11
https://github.com/eratosthenesia/lispc
======
eggy
Clasp is not quite the same, but it can work seamlessly, and compiles to
machine code using an LLVM backend [1].

It was created to facilitate using all of the scientific libs in C++ by a
chemistry professor for the creation of molecules [2]. It's a big codebase.
I'll have to look at LispY C, since on first impression it seems smaller, and
I like C!

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

~~~
nemoniac
Clasp is an implementation of Common Lisp, a standard language and not a self-
designed lisp as in the case of Lisp/C.

~~~
eggy
Thanks for the clarification. I am going to dig in and have a look.

------
jackdaniel
Embeddable Common-Lisp[1] compiles Lisp to C and hooks to the compiler on the
host system (generating and building code during the runtime is also
possible). Moreover it's a full implementation of the Common Lisp and has a
bytecode compiler/interpreter which may freely interop with the C/C++ code.

[https://common-lisp.net/project/ecl/](https://common-lisp.net/project/ecl/)

------
TeMPOraL
C-Mera[0] is also worth looking at. It's a Lisp-to-C-like source-to-source
compiler. They're doing pretty neat stuff with that wrt. high-performance
graphics[1]. On this year's European Lisp Symposium there was a demonstration
of using this to generate and simultaneously test a graphics filter on many
different architectures with many different optimizations to determine which
works best on what. The video of the talk should be available next week.

[0] - [https://github.com/kiselgra/c-mera](https://github.com/kiselgra/c-mera)

[1] - [https://github.com/kiselgra/cm-fop](https://github.com/kiselgra/cm-fop)

~~~
eggy
Wow, that does look interesting, and one file has over 16K LOC, when compared
with the <1.5K LOC of the OP's Lispy C. Both seem to let you code in SEXPRs in
a very C-looking style. Others are raising Lisp to C solutions like ECL, but I
have not really seen the C output of ECL, and you program ECL in Lisp. With
C-Mera or Lispy C you are sort of writing in C with parentheses. At least that
is how it looks to me. I have used Gambit-c and CHICKEN scheme before without
really touching the C they output.

------
jlas
> Because LISP is expressive and C is fast and I wanted the best of both
> worlds is the short answer.

I'm not sure how well known it is, but some Lisps can be statically compiled
to machine code.

But one thing I've wondered about is how good can it get? Are there any
benchmarks for Lisp vs. C?

~~~
dreamcompiler
Some Lisps? Almost all Common Lisps compile to native machine code. Which is
why CL programs tend to run orders of magnitude faster than e.g. Python
programs. (But they're still typically slower than C because of runtime memory
allocation and typetag checking.)

~~~
agumonkey
Talking about speed, someone put this online [http://www.nexoid.at/tmp/scheme-
benchmark-r7rs.html](http://www.nexoid.at/tmp/scheme-benchmark-r7rs.html)

~~~
eggy
Chez Scheme (the compiled version vs. Petite Chez) figures high on those
lists, and it was just opensourced by Cisco. I used to use Gambit-C, and I
still like it, but Chez is fast.

~~~
agumonkey
It is and regularly way above the others. I had to hold on my fanaticism.

~~~
eggy
I am playing with Eduardo Cavazos's libraries with Chez [1], and particularly
the port of xspringies. Great fun considering as he points out that the mass-
spring calcs are all taking place in scheme. It runs fine on my 2-3 year old
notebook.

C was a third language for me in the day, and I like Lisps, so this Lispy-C
thing is going to eat my afternoon up!

[1]
[https://github.com/dharmatech?tab=repositories](https://github.com/dharmatech?tab=repositories)

------
zerocrates
> _The C Programming Language_ by Brian W. Kernighan

An interesting way to cite K&R.

~~~
DiabloD3
Where-as I typically cite it in shorthand as "K&R", dropping "The C
Programming Language" altogether.

------
geon
Looks a lot like this:

[http://voodoo-
slide.blogspot.se/2010/01/amplifying-c.html?m=...](http://voodoo-
slide.blogspot.se/2010/01/amplifying-c.html?m=1)

[https://github.com/deplinenoise/c-amplify](https://github.com/deplinenoise/c-amplify)

------
in4lio
Fine! To generate the C code using Lisp syntax - it's not such bad idea, the C
preprocessor is awful. A few years ago, for this purpose, I wrote the _yupp_
preprocessor which use similar syntax, but _yupp_ allows to inject the code in
functional style into the source code on C.

[https://github.com/in4lio/yupp/](https://github.com/in4lio/yupp/)

------
cjlarose
I feel like besides powerful macro generation, the other big selling point of
a lisp is that you can dynamically generate code at runtime, either by
providing hooks into the compiler itself or by running the generated code
through an interpreter. This project doesn't seem to do that at all. Does
anyone know of any similar projects that do?

~~~
TeMPOraL
I'm not sure about where you see the difference between those "selling points"
\- Lisp macros _are_ the very advanced facility for runtime code-generation
and compile-time computing. It's not just about expanding syntactic shortcuts
- Lisps give you full power of the language runtime and compiler to be used at
compile-time.

~~~
billsix
I'm currently writing a library/book dedicated to the subject, including
compile time state, compile time I/0, and a compile time test framework in 9
lines of code!

Tests are specified as part of the definition, run at compile time, and if
they fail no executable is produced.

    
    
      {define
        "list#"
        permutations
        [|l|
         (if (null? l)
           ['()]
           [{let permutations ((l l))
              (if (null? l)
                  [(list '())]
                  [(flatmap [|x| (map [|y| (cons x y)]
                                      (permutations (remove x l)))]
                            l)])}])]
      ;;; tests
      (satisfies?
       permutations
       '(
         (() ())
         ((1) ((1)))
         ((1 2) ((1 2)
                 (2 1)))
         ((1 2 3) ((1 2 3)
                   (1 3 2)
                   (2 1 3)
                   (2 3 1)
                   (3 1 2)
                   (3 2 1)))
         ))}
    

[https://github.com/billsix/bug](https://github.com/billsix/bug)

------
Mutjake
Not a 1=1 match, but you might also want to check [https://github.com/aoh/owl-
lisp](https://github.com/aoh/owl-lisp) if you need a Lisp that produces C code
to gain the optimization goodies of different C compilers.

------
microcolonel
Why replace "struct" with "class"? These are completely different things. >.>

~~~
danielparks
I don't see where you get that. There is a struct function.

That said, the only difference between a struct and a class is that struct
member defaults to public, and class members default to private.

~~~
chadzawistowski
> the only difference between a struct and a class

In C++ land, this would be true.

C doesn't let you write methods within structs. C structs don't even have
inheritance. No virtual table is generated. There is no single-dispatch
mechanism.

------
waldrews
Hmm... would it be feasible to parse existing C code into an AST with an
existing compiler front-end, and generate this kind of Lisp?

------
v-yadli
This could be very useful as a codegen alone.

------
mapcars
I don't quite understand, is this a tool to generate C code, or you can use
compiled result directly from CL?

------
ape4
So crazy it might just work.

~~~
sdegutis
I'd be surprised if something exactly like this but more mature and with a lot
more questionable legacy design decisions doesn't already exist.

~~~
eudox
There's L++: [https://bitbucket.org/ktg/l](https://bitbucket.org/ktg/l)

And, for people who refuse to let go of curly braces, there's this shameless
plug: [https://github.com/eudoxia0/cmacro](https://github.com/eudoxia0/cmacro)

------
giancarlostoro
I really want this for D tbh. Looks clean though.

------
cpdean
That is a lot of docs.

------
mathheaven
My first impression with the title was wrong, I thought about something
related to Lisp and Y Combinator.

~~~
valbaca
Yeah, this title really didn't match up with the project name or how it's
pronounced.

