Could anyone please explain what the following code is doing?
Especially the line
(max alpha(betasearch alpha beta(car G)) beta(cdr G)) what does "max"
mean? is it a predefined commend in list? or i have to define it
myself? I will be very appreciated if somebody could help me, thankx in
advance!!!
(defun alphasearch (alpha beta G)
(cond
((>alpha beta) alpha)
((null G) alpha)
((atom G) G)
(t (alphasearch
(max alpha(betasearch alpha beta(car G)) beta(cdr G))
(defun betasearch(alpha beta G)
(cond
((<beta alpha) beta)
((null G) beta)
(atom G) G)
(t (betasearch alpha(min beta(alphasearch alpha beta(car G)))cdr
G)))))
Mike Chu <······@hotmail.com> writes:
> Could anyone please explain what the following code is doing?
> Especially the line
> (max alpha(betasearch alpha beta(car G)) beta(cdr G)) what does "max"
> mean? is it a predefined commend in list? or i have to define it
> myself? I will be very appreciated if somebody could help me, thankx in
> advance!!!
>
> (defun alphasearch (alpha beta G)
> (cond
> ((>alpha beta) alpha)
> ((null G) alpha)
> ((atom G) G)
> (t (alphasearch
> (max alpha(betasearch alpha beta(car G)) beta(cdr G))
>
> (defun betasearch(alpha beta G)
> (cond
> ((<beta alpha) beta)
> ((null G) beta)
> (atom G) G)
> (t (betasearch alpha(min beta(alphasearch alpha beta(car G)))cdr
> G)))))
MAX and MIN are pre-defined functions in Common Lisp.
(max 3 5) => 5
(min 1 2) => 1
You should be careful about your spaces. Lisp wants spaces between
tokens. The notation
(>alpha beta)
is not legal Lisp notation. This asks to call an operator ">alpha"
on a single argument held by a variable named "beta". I suspect you
wanted to call the operator whose name is ">" on two variables, one
of which was the argument alpha and the other the argument beta. To
do that you want
(> alpha beta)
Further, the notation
(max alpha(betasearch alpha beta(car G)))
is likely to confuse you. In lisp, the operator is after the parens,
not before, and it is quite inappropriate to mush the "(" up against
the item to its left, since there is no relationship. You want:
(max alpha (betasearch alpha beta (car G)))
in order to see that there are three function calls here, one to the
function MAX on arguments which are the value of ALPHA
and the result of the (betasearch...)
call. The second is the (betasearch call on three arguments which are
the value of ALPHA, the value of BETA, and the result of (car G).
The third is (car G) which is a call of the function CAR on a variable G.
In general, a notation like
(max alpha (betasearch alpha beta (car G)))
is equivalent to what might be written in an algebraic language
as:
max(alpha,betasearch(alpha,beta,car(G)))
I hope that helps.
For more information on MAX and MIN, see the Common Lisp HyperSpec
at http://www.harlequin.com/education/books/HyperSpec/FrontMatter/
Ifyou select the Symbol Index and the "M" tab within there, you can
find entries for MAX and MIN.