From: Norbert
Subject: if then else
Date: 
Message-ID: <1124570511.271017.279710@z14g2000cwz.googlegroups.com>
Hi,

I found examples in the Franz website using the following macro

(if (xxxx xxxx xxx))
    then
         (xxxx xxx )
    else
         (xxx xxx)

I read several articles in this list, but most of them are not recent.

Now, I tried to load a them in Allegro CL, but it didn't accept the
syntax. I did a research and looks like that there is a macro in the
Allegro extensions called "if*" that has the same syntax.

However, I'm quit sure that the samples that I saw the Franz website
have the if-then-else without the "*".

Could someone help me to undestand this difference or point me some
reference material? Also, does other Lisp implementations like SBCL
support it as an extension?

I found tons of papers regarding Lisp and Allegro forms but about
extensions was not enough to help to understand use it.


Thanks,

Norberto

From: Barry Margolin
Subject: Re: if then else
Date: 
Message-ID: <barmar-208FE7.21221920082005@comcast.dca.giganews.com>
In article <························@z14g2000cwz.googlegroups.com>,
 "Norbert" <······@gmail.com> wrote:

> Hi,
> 
> I found examples in the Franz website using the following macro
> 
> (if (xxxx xxxx xxx))
>     then
>          (xxxx xxx )
>     else
>          (xxx xxx)
> 
> I read several articles in this list, but most of them are not recent.
> 
> Now, I tried to load a them in Allegro CL, but it didn't accept the
> syntax. I did a research and looks like that there is a macro in the
> Allegro extensions called "if*" that has the same syntax.
> 
> However, I'm quit sure that the samples that I saw the Franz website
> have the if-then-else without the "*".

Could those be examples of Franz Lisp, not Allegro Common Lisp?  Franz 
Lisp was a free dialect of Lisp that was available on Unix in the early 
80's.  It predated Common Lisp, and was more like Maclisp than CL.  
Maclisp didn't have a built-in IF macro, and at that time there were a 
number of competing user-written IF macros, one of which made use of 
THEN and ELSE keywords; Franz Lisp may have adopted that one.

Perhaps if you included URLs, someone could explain these examples 
better.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Peter Seibel
Subject: Re: if then else
Date: 
Message-ID: <m2r7cowa15.fsf@gigamonkeys.com>
"Norbert" <······@gmail.com> writes:

> Hi,
>
> I found examples in the Franz website using the following macro
>
> (if (xxxx xxxx xxx))
>     then
>          (xxxx xxx )
>     else
>          (xxx xxx)
>
> I read several articles in this list, but most of them are not
> recent.
>
> Now, I tried to load a them in Allegro CL, but it didn't accept the
> syntax. I did a research and looks like that there is a macro in the
> Allegro extensions called "if*" that has the same syntax.
>
> However, I'm quit sure that the samples that I saw the Franz website
> have the if-then-else without the "*".

It's always possible that someone wrote some code in a package with
the name "IF" shadowed. You need to look for an IN-PACKAGE form in the
file in question and then find the definition of that package to see
if that's indeed what's going on. But if so, that's just a more subtle
(i.e. more confusing) way of using a different name.

> Could someone help me to undestand this difference or point me some
> reference material? Also, does other Lisp implementations like SBCL
> support it as an extension?

As far as I know, no. The IF* macro is, again as far as I know, the
creation of John Foderaro one of the founders of Franz, one of the
main authors of the original Allegro Common Lisp and more recently the
author of AllegroServe and the now-in-beta AllegroCache. The IF* macro
is based on the if macro from Franz Lisp, a pre-Common Lisp Lisp
dialect that ran on BSD, on which John also worked.

At any rate, John believes that using the IF* macro makes code much
clearer than using IF, WHEN, UNLESS, and COND. However some folks are
deeply disturbed by IF* since Common Lisp has perfectly good
conditional execution constructs such as IF, WHEN, UNLESS, and
COND. (Interestingly--to me anyway--John is also a member of the
anti-LOOP faction. Which always struck me as odd since IF* seems to be
to IF as LOOP is to DO--a more sugary syntax for expressing certain
common uses of an underlying rather primitive operation. But he sees
it differently apparently.)

You may also want to know that the IF* macro caused a bit of a flap a
couple years ago when John published a "coding standard" that
recommended using IF* instead of the standard conditional execution
constructs which made some people upset because for one of the most
senior programmers at one of the main vendors to be advocating use of
a non-standard macro in place of standard ones seemed to be a bit of a
statement about their attitude towards the standard. Somewhere in
there John released the source to IF* into the public domain and
pointed out that one of the great things about Lisp, that we all love,
is that the macro system lets us provide new language constructs so
why should it be such a big deal for him to make use of that
capability. I bring it up just so you know that there were, at one
time anyway, some fairly strong views expressed on the merits of IF*,
pro and con that might come bubbling back up in this thread. Or maybe
not: At any rate, I've never encountered a use of the IF* in any code
not written by John though I have heard that some of the other
programmers at Franz use it.

