News for hackers. Stuff that matters.
Re:Why Lisp macros are cool, a Perl perspective (2005) by randomwalker on Monday August 31, 2009 @12:14AM (#795418)
Even for those who don't need to be sold on Lisp macros, that was worth reading just for this sentence (in reference to C++ macros):

I forgot what rabid programming language fans are like; they can and will defend any system, no matter how dysfunctional, as long as it's _their_ dysfunctional sytem.

:-)

Re:Why Lisp macros are cool, a Perl perspective (2005) by SwellJoe on Monday August 31, 2009 @05:14AM (#795632)
Higher Order Perl is a fantastic book, which makes a lot of functional concepts more immediately usable for non-Lisp dynamic language programmers (the example language is Perl, but there are projects on the web to convert the examples to other languages; the concepts apply across most of the popular dynamic languages).
Re:Why Lisp macros are cool, a Perl perspective (2005) by aufreak on Monday August 31, 2009 @02:57AM (#795545)
Here is a link to the section on "what makes lisp different" that is referred to in the article -

http://bit.ly/8yrvC

Re:Why Lisp macros are cool, a Perl perspective (2005) by Scriptor on Monday August 31, 2009 @12:47AM (#795453)
Question about the code:

  (defmacro set-sqrt (place v) `(setf ,place (* v v)))
What does the comma right before place in its second usage signify?

Also, am I right in assuming that setf turns:

  (setf (f1 arg1) arg2)
into

  (setter-for-f1 arg1 arg2)
Re:Why Lisp macros are cool, a Perl perspective (2005) by abecedarius on Monday August 31, 2009 @12:57AM (#795461)
The comma means to use the value of place there, instead of the literal symbol 'place'.

(Ironically, MJD made one of the same mistakes there he complained about in his C examples -- mentioning 'v' twice, which makes any side effects happen twice. Lisp macros are better than C's, but still require some care.)

defsetf turns that expression into whatever the defsetf expander for f1 returns -- it's up to the code.

Re:Why Lisp macros are cool, a Perl perspective (2005) by masklinn on Monday August 31, 2009 @04:56AM (#795623)
> What does the comma right before place in its second usage signify?

It "punches a hole" in the quote: the ` in `(setf ,place (* v v)) says "don't evaluate this, this is a litteral value/list", but then the comma indicates "actually evaluate just this expression right here within the definition context" so ,place will be replaced by the value of the place argument. It's kinda equivalent to #{} in Ruby strings.

As others have pointed out, v should probably be unquoted as well.

Re:Why Lisp macros are cool, a Perl perspective (2005) by scott_s on Monday August 31, 2009 @09:53AM (#795895)
Ah, thanks for that. In Perl and shell scripts, it's the equivalent of $ - that is, "my name is $name".
Re:Why Lisp macros are cool, a Perl perspective (2005) by aufreak on Monday August 31, 2009 @03:02AM (#795547)

  (defmacro set-sqrt (place v) `(setf ,place (* v v)))
should actually be

  (defun square (x) (* x x))
  (defmacro set-sqrt (place v) `(setf ,place (square ,v)))
Re:Why Lisp macros are cool, a Perl perspective (2005) by smanek on Monday August 31, 2009 @12:58AM (#795465)
The comma 'unquotes' the place variable so it is replaced with the value passed to the first argument on set-sqrt. I'm not in front of a lisp interpreter, but I think both those v's should be unquoted too in order to get the expected behavior ... (plus they are a bit leaky since they are evaluated twice, but that's just being pedantic).

Read http://www.gigamonkeys.com/book/macros-defining-your-own.htm... for a more thorough explanation.

As for setf, a user can create arbitrary 'setters' using syntax like that described at http://gigamonkeys.com/book/object-reorientation-classes.htm...

Re:Why Lisp macros are cool, a Perl perspective (2005) by tumult on Monday August 31, 2009 @02:12AM (#795512)
I'm not a CL guy so I don't know how defsetf actually works, but I skipped down in that link to where that Lisp macro is, and if defsetf works like he describes (and I don't know if it does), then

    (setf (f1 arg1) arg2)
will cause an error, but

    (setf (sqrt arg1) arg2)
will expand into

    (setf arg1 (* v v))
which, as you can see, is nonsensical in terms of what it looks like he was trying to do.
Re:Why Lisp macros are cool, a Perl perspective (2005) by diiq on Monday August 31, 2009 @10:40AM (#795988)
Yes, as has been pointed out, he is missing a pair of commas (or more correctly, a patch to ensure that v is evaluated once and only once --- right now it is evaluated 0 times, and adding 2 commas would make it eval twice. Using the definition of (square x) is the cleanest way to fix this).
Re:Why Lisp macros are cool, a Perl perspective (2005) by lhorie on Monday August 31, 2009 @09:48AM (#795888)
The way I memorized it was to associate it with #{...} in ruby:

  def my_gimme(thing)
    gimme "select #{thing} from something"
  end
Of course, in lisp, the "interpolation" (and macros in general) is structural: you can't use malformed strings to inject unexpected code like you could in my silly example.

Incidentally, Stuart Halloway uses this same Ruby syntax as pseudo-code when he first introduces macro syntax in his Programming Clojure book.

Re:Why Lisp macros are cool, a Perl perspective (2005) by swolchok on Monday August 31, 2009 @10:52PM (#797231)
As a non-Lisper:

In short, macros are cool because, instead of hacking the compiler and groveling through its weird data structures to add language features, you can add language features in the language itself, because the language is already traditionally expressed in parse trees. Phrased this way, I don't see why this is a life-changing revelation.

Re:Why Lisp macros are cool, a Perl perspective (2005) by bkovitz on Monday August 31, 2009 @10:49AM (#796004)
And yet, still no example of a useful macro.

In C++, you already have assignment. You don't need to roll your own.

Re:Why Lisp macros are cool, a Perl perspective (2005) by tel on Monday August 31, 2009 @11:21AM (#796075)
Re:Why Lisp macros are cool, a Perl perspective (2005) by masklinn on Monday August 31, 2009 @06:26PM (#796859)
> And yet, still no example of a useful macro.

http://en.wikipedia.org/wiki/CLOS

Re:Why Lisp macros are cool, a Perl perspective (2005) by dstein64 on Friday September 04, 2009 @12:22AM (#804273)
Is there any significance to the "=3D" in his code, or are those the same as the normal equal "="? Thanks.
Re:Why Lisp macros are cool, a Perl perspective (2005) by benatkin on Monday August 31, 2009 @05:11AM (#795629)
For a long while I've thought that Randall Schwartz was the author of Higher Order Perl. Oops.