The "!" and "?" characters

Hi,

You’re the chief but … macros make it actually easier to read programs.
Just think of cond in lisp. But … you’re the chief :slight_smile:

cond in Lisp is not necessarily a macro. It can be a syntax (or
special form in Lisp term). Anyway, I see two problems in macros:

(1) macros work great with S expression syntax. But not with Algol
like syntax. I know Dylan has macros with Algol like syntax.
I still feel it too complex for Ruby though.

(2) with macros, each user can introduce his/her own syntax to the
program, which means you may need to learn new sub-language to
read a program. I believe syntax should be stable.

						matz.
···

In message “Re: The “!” and “?” characters.” on 03/04/12, Martin Weber Ephaeton@gmx.net writes:

I wonder at this… Lisp has macros, and they don’t make it harder
to read.

Perhaps because it is impossible to make Lisp harder to read :-))

I knew someone was going to say that. :frowning: :wink:

> > c_for(i = 0, i < 200, i += 1) { > > ... > > } > > I'm not sure if that's the best example, because you can do that anyway if > st1/st2/st3 are proc objects: > > i = nil > c_for(proc {i = 0}, proc {i < 10}, proc {i += 1}) do > puts i > end

Yes, but that’s ugly. :wink: Also, it’s slow, since it has to do a
proc.call for each. Interestingly, a good bit of syntax modification
can be done with procs. (I’ve noted this a number of times in
#ruby-lang.) I find not having macros because readability might suffer
to be somewhat odd since, given blocks, you can do many of the same
things (such as the WHILE {block} example in that one tutorial).

However, macros make it nicer to read, in addition to some of the
other important features.

I’m not a Lisp hacker (I’ve tried and failed there), but are Lisp macros
more powerful than that?

I am by no means a Lisp hacker either… more an admirer. But there
are a few things even in the above example that you shouldn’t overlook:

*  The macro c_for would not start a new scope.  Blocks do.

*  Given this, you can implement all the basic language in
   a form that makes them non-magical.  This doesn't mean you
   can't cheat and optimize them, but that's transparent.

*  Blocks _are_ code.  Macros _write_ code.  That means you can
   have a block that writes new functions or macros.  This is
   handy---things like attr_* already do it with eval()---and
   it makes it more efficient and aesthetic to do so.

*  The above all plays hand-in-hand with the ability to extend
   the parser, as in the bottom examples.  (You can't write =
   or ++ using current ruby procs.)

I’m sure there are some Lisp gurus around who could give some really
cool examples of what macros can do. (Please? :wink:

> This kind of function composition was something I saw quite a lot of when > trying to learn Lisp.

Function composition is cool. Macros are cool, too, though, and the
two aren’t mutually exclusive. Lisp is a very powerful N-generation
language, because of its ability to extend itself. New programming
concepts or methodologies that come along can simply be absorbed,
because the language is flexible.

Of course, there is probably little desire to make Ruby something other
than an object-oriented language. I have no personal desire to work
in a non-OOP environment. (That’s why I use ruby. :wink: But that doesn’t
mean macros aren’t powerful and useful. Necessary? No more than
anything else. But useful, certainly—just like anything else.

···

On Sun, 13 Apr 2003 02:19:11 +0900 Brian Candler B.Candler@pobox.com wrote:

On Sun, Apr 13, 2003 at 01:04:53AM +0900, Ryan Pavlik wrote:


Ryan Pavlik rpav@users.sf.net

“My plans are always practical! It’s the laws of
physics that get in the way of my success.” - 8BT