Live data from Hacker News

Why Lisp?

blog.rongarret.info

101–110 of 248 posts

Re: Why Lisp?

#101
post #92

Earlier quoted context omitted.

Let's see, what would I rather deal with. * Another programmer's 15 function API, and a document on how to use it properly? * Or another programmer's 15 function API, along with three macros which use the API properly, and capture all the scenarios I need based on a couple of examples.

generally, even bad api is easier to understand or debug than macro. and not all macros are well written.

Macros being hard to debug may be true of some macro systems that you know.

Not all macros are well written is a poor argument; not all anything is well written ... so don't use anything!

Re: Why Lisp?

#102
post #69
post #52

Earlier quoted context omitted.

I wonder how much macros are necessary one you add call-by-name parameters e.g. scala.

Or, once you have lazy evaluation (like in Haskell), for that matter.

Search down for my comment which contains the substring:

"if I have a non-strictly evaluated language with higher order functions, do I still need macros?"

Re: Why Lisp?

#103
post #57
post #45

Earlier quoted context omitted.

The best you'll get are examples of something solvable in Python being "beautiful" in Lisp. Then some real world Lisp examples will be references to a 20 year old storefront generator and the initial release of reddit. Lisp(s) are certainly better than Python in every way, except when it comes to successful projects completed.

I think you need a bigger reference frame of Lisp's usage over its 50 year history that extends even to 2015. But even then, quoting Kent Pitman: "Please don't assume Lisp is only useful for Animation and Graphics, AI, Bioinformatics, B2B and E-Commerce, Data Mining, EDA/Semiconductor applications, Expert Systems, Finance, Intelligent Agents, Knowledge Management, Mechanical CAD, Modeling and Simulation, Natural Lang…

[deleted]

Re: Why Lisp?

#104
post #71

Earlier quoted context omitted.

"If used judiciously" is just FUD. Soviet-era authority figure: "Western-style freedom has its good points---if applied judiciously". If you're a proper Lisper, you use macros like it's going out of style, and other proper Lispers love your code for it. All programs have their own dictionary of whatever it is they define, whether it be macros or variables. You can no more understand a function call just by looking at…

I guess the "problem" with understanding this perspective for us non-lisp people is that we may not be able to imagine all the places that we could have used macros (or something equivalent) if we haven't even learnt it. You don't know what you don't know, or in this case, you don't know how to use something you haven't used. But this seems to be the same for boatload of programming features that many people aren't t…

Macros are easy to understand if you are shown that whatever language you are using already has them. The difference is that they are locked in and wrapped behind at least two layers.

Firstly, there rigid surface syntax which customizes the look of every macro at the character level. For instance, in C, the do ... while(); loop must have a trailing semicolon. (No Lisp macro has such requirements.)

Secondly, that surface syntax translates to a limited set of abstract syntax tree forms which is not extensible.

Lisp macros open that up. The outer layer of varnish is stripped away, so any conceivable abstract syntax tree form has a notation; you do not have to invent new character-level surface syntax in order to work with a new form. And then, custom recognizers for arbitrary forms can be written by the language users, which do tree to tree transformations.

So then how you use these things once you have them is the same way that yu use the features of programming languages that you know.

E.g. loop is a macro in Lisp. We use it like this:

  [1]> (loop for x from 1 to 10
             for a = 2 then (* 2 a)
             collect (list x a)))
  ((1 2) (2 4) (3 8) (4 16) (5 32) (6 64)
   (7 128) (8 256) (9 512) (10 1024))
Someone wrote the loop macro, so in this situation I'm just a user. I don't care whether this is a macro, or built-in to the language like "foreach x in list do".

When I use loop, I'm benefiting from macro-writing.

The benefits are far-reaching. For instance, language experimentation takes place in the user base, not behind the closed doors of an ivory tower (ISO committee or whatever). Language ideas are packaged as code and shared around.

Technical problems turn into social problems, as someone noted.

Re: Why Lisp?

#105
post #91

Earlier quoted context omitted.

In what language are you writing?

That might be pseudo-code, but Dylan has a similar syntax, like Lisp without the explicit S-expressions.

It seemed a little unfair to be talking about such beautiful and extensible syntax without including the parentheses. But I am unfamiliar with Dylan.

Re: Why Lisp?

#106

The article doesn't discuss macros, which is one of the answers to "Why Lisp?" I didn't "get" macros until I read a footnote in the (freely available) book Practical Common Lisp . In chapter 7, it introduces the `dolist` macro. DOLIST loops across the items of a list, executing the loop body with a variable holding the successive items of the list. This is the basic skeleton (leaving out some of the more esoteric opt…

Could someone please explain the difference between Lisp macros and, say, languages that have first-class functions? I get that a Lisp macro will be expanded into the respective code, while a function's execution is different. However, at the practical (i.e., developer's) level, are there any additional benefits? Can, say, a Lisp macro be 'partially formed', in the sense that it can expand into some boilerplate that…

