News for hackers. Stuff that matters.
Re:Just what does “code as data” mean anyway? (2014) by tombert on Friday February 16, 2018 @09:54AM (#16392700)
When I was first learning C, I wondered the point of macros; especially with inline functions.

It wasn't until I taught myself Racket and Clojure a few years later that I realized the utility, and it was immediately one of those "the world is different now" moments; I could actually augment the language without having to contribute to the core compiler.

Re:Just what does “code as data” mean anyway? (2014) by carlmr on Friday February 16, 2018 @09:55AM (#16392709)
It's very nice, but with great power comes great responsibility. Some people program so many things with C macros that it becomes very hard to read their code.
Re:Just what does “code as data” mean anyway? (2014) by zeveb on Friday February 16, 2018 @10:53AM (#16393165)
That's the beauty of Lisp: it's all very readable, because it's a real language, not a string-substitution preprocessor.

Yes, any idiot can write unreadable Lisp — but good Lisp is a work of art. The Art of the Metaobject Protocol should be required reading: it builds an entire object system, complete with classes and generic functions (multimethods), written in the language itself. It's a tour de force.

Re:Just what does “code as data” mean anyway? (2014) by metaobject on Friday February 16, 2018 @01:07PM (#16394329)
And I'm just pointing this out for those who aren't already aware -- C macros and Lisp macros aren't really comparable.

C macros are implemented as string substitutions in a separate step before compilation. Lisp macros can make use of the rest of the language features and allow for operations on the abstract syntax tree of the code, opening up things like adding new control constructs, generating boilerplate code, string substitution, and the creation of domain specific languages.

Re:Just what does “code as data” mean anyway? (2014) by yetanotheruser on Friday February 16, 2018 @10:00AM (#16392754)
I'm still wrapping my head around macros, but I have been able to come up with a couple use cases that I quickly realized were already covered by existing macros, the most recent one being a less flexible -> macro.

Anyways, I kept reading places that lisp macros and c macros were completely distinct, which seems untrue after a couple years of trying clojure.

Re:Just what does “code as data” mean anyway? (2014) by kbp on Friday February 16, 2018 @11:22AM (#16393410)
> I kept reading places that lisp macros and c macros were completely distinct, which seems untrue after a couple years of trying clojure.

They're similar in that they're both compile-time functions that generate code, but they're very different in practice, because C macros are written in a text substitution language that knows virtually nothing about C, which naturally makes writing even simple macros very error-prone. Lisp macros, on the other hand, are written in plain old Lisp and receive regular Lisp data structures that you can use the whole language to operate on.

A lot of people learn from C that macros are very difficult to get right, so it's important when they move to Lisp that they give them a second look, because Lisp is a much more capable language for code transformation than cpp.

Re:Just what does “code as data” mean anyway? (2014) by yetanotheruser on Friday February 16, 2018 @01:53PM (#16394793)
Right, that makes sense
Re:Just what does “code as data” mean anyway? (2014) by flavio81 on Friday February 16, 2018 @11:14AM (#16393353)
>Anyways, I kept reading places that lisp macros and c macros were completely distinct, which seems untrue after a couple years of trying clojure.

I haven't used Clojure macros but as a programmer that uses both C and Common Lisp, I can say with good authority that C macros and CL macros are very different.

Re:Just what does “code as data” mean anyway? (2014) by yetanotheruser on Friday February 16, 2018 @06:44PM (#16397662)
Yea, not the same. Similar motivations though, right?