Hacker News new | ask | show | jobs
by cjlarose 3697 days ago
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?
3 comments

I never published it, but I wrote FFI bindings from common-lisp to the tinycc library, and it could generate and compile C code at runtime without having to shell out to a C compiler. It was really more of a toy than anything else, though it was slightly useful for things like basic system calls with complicated structs.
Embeddable Common-Lisp does that

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

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
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.