> I found tons of papers regarding Lisp and Allegro forms but about
> extensions was not enough to help to understand use it.

Your best bet, as far as I know, is to look at the source (which you
probably have already found):

  <http://www.franz.com/~jkf/ifstar.txt>

-Peter

-- 
Peter Seibel           * ·····@gigamonkeys.com
Gigamonkeys Consulting * http://www.gigamonkeys.com/
Practical Common Lisp  * http://www.gigamonkeys.com/book/
From: John
Subject: Re: if then else
Date: 
Message-ID: <slrndgfl01.228v.i7bL0xoA@mailinator.com>
On 2005-08-20, Peter Seibel <·····@gigamonkeys.com> wrote:
>  (Interestingly--to me anyway--John is also a member of the anti-LOOP
>  faction. Which always struck me as odd since IF* seems to be to IF as
>  LOOP is to DO--a more sugary syntax for expressing certain common uses
>  of an underlying rather primitive operation. But he sees it differently
>  apparently.)

Well, according to his "coding standard" its because:

  "The structure of the code inside a loop is not apparent. Thus a
   function with loop in it is opaque until you've read carefully
   through all the keywords used in the expression."

Which seems silly to me as code with any non-trivial loop is opaque until
you read it. Personally, I think experienced LISP programmers can read
either form without a problem while the novice will have issues with both
so this seems to be a non-issue.

So if you take out the IF* and LOOP items from his coding standard you are
left with "Comment your code." Something I hope we can all agree on :)
From: Tayssir John Gabbour
Subject: Re: if then else
Date: 
Message-ID: <1124680345.913649.199930@f14g2000cwb.googlegroups.com>
Peter Seibel wrote:
> At any rate, John believes that using the IF* macro makes code much
> clearer than using IF, WHEN, UNLESS, and COND. However some folks are
> deeply disturbed by IF* since Common Lisp has perfectly good
> conditional execution constructs such as IF, WHEN, UNLESS, and
> COND. (Interestingly--to me anyway--John is also a member of the
> anti-LOOP faction. Which always struck me as odd since IF* seems to be
> to IF as LOOP is to DO--a more sugary syntax for expressing certain
> common uses of an underlying rather primitive operation. But he sees
> it differently apparently.)

I've often thought IF kinda bites when there's a longish then-clause
but very short else-clause. But small comments may help mitigate IF's
problems, which I don't think was mentioned in the old usenet struggle
over IF*.

I would've liked to have seen a serious discussion on DO vs. LOOP --
without the fun histrionics.


Tayssir
- -
"Till there be property there can be no government, the very end of
which is to secure wealth, and to defend the rich from the poor." --
Adam Smith
From: Christopher C. Stacy
Subject: Re: if then else
Date: 
Message-ID: <uhddiwrue.fsf@news.dtpq.com>
"Tayssir John Gabbour" <···········@yahoo.com> writes:

> Peter Seibel wrote:
> > At any rate, John believes that using the IF* macro makes code much
> > clearer than using IF, WHEN, UNLESS, and COND. However some folks are
> > deeply disturbed by IF* since Common Lisp has perfectly good
> > conditional execution constructs such as IF, WHEN, UNLESS, and
> > COND. (Interestingly--to me anyway--John is also a member of the
> > anti-LOOP faction. Which always struck me as odd since IF* seems to be
> > to IF as LOOP is to DO--a more sugary syntax for expressing certain
> > common uses of an underlying rather primitive operation. But he sees
> > it differently apparently.)
> 
> I've often thought IF kinda bites when there's a longish then-clause
> but very short else-clause. But small comments may help mitigate IF's
> problems, which I don't think was mentioned in the old usenet struggle
> over IF*.

What's wrong with COND?
From: Tayssir John Gabbour
Subject: Re: if then else
Date: 
Message-ID: <1124720905.840015.152180@g47g2000cwa.googlegroups.com>
Christopher C. Stacy wrote:
> "Tayssir John Gabbour" <···········@yahoo.com> writes:
>
> > Peter Seibel wrote:
> > > At any rate, John believes that using the IF* macro makes code much
> > > clearer than using IF, WHEN, UNLESS, and COND. However some folks are
> > > deeply disturbed by IF* since Common Lisp has perfectly good
> > > conditional execution constructs such as IF, WHEN, UNLESS, and
> > > COND. (Interestingly--to me anyway--John is also a member of the
> > > anti-LOOP faction. Which always struck me as odd since IF* seems to be
> > > to IF as LOOP is to DO--a more sugary syntax for expressing certain
> > > common uses of an underlying rather primitive operation. But he sees
> > > it differently apparently.)
> >
> > I've often thought IF kinda bites when there's a longish then-clause
> > but very short else-clause. But small comments may help mitigate IF's
> > problems, which I don't think was mentioned in the old usenet struggle
> > over IF*.
>
> What's wrong with COND?

