Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > the perens in lisp dilects is there for a reson... macros.

Reply
Thread Tools

the perens in lisp dilects is there for a reson... macros.

 
 
atbusbook@aol.com
Guest
Posts: n/a
 
      08-05-2006
macros are sort of like c macros but more powerful. they are the
manafestation of treating code like data. lisp code is just a textual
representation of a data structure that is the list. this means that
you can manipulate code to emulate structured controll constructs and
elemanate boilerplate code. to show you the power of a macro heer is a
while loop

<code>
(defmacro while (test &body body)
`(do ()
((not ,test))
,@body)
</code>

Another one would be untill

<code>
(defmacro untill (test &body body)
`(while (not ,test) ,@body))
</code>

wich is defined on top of while

another test to wead out programers would be lisp stile macros because
of variable capture
and other perls of the macro world. but higenic macros can not have the
power of true macros

i also hear you talk about introspection. in lisp you use eval list

lets define a sum function to show you

<code>
(defun sum (lst)
(eval (append '(+) lst)))
</code>

another example would be this

<code>
(loop (print (eval (read))))
</code>
this is an interactive top level in 1 line

another use is for calling of functions

<code>
(defvar cmds `('foo ,(lambda () (format t "hello world")))
(funcall (getf cmds (read-from-string (read-line))))
</code>
of corse no error checking for comas and other things that could crash
the program

 
Reply With Quote
 
 
 
 
Chad Perrin
Guest
Posts: n/a
 
      08-05-2006
The parentheses are not strictly necessary for macros. They're just the
traditional LIspy way to do it. For instance, this is from UCBLogo's
help documentation (I copied the first screenful from a terminal
emulator):



MACRO procname :input1 :input2 ... (special form)
DEFMACRO procname text

A macro is a special kind of procedure whose output is evaluated
as Logo instructions in the context of the macro's caller.
.MACRO is exactly like TO except that the new procedure becomes
a macro; .DEFMACRO is exactly like DEFINE with the same exception.

Macros are useful for inventing new control structures comparable
to REPEAT, IF, and so on. Such control structures can almost, but
not quite, be duplicated by ordinary Logo procedures. For example,
here is an ordinary procedure version of REPEAT:

to my.repeat :num :instructions
if :num=0 [stop]
run :instructions
my.repeat :num-1 :instructions
end

This version works fine for most purposes, e.g.,

my.repeat 5 [print "hello]

But it doesn't work if the instructions to be carried out include
OUTPUT, STOP, or LOCAL. For example, consider this procedure:

to example
print [Guess my secret word. You get three guesses.]
repeat 3 [type "|?? | ~
if readword = "secret [pr "Right! stop]]
print [Sorry, the word was "secret"!]
end

This procedure works as written, but if MY.REPEAT is used instead
of REPEAT, it won't work because the STOP will stop MY.REPEAT
instead of stopping EXAMPLE as desired.

The solution is to make MY.REPEAT a macro. Instead of actually
carrying out the computation, a macro must return a list containing
Logo instructions. The contents of that list are evaluated as if
they appeared in place of the call to the macro. Here's a macro
version of REPEAT:

--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
"It's just incredible that a trillion-synapse computer could actually
spend Saturday afternoon watching a football game." - Marvin Minsky

 
Reply With Quote
 
 
 
 
Neumann
Guest
Posts: n/a
 
      08-05-2006
There's a discussion related to this going on over at Lambda the
Ultimate that you might enjoy:
http://lambda-the-ultimate.org/node/1646

 
Reply With Quote
 
Daniel Martin
Guest
Posts: n/a
 
      08-06-2006
writes:

> <smug lisp weenie giving standard lisp macro rant omitted>


This appears to be the continuation of some conversation / flamewar
somewhere else. Why bring this crud over here? Is there some reason
that we should care?

Fine, lisp macros are great and glorious and the be all and end all of
programming constructs, and all other languages hopelessly inferior.
All hail lisp macros. They're even so great and wonderful we'll bow
down before the wisdom of someone who manages to cram three spelling
errors and an awful grammar error into the subject line. You've
proven your vast superiority over us with your l33t lisping skillz.

Can you just go away now and let us get back to ruby?

 
Reply With Quote
 
Rick DeNatale
Guest
Posts: n/a
 
      08-06-2006
On 8/5/06, Daniel Martin <> wrote:
> writes:
>
> > <smug lisp weenie giving standard lisp macro rant omitted>

>
> This appears to be the continuation of some conversation / flamewar
> somewhere else. Why bring this crud over here? Is there some reason
> that we should care?


I've only recently subscribed to this list, after just sampling it for
a while, and I've been wondering the same thing about the apparently
endless discussion of the merits of C, C++, Ocaml, and Java

--
Rick DeNatale

 
Reply With Quote
 
Charles Hoffman
Guest
Posts: n/a
 
      08-06-2006
On Sun, 2006-08-06 at 13:34 +0900, Rick DeNatale wrote:
> On 8/5/06, Daniel Martin <> wrote:
> > writes:
> >
> > > <smug lisp weenie giving standard lisp macro rant omitted>

> >
> > This appears to be the continuation of some conversation / flamewar
> > somewhere else. Why bring this crud over here? Is there some reason
> > that we should care?

>
> I've only recently subscribed to this list, after just sampling it for
> a while, and I've been wondering the same thing about the apparently
> endless discussion of the merits of C, C++, Ocaml, and Java
>


That stuff doesn't bother me, it seems normal for users, enthusiasts,
and people interested in one programming language to talk about other
programming languages. Programmers these days usually have to use
multiple languages in their work anyway, and may have some functionaliy
written in another language that they need to interface with Ruby. It's
less fun to have a topic-nazi policy.

I've also noticed that Rubyists seem have a high tendency (at least
higher than Javaists and others, I think) to be programming-language
geeks, the kind of folks who like to learn about the general concepts of
programming languages, learn lots of different ones, and compare them.
I'd count myself more among those than a Rubyist at this point, as I've
yet to work on a real project in Ruby yet (but I'm itching to).

--ch--


 
Reply With Quote
 
Charles Hoffman
Guest
Posts: n/a
 
      08-06-2006
On Sun, 2006-08-06 at 13:34 +0900, Rick DeNatale wrote:
> On 8/5/06, Daniel Martin <> wrote:
> > writes:
> >
> > > <smug lisp weenie giving standard lisp macro rant omitted>


Oh, and if anyone's keeping score, the parens in Lisp/Scheme are there
to structure the code and data. Where other languages are full of {},
[], ;, and all sort of other punctuation marks, in Lisp you only
have/need parentheses to serve all the same purposes. It doesn't have
anything to do with macros per se.

--ch--


 
Reply With Quote
 
M. Edward (Ed) Borasky
Guest
Posts: n/a
 
      08-06-2006
Rick DeNatale wrote:
> On 8/5/06, Daniel Martin <> wrote:
>> writes:
>>
>> > <smug lisp weenie giving standard lisp macro rant omitted>

>>
>> This appears to be the continuation of some conversation / flamewar
>> somewhere else. Why bring this crud over here? Is there some reason
>> that we should care?

>
> I've only recently subscribed to this list, after just sampling it for
> a while, and I've been wondering the same thing about the apparently
> endless discussion of the merits of C, C++, Ocaml, and Java

Whatever you opinions about any programming language are, Ruby is
implemented in C at the moment, so C at least has *that* going for it!

 
Reply With Quote
 
M. Edward (Ed) Borasky
Guest
Posts: n/a
 
      08-06-2006
Charles Hoffman wrote:
> That stuff doesn't bother me, it seems normal for users, enthusiasts,
> and people interested in one programming language to talk about other
> programming languages.

Especially the denizens of the main Ruby mailing list, which includes
the founder of the language. We are people who use or want to use Ruby,
and we want it to have what it needs from other languages. Matz did a
pretty good job of that all by himself.


> Programmers these days usually have to use
> multiple languages in their work anyway,

Well ... my personal opinion is that more than two languages is probably
overload. You need one general purpose language and whatever
domain-specific language fits what you're doing. More than that and you
start losing time context switching and spending time looking up things
like "how do I parse a date/time string to a date/time object in Ruby
when I know how to do it in R?"

> I've also noticed that Rubyists seem have a high tendency (at least
> higher than Javaists and others, I think) to be programming-language
> geeks, the kind of folks who like to learn about the general concepts of
> programming languages, learn lots of different ones, and compare them.
>

That may be because of Ruby's youth relative to other general-purpose
languages. I remember the same phenomenon when Java was a young
language. I'm personally a language geek and have been since ... well,
let's just say that the first code I wrote in my life was for a machine
built from vacuum tubes that had only an assembler.

 
Reply With Quote
 
dblack@wobblini.net
Guest
Posts: n/a
 
      08-06-2006
Hi --

On Mon, 7 Aug 2006, M. Edward (Ed) Borasky wrote:

> Charles Hoffman wrote:
>> That stuff doesn't bother me, it seems normal for users, enthusiasts,
>> and people interested in one programming language to talk about other
>> programming languages.

> Especially the denizens of the main Ruby mailing list, which includes the
> founder of the language. We are people who use or want to use Ruby, and we
> want it to have what it needs from other languages. Matz did a pretty good
> job of that all by himself.
>
>
>> Programmers these days usually have to use
>> multiple languages in their work anyway,

> Well ... my personal opinion is that more than two languages is probably
> overload. You need one general purpose language and whatever domain-specific
> language fits what you're doing. More than that and you start losing time
> context switching and spending time looking up things like "how do I parse a
> date/time string to a date/time object in Ruby when I know how to do it in
> R?"
>
>> I've also noticed that Rubyists seem have a high tendency (at least
>> higher than Javaists and others, I think) to be programming-language
>> geeks, the kind of folks who like to learn about the general concepts of
>> programming languages, learn lots of different ones, and compare them.
>>

> That may be because of Ruby's youth relative to other general-purpose
> languages. I remember the same phenomenon when Java was a young language.


I think Ruby is slightly older than Java, isn't it?

> I'm personally a language geek and have been since ... well, let's
> just say that the first code I wrote in my life was for a machine
> built from vacuum tubes that had only an assembler.


You may have me beat. My first was BASIC on a PDP-8, followed by
BASIC and assembler on a PDP-10. I think at least the '10 had
integrated circuits

As for language geekdom: I feel like I used to be more than I am now,
but it's more because Ruby stuff is keeping me so busy than because
Ruby satisfies all my language interest. In fact I've never wanted
Ruby to take on Lisp macros, Python whitespace, Java-style typing,
C-style comments, and all the rest of it. Maybe there should be one
or more kitchen-sink languages out there, but they should be written
from scratch for that purpose.

Here's what I think is a classic and still very relevant post by Dave
Thomas about the design of Ruby and the process of change:
http://blade.nagaokaut.ac.jp/cgi-bin...uby-talk/12606


David

--
http://www.rubypowerandlight.com => Ruby/Rails training & consultancy
----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <-----
http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log
http://www.manning.com/black => book, Ruby for Rails
http://www.rubycentral.org => Ruby Central, Inc.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nice historical Musical - VERY RELAXING - about LISP history -fundamental ideas of LISP nanothermite911fbibustards C++ 0 06-16-2010 09:47 PM
pat-match.lisp or extend-match.lisp in Python? ekzept Python 0 08-10-2007 06:08 PM
the perens in lisp dilects is there for a reson... macros. atbusbook@aol.com Python 1 08-05-2006 04:30 PM
the perens in lisp dilects is there for a reson... macros. atbusbook@aol.com Perl Misc 0 08-05-2006 06:42 AM
Bruce Perens: The Emerging Economic Paradigm of Open Source Have A Nice Cup of Tea NZ Computing 0 04-12-2006 07:06 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57