From: Young-Jin Lee
Subject: [Q] Beginner's question on recursive call in lisp.
Date: 
Message-ID: <LB8B5.3908$rr.64309@vixen.cso.uiuc.edu>
Hi, I have a question about loop and recursive call in lisp.
I'm implementing some recursive method, alpha beta prnning method, but I
cannot find how to escape the recursive call.
For instance,
(defun recursiveMethod(position depth whoseturn)

 (if (= depth 0)
  (return (evaluate position whoseturn))
 )

......
(setf currentValue (recursiveMethod position (- depth 1) whoseturn))

....
)

I thought I can escape this recursive call when depth becomes 0, but when I
ran this routine I got
"Error: Not inside a block named nil. [condition type: CONTROL-ERROR]".

What is the right strategy to configure a recursive call?
Is there any good example for alpha-beta pruning?

Any comments would be greatly appreciated.

Thanks in advance.

YJ

From: Marco Antoniotti
Subject: Re: [Q] Beginner's question on recursive call in lisp.
Date: 
Message-ID: <y6c4s2yn6pa.fsf@octagon.mrl.nyu.edu>
"Young-Jin Lee" <······@uiuc.edu> writes:

> Hi, I have a question about loop and recursive call in lisp.
> I'm implementing some recursive method, alpha beta prnning method, but I
> cannot find how to escape the recursive call.
> For instance,
> (defun recursiveMethod(position depth whoseturn)
> 
>  (if (= depth 0)
>   (return (evaluate position whoseturn))
>  )
> 
> ......
> (setf currentValue (recursiveMethod position (- depth 1) whoseturn))
> 
> ....
> )
> 
> I thought I can escape this recursive call when depth becomes 0, but when I
> ran this routine I got
> "Error: Not inside a block named nil. [condition type: CONTROL-ERROR]".
> 
> What is the right strategy to configure a recursive call?
> Is there any good example for alpha-beta pruning?
> 
> Any comments would be greatly appreciated.

The first and only comment that applies is that RETURN should not be
there :) (Too much C/C++ programming obfuscates the soul).

