Hacker News new | comments | show | ask | jobs | submit login
Lisp or a pre-processor?
3 points by demallien 1423 days ago | hide | past | web | 4 comments | favorite
We see many (many!) items on HN talking about the advantages of Lisp, but as is noted in nearly every Lisp thread, Lisp has never really been able to gain much traction.

In those discussions, Lisp has two wildly touted advantages: 1) it is a functional language, encouraging programmers to avoid state. 2) Lisp macros are a powerful tool that allows programmers great power in creating control structures.

These are definately two significant advantages, but the come with a couple of equally large inconveniences. 1) Lisp does not have the same quantity of libraries that you can find for other languages, and 2) there just aren't a lot of Lisp programmers out there.

My current solution to try and square the circle is to use a mixture of a higher level language (typically Lua or Javascript) with a good tool for generating bindings to low-level C code. This is a very productive solution, but it does introduce a performance penalty (although this has been getting smaller as time goes by).

This has lead me to start pondering about another solution - creating a custom version of C with a programmable pre-processor to convert it to standard compliant C. This introduces the same sort of flexibility that Lisp macros provide, and can even make concurrency problems easier to handle by making it easy to introduce Erlang-style actors.

Has anyone on HN gone down this path already? If you have, how did it work out? What were the pitfalls? And what system did you use for parsing your custom C?

Note that DSLs for C are a well-trod path, from lex and yacc to some mix-SQL-and-C tools. Also consider the number of compilers emitting C.

Also, are you aware of http://p99.gforge.inria.fr/p99-html/?

(Neither of those are what you're asking for, but they do partially solve the problem you're trying to solve.)

Have you looked into Clojure? It is a Lisp dialect with JVM integration. It has a reasonable sized library ecosystem, and the interop functionality would allow you to use the existing ecosystem of Java libraries where native libraries do not yet exist.

Wouldn't you need less syntax than C has and homoiconicity to be able to have a macro system like lisp?

Isn't this the main reason why the C preprocessor couldn't become as powerful as LISP macros?

No, the preprocessor in question is a full parser. If you can express the syntax you want with a formal grammar, the parser can handle it.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact