How Would You Generate C Code Using Common Lisp Macros? (github.com)
Long-time Slashdot reader kruhft brings news about a new S-Expression based language transpiler that has the feel of C.
This structure allows for the creation of code generation macros using the full power of the host Common Lisp environment, a language designed for operating on S-Expressions, also known as Lists. It is unknown exactly what power might come about from this combination of low level processing with high level code generation.
This has prompted some discussion online about other attempts to convert Lisp to C -- raising several more questions. How (and why) would you convert your Lisp code into C, and what would then be the best uses for this capability?
This has prompted some discussion online about other attempts to convert Lisp to C -- raising several more questions. How (and why) would you convert your Lisp code into C, and what would then be the best uses for this capability?
Oblig XKCD
Hi! I make Firefox Plug-ins. Check 'em out @ https://addons.mozilla.org/en-US/firefox/addon/youtube-mp3-podcaster/
What kind of dumb article is this? Stop living in the past Grandpa.
All the beauty of C syntax with all the conciseness of Lisp:
(int main ((int argc) (char (** argv)))
(sswitch ([] argv 1)
(case ("a" "c")
(printf "The value is \"a\" or \"c\"\n"))
(case "d"
(goto e-label))
(case "b"
(printf "The value is \"b\"\n"))
(case "e"
(: e-label)
(printf "The value is \"d\" or \"e\"\n"))
(default
(printf "The value is neither \"a\", \"b\", \"c\", \"d\", or \"e\"\n")))
(return 0))
"First they came for the slanderers and i said nothing."
Weeping and at gunpoint. ;)
Anons need not reply. Questions end with a question mark.
How (and why) would you convert your Lisp code into C
Well that's pretty easy. There are tons of simple Lisp compilers. Heck building a LISP used to be an exercise for many years included (full source) with Microsoft's C compiler.
A few examples:
http://www.buildyourownlisp.co...
http://howtowriteaprogram.blog...
http://sbcl.sourceforge.net/
http://clisp.sourceforge.net/
A little off topic but a Lisp in Java by a master of the programming craft which is worth looking at: http://norvig.com/jscheme.html
And finally also off topic but the original LISP in assembly: http://www.softwarepreservatio...
In short the way you convert LISP to C is writing a LISP interpreter or compiler.
Yes and no. Yes in that functional programming isn't nearly all it's cracked up to be by its evangelists. No in that there are some applications (mainly in things involving control systems, physics modelling, and a few other niche applications) where Lisp is a much more elegant (read: less spaghetti-prone) way of writing the code, and having a good way to make your academic Lisp usable in real software is a way to make your life easier if you happen to work in one of those domains.
Who's providing internet access to your grave?
Kyoto Common Lisp and its descendants compile into C.
Facebook already did this with PHP. It was called HipHop. But it sucked. Too many issues, and it didnt solve enough issues. Luckily, Facebook started over from scratch, and just built of PHP virtual machine that does JIT compilation instead of needing to compile PHP into C then into machine language, and the result is actually a faster product, which supports more of the PHP language, and is a hell of a lot more stable (still not perfect though)
So, why bother cross-compiling to another language? Just build a LISP JIT VM system. Solve all your problems! :D
It's not a senior project; I graduated 20 years ago[1]. It's a tool I've created recently from some ideas I've seen and had in hopes of realizing something that is more than the sum of it's parts.
[1] Here's my senior project: http://github.com/burtonsamogr... ;-)
Listen to my music.
I'm glad this story got posted and sxc is getting some press, but the real question I asked was:
The idea of using pre-processors to generate C code is not new to programming; but the usage of the full power of Common Lisp in such a natural way is up to the question.
Listen to my music.
It's like the old slashdot rose from the grave one more time... Don't worry kids, tomorrow we'll be back to stories about windmills and mobile phones, I'm sure.
Apparently there is a kind of magic in LISP that is not in other languages. I studied LISP for a while to see if I could get a sense of this magic, but failed miserably - it never clicked, there was never any sense of enlightenment. Is LISP elegant? Not in my eyes. It's a mess of brackets, weird syntax, and strange symbols.
At the same time, the attempts to write software with "C-like words, but with LISP syntax" is almost endearing. "Look, now you can actually have a switch-statement with strings in it!" they proudly exclaim, failing to note that this new statement only exists in their personal version of C, rather than in standard C. Who exactly is the target market for this new type of switch statement? Neither the C community nor the LISP community is likely to want it, since neither side recognizes the syntax they are using in the first place.
According to one of the links, the goal is this: "The syntax is more like C as this is more of a tool that is meant to bring C programmers into the Lisp world rather than pulling Lisp programmers into the C world." To that I say, "good luck with that". But hey, maybe they can get Linus on board and rewrite the entire kernel in LISP-in-C-like-form?