burtonsamograd / sxc

sxc is an 'S-Expression C' transpiler for generating C code using macros written in Common Lisp
212 stars 10 forks source link

Related projects for macros on C-like languages #3

Open qwertie opened 7 years ago

qwertie commented 7 years ago

Hey there, I saw this on Slashdot, congratulations on being noticed. I've been working on another approach to the problem of adding lisp-like macros to C-like languages. It's part of a work-in-progress multi-language architecture... which is not that important except that my system doesn't support C at the moment, only C#, and I'm trying to figure out how to find volunteers to help expand the idea to multiple languages.

My system is based not on s-expressions themselves but an idea inspired by s- expressions, called Loyc trees. Loyc trees are isomorphic to s-expressions except for a side- channel called "attributes", so in principle Common Lisp macros could run on Loyc trees representing languages like C that have little need for attributes. I've never actually programmed in Lisp though, so I haven't explored that idea. Instead I built my own macro processor called LeMP which has a bunch of handy built-in macros, some of which are designed for C# and others that would be useful in any language.

A key difference in my approach is that instead of expecting people to program in s-expressions, I've made a richer C-like language called LES... And for C# I also designed an enhanced parser that provides a bunch of new syntax that is useful for macros. Likewise or would be nice to find people to create modified parsers for other languages, like C, or even unmodified parsers whose output trees can be converted to loyc trees.

I don't know your motivations for building sxc - What are they? - but depending on what they are, maybe some of my work could interest you. So, that's just fyi. Merry Christmas Happy Holidays!

burtonsamograd commented 7 years ago

My motivations for creating sxc are to combine two languages together that I am both very familiar with and see what the combination could allow during the creative programming process. During my writing of the tool I was directly translating the code of K&R into the syntax of sxc but had put little thought into any new types of macros that could be made other than regular substitutions. The macro 'sswitch' was as far (and simple) as I got in the process; something that shows that making C 'programmable' using macros could lead to some benefits with overall code 'beauty' through the elimination of repetitive patterns and leading to a more declarative (rather than procedural) style of programming in C, much like one strives for in Lisp.

Loyc trees seem interesting. Thank you for the pointer.

qwertie commented 7 years ago

Okay, well, check out the master list of macros for inspiration... most of the same features would be useful in C, I think.

burtonsamograd commented 7 years ago

What is the difference between Loyc trees and Common Lisp symbols along with property lists and lists, as a generalization of the information contained with the Loyc tree?

qwertie commented 7 years ago

Hey, sorry I didn't notice your message until a couple of days ago - when I didn't have internet access. Perhaps you gathered the answer from our FB discussion? I must admit I had not encountered the idea of a property list until just now, and LES / Loyc trees have no corresponding concept, as LES and Loyc trees do not (formally speaking) use symbol tables of any kind. An identifier (or 'symbol' in CL terminology) is defined as a sequences of characters (or bytes, in the case of LESv3) that we call an "identifier". Symbol tables, such as property lists, are something one would build on top, separate from LES and Loyc trees

(mind you, the implementation of Symbol in .NET allows "custom" symbols, with which one could, I suppose, implement Lisp-like property lists.)

qwertie commented 7 years ago

In practice, it's sensible for an implementation of Loyc trees to share symbols. Two references to an identifier called foo would have two separate Loyc tree nodes (in order to keep track of the two different source code locations where foo appears), but they may share the same symbol, if only to avoid duplicating the string "foo". A Lisp implementation of Loyc trees would probably use Lisp's built-in concept of symbols.