
Show HN: Compiler using Lisp’s macro system for metaprogramming C-like languages - dis0rdr
https://github.com/kiselgra/c-mera
======
kruhft
Reminds me of an older (unfinished) project of mine, sxc:

[https://github.com/burtonsamograd/sxc](https://github.com/burtonsamograd/sxc)

------
jokoon
I don't understand, what are lisp/scheme/racket/haskell being used for? I mean
how are those languages good from a software engineering point of view? From a
project management point of view?

Is it possible to hear bad things about those languages? Why aren't they used?
Is it because they are too hard to use, or to difficult to approach for a
beginner?

~~~
cryptonector
Haskell and friends (Elm, ..) are fantastic, and perhaps the absolute best
programming languages for software engineering. Except there's a small
problem: Haskell is either write-only or read-only, depending on what you're
looking at. That is, beautiful Haskell code is easy enough to read, but very
very difficult to write, while working code you might write may not be very
readable at all. Of course, that can happen in any language, but it seems to
me that Haskell leads to that sort of situation very easily. On the other
hand, the nice thing about Haskell is that once your code compiles it also
probably does what you want it to :)

I would stay away from dynamically-typed languages (e.g., the Lisp and Scheme
families) for software engineering. Dynamic typing means more run-time errors,
which means a higher support burden, which is very much what you want to lower
when you're a software engineer. And this is why I like Haskell: it's
statically-typed. (The main appeal of Lisp is its macro system, really.
Haskell gives you the sort of power that the Lisp macro system gives you
anyways, though at the cost of more compile-time processing.)

If you can't use Haskell, then your best bets are Rust and C/C++.

In any case, a software engineer almost necessarily has to be familiar with
all of these, and able to use any of them. You really want a strong foundation
at the lowest layers (C, and even ASM) in order to work the full stack
(libraries, applications, compilers, OS). You don't have to be a full stack
engineer, naturally, but it sure helps to be able to adapt to working at
different layers, and for this you need a strong conceptual foundation. A lot
of layers in a full stack are written in C/C++, but web front-ends involve
JavaScript, which is dynamically-typed, so you'll really need to be familiar
with all of these, and that's just to get started.

~~~
SomeHacker44
My opinion: If you can't use Haskell, you should definitely use a null-free
language for safety in this day and age, which means Rust and definitely _not_
C/C++.

~~~
cryptonector
Yes, but that doesn't mean that you shouldn't be able to use C/C++ as needed
-- sometimes you have no choice.

~~~
SomeHacker44
As always, pragmatism is good. If you are good at C/C++, use it and be happy
and productive. I presumed the context of this discussion, however, was
wanting to use Haskell for its particular benefits, and in my opinion the
null-free nature is a key benefit, which would not be achieved by using C/C++.

------
4lch3m1st
I think the title might be misleading here. It doesn't really transpile Common
Lisp to C, it requires you to write in a C-like Lisp dialect so it gets
translated to C. Might as well have been an entire Lisp dialect with a
compiler of its own.

~~~
yorwba
I think the idea is that you write C-with-sexpr-syntax, but by embedding those
s-expressions in Common Lisp, you can make use of macros written in Lisp to
generate C code. Essentially, it's a saner preprocessor for C that requires
you to write in funky syntax.

I think this would be even more interesting if it could do the C ->
s-expression transformation, so that code already written in C could integrate
calls to Lisp macros without needing a full rewrite.

~~~
cryptonector
A C->S-expression compiler would have to produce very obvious and simple
mappings in order for a macro system to be usable. Another way of saying this
is that a simple and standard AST would be nice.

~~~
sedachv
The Vacietis
([https://github.com/vsedach/Vacietis/](https://github.com/vsedach/Vacietis/))
reader can be easily adapted to do that. You can see examples in the unit
tests:

[https://github.com/vsedach/Vacietis/blob/master/test/reader-...](https://github.com/vsedach/Vacietis/blob/master/test/reader-
tests.lisp)

As-is, C block constructs get mapped directly to Common Lisp special forms
like _tagbody_ and _prog_ because those implement a superset of C control flow
semantics. Pick different names in _vacietis.c_ and you have an AST.

------
PaulHoule
TLDR -- there is nothing so special about Lisp (in terms of metaprogramming)
other than a syntax that is easy to parse. All languages have tools to
manipulate code at the source code level, but people rarely use them. These
guys did.

