Re: macros
From: Pascal Costanza (costanza_at_web.de)
Date: 08/14/04
- Next message: Richard Fateman: "Re: symbolic algebra lib"
- Previous message: rem642b_at_Yahoo.Com: "Re: OT: writing resumes with VT100 for a Lisp job"
- In reply to: Frank Buss: "Re: macros (was: Paul Graham's teaching style is bad}"
- Next in thread: Marco Parrone: "Re: macros"
- Reply: Marco Parrone: "Re: macros"
- Reply: Frank Buss: "Re: macros"
- Reply: Marcin 'Qrczak' Kowalczyk: "Re: macros"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 14 Aug 2004 20:22:40 +0200
Frank Buss wrote:
> Peter Seibel <peter@javamonkey.com> wrote:
>
>>But you could argue that this is really a lisp-1 vs lisp-2 problem. A
>>better example, I think, would be something like with_open_file. I
>>want to be able to write:
>>
>> with_open_file(in, "filename") {
>> /* Do stuff with 'in' */
>> }
>>
>>and have it mean, open "filename" and make 'in' the variable holding
>>the stream and automatically close it when we reach the end of the
>>block.
>
> This is not a better example, at least not for C++, because every C++
> programmer would write it this way, with a local variable:
>
> {
> ifstream in("filename");
> /* Do stuff with 'in' */
> }
>
> At the end of the block, or even at a return within the block, "in" is
> destroyed and the close method is called on it.
I don't think this is a valid counter example, because you are just
reusing a feature that someone else has implemented for you. The
question is how to create that feature in the first place. However, I
think there are again some counter arguments to that position, so I
don't want to go into too much detail here.
Instead, I propose another challenge. How do you implement the following
in C#++@!&^%?
aif int test_result = some_test() {
...
} else { ...
}
If the test succeeds (resulting in something other than 0), the first
block is executed. In that block, the variable test_result (or whatever
name the programmer wants) is visible and bound to the test result.
Otherwise, the second block is executed, and that variable is not
visible. Bonus points if you don't need to surround those blocks by
curly braces, but instead can also use single statements. I don't care
if you have to add parentheses or semi-colons at random places to make
this work. ;)
(I don't say this is impossible or only possible in inelegant ways. I
don't know about all the various preprocessing tools for C-based
languages, so it's hard to make such a statement. I'm rather just curious.)
Another challenge has been posted by Guy Steele to the ll1 mailing list
some time ago:
"The goal is to have something that looks like a function that takes a
(numerical) function as an argument and finds its roots, or a root.
Something like this:
(findroots (lambda (a) (* (sin a) (+ a (* 3 a)))))"
See http://www.ai.mit.edu/~gregs/ll1-discuss-archive-html/msg02088.html
for the full description.
He concludes with "By the way: to fans of Lisp macros, any macro
facility incapable of this particular application is not the true macro
facility."
Pascal
P.S.: Please always keep in mind that these questions are _not_ about
whether something is possible at all. This is always the case due to
Turing equivalence. The question is always: How convenient is it to make
certain features work, and what drawbacks do you add to the rest of the
language by adding some specific feature?
-- Tyler: "How's that working out for you?" Jack: "Great." Tyler: "Keep it up, then."
- Next message: Richard Fateman: "Re: symbolic algebra lib"
- Previous message: rem642b_at_Yahoo.Com: "Re: OT: writing resumes with VT100 for a Lisp job"
- In reply to: Frank Buss: "Re: macros (was: Paul Graham's teaching style is bad}"
- Next in thread: Marco Parrone: "Re: macros"
- Reply: Marco Parrone: "Re: macros"
- Reply: Frank Buss: "Re: macros"
- Reply: Marcin 'Qrczak' Kowalczyk: "Re: macros"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|