Good question! I'll try it out next time and see how it looks.

For me, the IF problem is one of those things that pops into my head,
but never quite important enough to do anything about. Particularly
since I don't work in a team where I can ask someone, "Hey, how do you
think this looks?"



Tayssir
- -
"Till there be property there can be no government, the very end of
which is to secure wealth, and to defend the rich from the poor." --
Adam Smith
From: Pascal Bourguignon
Subject: Re: if then else
Date: 
Message-ID: <87slx26w2p.fsf@thalassa.informatimago.com>
"Tayssir John Gabbour" <···········@yahoo.com> writes:
> I've often thought IF kinda bites when there's a longish then-clause
> but very short else-clause. But small comments may help mitigate IF's
> problems, which I don't think was mentioned in the old usenet struggle
> over IF*.

One of my teacher used to tell us to test for the smallest clause first.

(if condition
    (progn
        big
        big
        big)
   small)

--> 

(if (not condition)
    small
    (progn
        big
        big
        big))

I this case, I would often use rather:

(unless condition
   (return-from where-we-are small))
big
big
big

or don't bother at all...


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Our enemies are innovative and resourceful, and so are we. They never
stop thinking about new ways to harm our country and our people, and
neither do we. -- Georges W. Bush
From: Tayssir John Gabbour
Subject: Re: if then else
Date: 
Message-ID: <1124764911.975182.16860@g43g2000cwa.googlegroups.com>
Pascal Bourguignon wrote:
> "Tayssir John Gabbour" <···········@yahoo.com> writes:
> > I've often thought IF kinda bites when there's a longish then-clause
> > but very short else-clause. But small comments may help mitigate IF's
> > problems, which I don't think was mentioned in the old usenet struggle
> > over IF*.
>
> One of my teacher used to tell us to test for the smallest clause first.
>
> (if condition
>     (progn
>         big
>         big
>         big)
>    small)
>
> -->
>
> (if (not condition)
>     small
>     (progn
>         big
>         big
>         big))
>
> I this case, I would often use rather:
>
> (unless condition
>    (return-from where-we-are small))
> big
> big
> big
>
> or don't bother at all...

I'm glad to hear that I'm not the only one... Yeah, turning it into a
(not condition) always seems like a double-negative.


Tayssir
From: Coby Beck
Subject: Re: if then else
Date: 
Message-ID: <ZV4Pe.214222$tt5.48680@edtnps90>
"Peter Seibel" <·····@gigamonkeys.com> wrote in message 
···················@gigamonkeys.com...
> As far as I know, no. The IF* macro is, again as far as I know, the
> creation of John Foderaro one of the founders of Franz, one of the

[big snip]

What an emminently reasonable and comprehensive summary of a very 
emotionally charged and contentious debate.  Nicely done, Peter.

-- 
Coby Beck
(remove #\Space "coby 101 @ bigpond . com")
From: Pascal Costanza
Subject: Re: if then else
Date: 
Message-ID: <3mplp2F183r7lU1@individual.net>
Norbert wrote:
> Hi,
> 
> I found examples in the Franz website using the following macro
> 
> (if (xxxx xxxx xxx))
>     then
>          (xxxx xxx )
>     else
>          (xxx xxx)
> 
> I read several articles in this list, but most of them are not recent.
> 
> Now, I tried to load a them in Allegro CL, but it didn't accept the
> syntax. I did a research and looks like that there is a macro in the
> Allegro extensions called "if*" that has the same syntax.
> 
> However, I'm quit sure that the samples that I saw the Franz website
> have the if-then-else without the "*".

It's possible to achieve this by shadowing 'if from the common-lisp 
package and replacing it with one's own version of 'if.

I don't think that if* is widely used. You can get the same effect by 
the default if when you use it like this:

(if ...
    (progn ...)  ; then part
    (progn ...)) ; else part

if* just adds the syntactic keywords then and else, and removes the 
necessity to add progn for creating blocks of code if more than one 
expression needs to be executed.

> I found tons of papers regarding Lisp and Allegro forms but about
> extensions was not enough to help to understand use it.

Don't worry too much. Just use the Common Lisp built-in if. At some 
stage, you could use if* as an exercise for writing your own macros. 
It's not that hard.



Pascal

-- 
OOPSLA'05 tutorial on generic functions & the CLOS Metaobject Protocol
++++ see http://p-cos.net/oopsla05-tutorial.html for more details ++++