The majority of macros I write could be represented with HOF and lexically-closed lambdas. That adds significant extra syntax when you use them though.

Consider a classic pattern of a with macro:

    (with-mutex-held-macro (some-mutex) (do-stuff))

    (call-with-mutex-held-hof some-mutex (lambda () (do-stuff))
A minor advantage is that a macro will be expanded in-line; a Sufficiently Smart Compiler could transform the HOF version into something equivalent, so it's not strictly an advantage (except to compiler implementers I suppose).

I think that e.g. generalized references (i.e. the common lisp setf macro) are not possible with HOF, but HOF is more common in pure languages where assignment is eschewed anyway.

Mark Jason Dominus (author of Higher Order Perl) had some good comments on lisp macros as well:

http://lists.warhead.org.uk/pipermail/iwe/2005-July/000130.h...

Re: Why Lisp?

#107
post #37

Earlier quoted context omitted.

One qualitative difference in expressive power comes from the fact that functions first evaluate all their arguments and macros don't.

Ah, but that is not the case in some languages in which arguments are evaluated lazily. Usually the iron-man version of this question is: "if I have a non-strictly evaluated language with higher order functions, do I still need macros?" A part of the answer is: you probably don't need the kinds of macros which cover up machine-generated lambdas, which simulate non-strict evaluation in strictly evaluated Lisp programs…

I'm not entirely convinced.

Which definition of "macro" are you using, if you equate lazy evaluation with a kind of "hardcoded macro"?

More importantly, "it's hard to make a convincing argument that [these hardcoded macros] provide all the expressivity you would conceivably ever need" doesn't convince me. A better argument would be to produce a compelling example where these "macros" are not enough. And by compelling, I mean something that cannot be elegantly produced in a non-Lisp language.

Re: Why Lisp?

#108
post #107

Earlier quoted context omitted.

Ah, but that is not the case in some languages in which arguments are evaluated lazily. Usually the iron-man version of this question is: "if I have a non-strictly evaluated language with higher order functions, do I still need macros?" A part of the answer is: you probably don't need the kinds of macros which cover up machine-generated lambdas, which simulate non-strict evaluation in strictly evaluated Lisp programs…

I'm not entirely convinced. Which definition of "macro" are you using, if you equate lazy evaluation with a kind of "hardcoded macro"? More importantly, "it's hard to make a convincing argument that [these hardcoded macros] provide all the expressivity you would conceivably ever need" doesn't convince me. A better argument would be to produce a compelling example where these "macros" are not enough. And by compelling…

> Which definition of "macro" are you using, if you equate lazy evaluation with a kind of "hardcoded macro"?

That definition of "macro" equivalent with "phrase structure rule in your functional language's compiler" which takes the input structure and generates whatever code brings about the lazy semantics (which is not inherent in the x86 instruction set or what have you).

> example where these "macros" are not enough

An example is any instance of language extension where, say, the maintainers of the compiler for a functional language have to ship a new compiler to the users to get them to use the new feature.

Functional languages with lazy evaluation are not finished, right? They are developed actively.

Re: Why Lisp?

#109
post #91

Earlier quoted context omitted.

That might be pseudo-code, but Dylan has a similar syntax, like Lisp without the explicit S-expressions.

It seemed a little unfair to be talking about such beautiful and extensible syntax without including the parentheses. But I am unfamiliar with Dylan.

Well, typing parens in a HTML textbox can be pretty tedious, so I understand the desire for pseudocode.

Dylan has an interesting hygienic macro system that's similar to Scheme's. I don't think Dylan allows for arbitrary code-generating macro procedures, but it's possible in principle; see [1].

[1]: https://people.csail.mit.edu/jrb/Projects/dexprs.pdf

Re: Why Lisp?

#110
post #65

There are certainly good reasons why lisp is the way it is. I dislike reading that style of code, though. I don't like how you have to read it in a strange sort of top-to-bottom-but-also-inside-out way (really this happens in all languages but it's especially bad in lisp because there are no infix operators and so forth), and of course the common gripe about all the parens. And to be honest, I am not really intereste…

Clojure has a threading macro built in ( http://clojuredocs.org/clojure.core/-%3E ) which lets you write code like : user=> (-> "a b c d" .toUpperCase (.replace "A" "X") (.split " ") first) It is trivial to write the macro in other Lisps.

This is one of the nicest macros - chaining with sane return semantics and no overhead/boxing required. Breaks my heart trying to replicate it.
Post reply on HN