9 ms·
Why Lisp macros are cool, a Perl perspective (2005)
- dang 7y agoA thread from 2018: https://news.ycombinator.com/item?id=17990114 https://news.ycombinator.com/item?id=17990114 2014: https://news.ycombinator.com/item?id=8698074 https://news.ycombinator.com/item?id=8698074 2012: https://news.ycombinator.com/item?id=4246143 https://news.ycombinator.com/item?id=4246143 2009: https://news.ycombinator.com/item?id=795344 https://news.ycombinator.com/item?id=795344
- Y_Y 7y ago2022: https://news.ycombinator.com/item?id=32644851 https://news.ycombinator.com/item?id=32644851
- giancarlostoro 7y agoI know you're being funny but it's part of the community culture to always link to prior discussions cause they might spark continuing discussion and extended context to the article.
- RHSeeger 7y agoI didn't read it as mocking the people posting previous discussions. Rather, I read it as saying "and it'll be discussed again... it always is".
- giancarlostoro 7y agoWell thats kind of a given for posts with so many repeated prior discussions.
- labster 7y agoI hope you've written a script to make this happen. If not, well, you've got a whole year. It will be a little harder because the story and comment ids are all mixed together, you really have to poll a lot to claim the right id number.
- philipov 7y agoIs this the answer to a "Find the next number in this sequence" joke? What's the formula?
- senorsmile 7y agoThis reply only exists to remind myself to come back to see what it actually points to in 2.1 years.
- B1FF_PSUVM 7y agoUnpopular opinions, CLVII: Sturgeon's law applies to macros. Squared.
- RHSeeger 7y agoBeing able to write new control structures is something I miss in most languages. Lisp macros make it much easier to do that. Tcl uplevel and upvar are another way to approach it.
- LessDmesg 7y agoCurious: what kind of new control structures do you miss in other languages?
- bjoli 7y agoDelimited gotos. Many lacks proper looping constructs. CL has a package a macro that gives you a limited version delimited continuations which are handy for some situations.
- RHSeeger 7y agoA good example would be a case switch, that ran the first block that evaluated to true (lisp has this, many languages don't). That being said, custom control structures can abstract away some things.
- stevelosh 7y agoThis would save me literally thousands of lines of code at my day job: (defmacro ?= (symbol-or-symbols expr) (let* ((symbols (etypecase symbol-or-symbols (cons symbol-or-symbols) (symbol (list symbol-or-symbols)))) (tmps (loop :for s :in symbols :collect (gensym (symbol-name s)))) (err (gensym "ERROR"))) `(multiple-value-bind (,@tmps ,err) ,expr (if (not (null ,err)) (return ,err) (setf (values ,@symbols) (values ,@tmps))))))
- comex 7y ago
- Rerarom 7y agoWhat curious newbies might miss from discussions of macros is that they are a separate language operating at compile time. They are usually advertised as code operating on itself or something like that. They're not. Powerful, yes, but not that cool.
- procparam 7y agoA separate language? How do you mean? This is one of the big advantages of Lisp macros over C macros. In Lisp you write macros using Lisp, including normal user-defined functions. In C, on the other hand, you write macros using "C Preprocessor directives"
- Rerarom 7y agoYes, of course, I get that it has the same syntax, which is not the case with C macros and which makes macros way better. Thing is, there is one Lisp that executed at compile time which expands the macros, and then there is the resulting code which executed at runtime. It's not self-modifying code. It's just code that operates on some other code, written in the same syntax.
- btilly 7y agoWhatever artificial division you believe exists between "compile time" and "run time" in Lisp is almost certainly your misunderstanding, and does not reflect how the language actually works.
- threatofrain 7y agoPerhaps I could use some clarity on this matter too, and hopefully with a bit of gentleness. As I understand it, some Lisps do have an explicit compile phase and there is discussion among the language users over the runtime cost of macro abstractions. https://docs.racket-lang.org/guide/stx-phases.html https://docs.racket-lang.org/guide/stx-phases.html I understand there may be some philosophical or theoretical interest in framing Lisp the way you do, but does that invalidate the close-to-the-app thinking about the costs of macros and where those costs are distributed?
- valw 7y agoI wrote a blog post making a similar point with Clojure as an example: https://vvvvalvalval.github.io/posts/2018-01-06-so-yeah-about-clojures-syntax.html https://vvvvalvalval.github.io/posts/2018-01-06-so-yeah-abou... The core ideas are timeless really, but the examples might be a bit more relatable today. I'm reproducing the ToC here: 1. Does syntax matter? 2. The ingredients of Clojure's syntax 2.1 Data literals 2.2 Macros 3. Consequences 3.1 Verbosity is a solved problem 3.2 Separation of concerns: code layout ⊥ program structure 3.2.1 Example: the Builder Pattern 3.3 Code = Data = Data Viz 3.4 Tooling as libraries 3.5 An 'all-tracks' language: embedding paradigms 3.5.1 Example: Web UIs 3.6 Saner language stewardship 4. Summary
- overgard 7y agoI don't think Lisp is ugly or anything, but part of me wonders if, in languages with syntax, the lack of expressivity is a feature rather than a bug. Partially because wrong things look wrong, if the syntax is intelligently designed. The setx example he gave seemed perfect in that respect, while it's superficially pretty neat, the maintainer in me started to think about what it would be like to debug that, or all the horrible ways it could act slightly different than you'd expect. I kind of like that assignment in the languages I use is really boring for the most part. I dont think that setf example is a footgun per se, but, I would have to look at it more closely than in another language like python.
- kyllo 7y agoThe best thing about a highly expressive language is that you can do anything you want to. The worst thing about a highly expressive language is that you can do anything you want to. Expressive power vs. intelligibility (for the sake of common convention and communication in a team setting) is a real tradeoff, and the "principle of least power" does partially explain the popularity of slightly less-powerful languages like Java, Python, and Go, where there is generally just one idiomatic pattern for accomplishing a given task.
- jacobush 7y agoI have done some Real Work ™ in Lisp, but dear deity, Forth... that to me really is you can do anything you want to - in such a scary way I have never worked up the courage to actually learn it.
- astrobe_ 7y agoIf you go full Forth you start with writing your own interpreter, so what you are scared of is really your own shadow. And that's one of the qualities of Forth: to stop worrying, stop being scared of yourself, stop being scared of the future... Or more precisely it learns you to fear the right thing: namely the Great Evil of Accidental Complexity, which often disguise itself as necessary evil.
- ragebol 7y agoWhat's with the `=3D` all over the place? I tried searching for it but that doesn't do much useful unfortunately.
- hnick 7y agohttps://stackoverflow.com/questions/4016067/whats-a-3d-doing-in-this-html https://stackoverflow.com/questions/4016067/whats-a-3d-doing... Basically: it's a form of escaping, and like other forms of escaping the escape character itself has to be represented as an escape sequence. So in other languages where \ is the escape character, you have to put \\ to represent an actual slash rather than the start of an escape sequence. Here = is the escape character followed by the hex of the character, so to represent a literal = it needs its own hex value 3D after it.
- thomaslee 7y agohttps://en.wikipedia.org/wiki/Quoted-printable https://en.wikipedia.org/wiki/Quoted-printable Note that 0x3D is the "=" character in ASCII, so "=3D" in QP is "=" in ASCII. :) This email has probably been through a few conversions to QP and back again between different email clients. Perhaps some buggy client got confused between an ASCII "=" and a QP escape sequence or something like that.
- ragebol 7y agoRoughly what I expected, TIL, thnx
- deleted 7y ago[deleted]