Live data from Hacker News

LispY C

github.com

31–40 of 45 posts

Re: LispY C

#32
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

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

Re: LispY C

#33
post #2

So crazy it might just work.

Historically the Scheme48 abstract machine was written in Pre-Scheme, a Scheme subset restricted enough to compile straightforwardly to C.

For me, using Pre-Scheme to write graphics kernels was great fun, and produced decently fast code :)

Re: LispY C

#34
post #8

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?

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.

Re: LispY C

#35
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/

Re: LispY C

#36
post #8

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?

Embeddable Common-Lisp does that

https://common-lisp.net/project/ecl/

Re: LispY C

#37
post #8

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?

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.

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

Re: LispY C

#38

> The C Programming Language by Brian W. Kernighan An interesting way to cite K&R.

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

Re: LispY C

#39
post #8

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?

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.

I understand that macros are both the mechanism to generate code at compile-time as well as for generating code at runtime. But it doesn't look like the linked project does the latter. In fact, there are mentions in the README that indicate that there is no runtime for LISP/c at all:

> The way that LISP/c works is sort of tricky. It utilizes a lot of string manipulation and interpretation. It doesn't need to be insanely fast, though, because it's just dealing with code; the compiled result will not suffer from any slowness.

In other words, it seems that this project just allows you to generate C code from a LISP-like syntax, but doesn't allow you to `eval` during the execution of the resulting C program. There is no runtime representation of code as data as with other lisps.

Re: LispY C

#40
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?
Post reply on HN