(defun recursive-method (position depth whoseturn)
  (when (= depth 0)
    (evaluate position whoseturn))

is all you need.

Cheers

-- 
Marco Antoniotti =============================================================
NYU Bioinformatics Group			 tel. +1 - 212 - 998 3488
719 Broadway 12th Floor                          fax  +1 - 212 - 995 4122
New York, NY 10003, USA				 http://galt.mrl.nyu.edu/valis
             Like DNA, such a language [Lisp] does not go out of style.
			      Paul Graham, ANSI Common Lisp
From: Rainer Joswig
Subject: Re: [Q] Beginner's question on recursive call in lisp.
Date: 
Message-ID: <joswig-F18F99.03522630092000@news.is-europe.net>
In article <···············@octagon.mrl.nyu.edu>, Marco Antoniotti 
<·······@cs.nyu.edu> wrote:

> "Young-Jin Lee" <······@uiuc.edu> writes:
> 
> > Hi, I have a question about loop and recursive call in lisp.
> > I'm implementing some recursive method, alpha beta prnning method, but I
> > cannot find how to escape the recursive call.
> > For instance,
> > (defun recursiveMethod(position depth whoseturn)
> > 
> >  (if (= depth 0)
> >   (return (evaluate position whoseturn))
> >  )
> > 
> > ......
> > (setf currentValue (recursiveMethod position (- depth 1) whoseturn))
> > 
> > ....
> > )
> > 
> > I thought I can escape this recursive call when depth becomes 0, but when I
> > ran this routine I got
> > "Error: Not inside a block named nil. [condition type: CONTROL-ERROR]".
> > 
> > What is the right strategy to configure a recursive call?
> > Is there any good example for alpha-beta pruning?
> > 
> > Any comments would be greatly appreciated.
> 
> The first and only comment that applies is that RETURN should not be
> there :) (Too much C/C++ programming obfuscates the soul).
> 
> (defun recursive-method (position depth whoseturn)
>   (when (= depth 0)
>     (evaluate position whoseturn))
> 
> is all you need.

Otherwise use RETURN-FROM .

-- 
Rainer Joswig, Hamburg, Germany
Email: ·············@corporate-world.lisp.de
Web: http://corporate-world.lisp.de/
From: Guy Footring
Subject: Re: [Q] Beginner's question on recursive call in lisp.
Date: 
Message-ID: <wkem1z38kw.fsf@ford.com>
(RETURN x) is equivalent to (RETURN-FROM NIL x), but, as the error
message says, you don't have a block called NIL.  You do, however,
have a block with the same name as the function, i.e. recursiveMethod.
You should, therefore, be using (RETURN-FROM recursiveMethod) in 
your example, if you are going to use RETURN-FROM at all.  It is probably
better style to restructure the code to avoid explicit RETURN-FROM 
statements altogether:

(defun recursiveMethod(position depth whoseturn)
  (if (= depth 0)
     (evaluate position whoseturn)
    (progn
      ......
      (setf currentValue (recursiveMethod position (- depth 1) whoseturn))
      ....)))

Hope this of some help.

"Young-Jin Lee" <······@uiuc.edu> writes:

> Hi, I have a question about loop and recursive call in lisp.
> I'm implementing some recursive method, alpha beta prnning method, but I
> cannot find how to escape the recursive call.
> For instance,
> (defun recursiveMethod(position depth whoseturn)
> 
>  (if (= depth 0)
>   (return (evaluate position whoseturn))
>  )
> 
> ......
> (setf currentValue (recursiveMethod position (- depth 1) whoseturn))
> 
> ....
> )
> 
> I thought I can escape this recursive call when depth becomes 0, but when I
> ran this routine I got
> "Error: Not inside a block named nil. [condition type: CONTROL-ERROR]".
> 
> What is the right strategy to configure a recursive call?
> Is there any good example for alpha-beta pruning?
> 
> Any comments would be greatly appreciated.
> 
> Thanks in advance.
> 
> YJ
From: Erik Naggum
Subject: Re: [Q] Beginner's question on recursive call in lisp.
Date: 
Message-ID: <3179479502013367@naggum.net>
* "Young-Jin Lee" <······@uiuc.edu>
| Hi, I have a question about loop and recursive call in lisp.

  That is because you still think in another language.  This is very
  evident in how you name your variables.  Stop presuming (or behaving
  as if you are) that all programming languages are essentially the
  same, that it is sufficient to learn to think in the language
  thatTaughtYouToWriteLikeThis and you will observe the need to find
  out what return actually does, meaning: consult a dictionary when
  reading or writing a foreign language, don't just assume that words
  that look a lot like words you know mean the same as they do in the
  language you learned first (that is, use the language specification).

#:Erik
-- 
  If this is not what you expected, please alter your expectations.
From: Johan Kullstam
Subject: Re: [Q] Beginner's question on recursive call in lisp.
Date: 
Message-ID: <m3u2avgywl.fsf@sysengr.res.ray.com>
"Young-Jin Lee" <······@uiuc.edu> writes:

> Hi, I have a question about loop and recursive call in lisp.
> I'm implementing some recursive method, alpha beta prnning method, but I
> cannot find how to escape the recursive call.
> For instance,
> (defun recursiveMethod(position depth whoseturn)
> 
>  (if (= depth 0)
>   (return (evaluate position whoseturn))
>  )
> ......
> (setf currentValue (recursiveMethod position (- depth 1) whoseturn))
> 
> ....
> )
> 
> I thought I can escape this recursive call when depth becomes 0, but when I
> ran this routine I got
> "Error: Not inside a block named nil. [condition type:
> CONTROL-ERROR]".

from you use of RETURN, i infer that you are suffering from a C
hangover.  don't worry, i suffered from this too.  seek out a lisp
book or two.

> What is the right strategy to configure a recursive call?
> Is there any good example for alpha-beta pruning?

peter norvig has an excellent example as part of the othello program
in his book _principles of artificial intelligence programming_ (aka
PAIP).  despite its name this book is of interest and great utility
also to those (like me) who are not particularly interested in
artificial intelligence.

you might want to look at paul grahams _ansi common lisp_.  it is
about lisp with no artificial intelligence slant at all.  for coming
from other languages, i think it's ideal.  if i had to recommend one
book, i would choose paul graham _ansi common lisp_.

don't get paul grahams other book, _on lisp_ until you get used to
lisp basics.  i got _on lisp_ first and found it incomprehensible
until i read _ansi common lisp_.

> Any comments would be greatly appreciated.
> 
> Thanks in advance.
> 
> YJ
> 
> 

-- 
J o h a n  K u l l s t a m
[········@ne.mediaone.net]
sysengr