Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Help me understand common lisp macros

Name: Anonymous 2009-10-24 15:36

What can common lisp macros do that can't be done by a function that uses eval and gets quoted arguments?

Name: Anonymous 2009-10-24 15:46

Code like a motherfucker.

Name: Anonymous 2009-10-24 15:47

I mean you can define

(define (myif pred ifstate elsestate) (eval (list 'if pred ifstate elsestate)))

and then call it like so:

(myif '(> x 1) '(+ x 3) '(- x 2))



so what else can lispmacros do?

Name: Anonymous 2009-10-24 15:53

Macros are just ordinary functions which transform one form to another, parameter parsing being done through something similar to destructuring-bind, and the form is passed quoted. The thing about macros is that they happen at macro-expansion time, which can happen during compilation or evaluation and in other strange combination of phases. If your Lisp was interpreted and not compiled in any way, you could just use F-Exprs (which call EVAL directly), but they're usually bad ideas, especially for compiled code(and almost all Common Lisp code can be compiled - even if you don't compile, the minimal compilation includes macroexpansion): http://www.nhplace.com/kent/Papers/Special-Forms.html

Macroexpansion by itself means code generation - which means that you only get normal code that can run or be compiled in the end (however your macro could perform some side-effects on the running image, but wether that is a good thing or not is another thing).

tl;dr: Compilation is important in common lisp, and macros allow easy and efficient code generation. Eval matters only for fully interpreted code. Some Lisp implementations don't even have a real EVAL, it's just a COMPILE called on a lambda thunk.

Name: Anonymous 2009-10-24 15:55

And I've forgotten to mention, macros can expand within an environment, while EVAL expands in a NULL lexical environment - this has many implications and it also means EVAL is limited in certain ways (unless external symbols that you need are declared special).

Name: Anonymous 2009-10-24 15:57

>>3
Another thing about macros is that debugging them is much more nicer than debugging F-EXPR's (basically what you want to do). You can macroexpand any macro you want within whatever lexical context you want, which makes macros pretty transparent about their workings. You should try doing it in Emacs+SLIME to see how nice it is.

Name: Anonymous 2009-10-24 15:58

>>3
Please use [code] tags. Thank you.

Name: Anonymous 2009-10-24 16:02

thanks for the explanation

Name: Anonymous 2009-10-24 16:20

programming related discussions make me sick

Name: Anonymous 2009-10-24 16:39

>>9
So you're the one responsible for the declining quality of threads on here for the last 3 years...!

Name: Anonymous 2009-10-24 18:37

>>1
They can avoid slow calls to EVAL, they can avoid the need for lots of quoting when called, and they can let the programmer actually refer to variables. If you'd taken 30 seconds to try >>3 in CL, you would have found that it doesn't work.

Name: Anonymous 2009-10-25 3:27

>>11

Of course it doesn't work in CL, it's scheme code.

Name: Anonymous 2009-10-25 7:09

What a shit explanation.

1) FEXPRs are fucking slow. Macros do the actual work, consing like there's no tomorrow and doing expensive stuff - generic function dispatch that comes with abstraction. They expand into code that doesn't even have to require the system containing the macro, thus reducing image bloat.

2) Macros can use lexical environments (and i'm not talking about environment objects, which in ANSI can't even be augmented or introspected upon. And not much except SBCL implements CLtL2 with their &env goodness. See how much hoops CL-WALKER has had to go through to do simple quasi-"portable" macroexpansion). Special variables by default sucks, as it:

- Fucks up referential transparency. Leads to spaghetti code clusterfuck.
- Is slow, as can't be reduced to register access.
- Compiler can't prove properties about the code, e.g. type inference if anything can be modified anywhere

Runtime-based lexical access is fucking slow - see Ruby (though Ruby sucks on many more levels). Runtime-modifiable lexical access sucks even moar - leads to spaghetti code like dynamic-by-default.

And in SBCL TLS indices don't get recycled. So don't plan on using PROG with uninterned symbols and expecting it to work still after using over 8192 uninternet symnols. Try: (loop repeat 8192 (prog (list (make-symbol "chuj dupa cyce")) '(42) nil). Untested as there's no REPL nearby.

Name: Anonymous 2009-10-25 7:16

Oh, and OP looks like a newLISP troll. Kazimir Majorinc perhaps?

Name: Anonymous 2009-10-25 7:38

>>1
Lisp macros can't do anything that can't be done with eval. In fact, Lisp can't do anything a program written in assembly that writes programs that write programs can't, so just use assembly.
.
.
.

Get it yet OP?

Name: Anonymous 2009-10-25 7:43

Let me dispel these wild and irresponsible rumors. If mere turing-completeness did the trick, people wouldn't even write in assembly. They'd write in the turing-machine instruction set. So at least there /appears/ to be /some/ difference.

Read that dickwad graham and stop trolling newfags.

Name: Anonymous 2009-10-25 7:45

>>16
Let me dispel these wild and irresponsible rumors.
let me troll

If mere turing-completeness did the trick, people wouldn't even write in assembly. They'd write in the turing-machine instruction set.
I don't get what point >>15 made

So at least there /appears/ to be /some/ difference.
The point >>15 made

Name: Anonymous 2009-10-25 7:47

And get your learnings on c.l.l <http://groups.google.com/group/comp.lang.lisp/topics?lnk=srg>; instead of this zerovoid-infested hive of scum and villainy.

They don't even anally rape newfags - in fact, they need you to continue spreading The Truth after they die.

The community makes cliki pages about my shit libraries as soon as i release it and it ain't scared of anything.

Name: Anonymous 2009-10-25 7:47

Oh it's frozenvoid. Whatever.

Name: Anonymous 2009-10-25 7:52

>>18
And get your learnings on c.l.l
Usenet is full of morons. You're 20 years late.

instead of this zerovoid-infested hive of scum and villainy.
this is the land of the EXPERT PROGRAMMERS, you silly qunt!

They don't even anally rape newfags - in fact, they need you to continue spreading The Truth after they die.
I've got better things to do than being a mirror-moron on usenet.

The community makes cliki pages about my shit libraries as soon as i release it and it ain't scared of anything.
Which libraries?

Name: Anonymous 2009-10-25 8:01

>>17

That's a question from a newfag. It's not the Literal Wish spell where the goal is to provide the least-helpful answer to the query.

Every time a newfag asks about EVAL they need to learn macros. Using EVAL makes sense when the expression actually has to be compiled/interpreted at runtime. Not in some shit case like MY-IF that evaluates its arguments. Most newbies make such shit mistakes as can be evidenced by c.l.l. archives.

Even if the use of EVAL/COMPILE is warranted, unless there's some memoization/caching involved don't even think of compiling it in the critical path.

Name: Anonymous 2009-10-25 8:13

>> 20

Last time i ran gnus there were only a few, if prersistent, parasites with their overwhelming sense of entitlement.

- Xah Lee, a batshit insane ADHD-ridden gook immigrant crossposting shit and actually getting gullible oldfags (!) responsing to his offtopic shit and flames.
- Certain Clojure evangelist, who has since backed down after we told him we don't take kindly to his Java apologism.
- newLISP fags, who since went back to their web-2.0 BBSes with CSS, AJAX and rounded corners.
- Toady, who finally realized that no one wants to buy his shit ocaml books and no one buys into his bullshit about how "lisp has no pattern matching" and  "static typing is a clear win for productivity".

There are also places like #lisp, where oldfags actually anally rape newfags when they can't recite CLHS and AMOP by heart. And also quite "polite" (in the Naggum sense) like slime-devel and sbcl-devel. See the gmane hierarchy.

Which libraries?

The ones i wrote and people use. I won't use my real name here, of all places.

Name: Anonymous 2009-10-25 9:41

You can make a macro that does infix math, I suppose.

Name: Anonymous 2009-10-25 10:26

>>15 here. Let me clear up things:

>>1
Everything that can be done with macros can be done with eval. Everything that can be done with eval can be done with the rest of the lisp language. The language can be downed to a set of axioms; These actioms, among other things, make that particular lisp a turing-complete lisp. Just because turing-completeness is sufficient for meta-programming does not mean you should ignore every feature that quickens the development process of meta-programming. In fact, meta-programming is exactly about saving time from humans writing programs, because it is about programs writing programs. Whoever tries to distinguish between eval/macros either does not understand the issue or has listed a few minute differences between the two in certain cases (which can still be "solved" - you can fully emulate the power of macros with eval, yes).

>>22
Last time i ran gnus there were only a few, if prersistent, parasites with their overwhelming sense of entitlement.
I disagree. I think usenet is full of idiots.

- Xah Lee, a batshit insane ADHD-ridden gook immigrant crossposting shit and actually getting gullible oldfags (!) responsing to his offtopic shit and flames.
I know what you mean by "gullible oldfags": a set of people, different to every group, which is the de facto authority around; they're the cream of the crop in terms of knowledge of the topic/subject, and they spend a fair amount of their time answering questions and participating in useless flamewars and lengthy discussions passing the pedant ball to each other. Presumably you admire these people (they must've at least made an impression to you) because they have acquired this knowledge; but the truth is they're just repeating what has been said. What they do isn't hard at all, try to stay to a newsgroup for some time following the discussions and you'll find out they're mostly debating over the same bullshit, regardless of the source, which may be a troll or a genuine message. They're wasting their time; they're idiots.

- Certain Clojure evangelist, who has since backed down after we told him we don't take kindly to his Java apologism.
Oh great, you already defend the group and consider yourself part of it. Another one stuck with the idiots.

>>23
You can, it has been done.

Name: Anonymous 2009-10-25 13:48

>>24

Yeah, macros can be implemented by writing a code walker and a macroexpander. Then replacing EVAL with one that macroexpands recursively, only to call the "real" eval. But what's the point? Requiring every user to implement macroexpansion on their own thus ensuring that they give up and go back to Python?

but the truth is they're just repeating what has been said.

Some people actually did pretty intense shit. To keep it from being tl;dr enough to say that among IRC and Usenet denizens are people who participated in the RnRS and ANSI CL process, do some hairy shit no one else wants to do (closeness to MOP), develop compilers/VMs, bought Symbolics hardware before owning it became a fashion statement, etc.

Hard to be admired, though. These people are unlikeable, "polite" in the Naggum sense and dare mention it lest be flamed for being a "people person". Better be as laconic as possible and only say something after thoroughtly checking that it's true. Part of it is not saying shit like "IMO" or "probably" when addressing technical matters. Say something stupid and feel being silently judged with implicit DECF of yer karma meter. These people are hard to admire. And they either have really good long-term memories and keep lists of grievances, real or implied. Just kidding!

Oh great, you already defend the group and consider yourself
part of it. Another one stuck with the idiots.

Heh, no. Forgot the sarcasm tag. Meant to imply that attempts at balkanization were met with dozens of passive-aggressive thinly-veiled references toward "GTFO".

But yeah. This isn't a /typical/ programming community. Not like the Perl one that answers how to map over an array for the millionth time. It's kind of like a cult, people convinced that Lisp is The Answer to all problems in computer science, and if it's not, it's because no one thought of the most elegant syntax for expressing data-sets of all of CS' problems. How much of it is realized through brainwashing (L. Ron Graham and his self-help books, "peer" pressure, alienation with the Algol-inclined mainstream) and how much through individual conviction and deliberation (CLHS, Symbolics Genera, CLIM) is left as an exercise to the reader.

Name: Anonymous 2009-10-25 13:49

Oh, and MJD well summed up us lispniks thar: <http://perl.plover.com/yak/12views/samples/notes.html#sl-39>;.

Name: Anonymous 2009-10-25 14:52

Name: Anonymous 2009-10-25 14:53

>>27
mai waifu ;_;

Name: Anonymous 2009-10-25 15:37

>>12
Port it, dipshit.

Name: Anonymous 2009-10-25 15:40

>>26
With a cherry-picked example and a pack of lies?

Name: Anonymous 2009-10-25 18:07

>>13
"chuj dupa cyce"
( ≖‿≖)

Name: Anonymous 2009-10-25 18:09

>>31
(ಠ‿ಠ)

Don't change these.
Name: Email:
Entire Thread Thread List