Recursion doesn't work (e.g., for con... Log Out | Topics | Search
Moderators | Register | Edit Profile

Zillions of Games Discussion Forum » Desired Features for Zillions of Games » Recursion doesn't work (e.g., for connection games) « Previous Next »

Author Message
Patrick S. Duff (Pduff)
Posted on Thursday, October 12, 2000 - 10:05 pm:   

Calling "(connect friend? n)" with the following recursive definition of "connect" crashes Zillions.

Instead of only expanding the definition at run-time when the function is called (correct behavior), it appears to be trying to expand all calls at all levels infinitely at parse-time (incorrect behavior).

I use recursion a lot, so I'd like it to work in Zillions!

(define connect
(if (on-board? $2)
$2
(if (and $1 (not (position-flag connected_$1)))
(set-position-flag connected_$1 true)
(connect $1 n)
(connect $1 e)
(connect $1 s)
(connect $1 w)
) ) )
Patrick S. Duff (Pduff)
Posted on Thursday, October 12, 2000 - 10:18 pm:   

By the way, this example illustrates a problem in the parser.

I first tried "(connect friend n)" and "(and $1? (not (position-flag connected_$1))", but this fails with a parse error on "$1?".

Changing to "(connect friend? n)" and "(and $1 (not (position-flag connected_$1))" works, because by some fortunate design or accident, flag names work fine with a trailing "?" character.
Patrick S. Duff (Pduff)
Posted on Saturday, October 14, 2000 - 10:58 am:   

When I entered the definition for "connect" given above I accidentally left out one line; add "(opposite $2)" before the end of the outer "if" to balance out the "$2" move.

But the original problem still remains; Zillions doesn't handle recursion properly.
David GLAUDE (Glu)
Posted on Monday, October 16, 2000 - 9:21 am:   

Patrick S. Duff

About recursion:
----------------

(define xxx ...) is not a fonction call, but macro processing.
This macro processing could be done OUTSIDE of Zillions-of-Games if required.
That's why recursion is not supported at all by Zillions-of-Games.

It is to notice that Zillions-of-Games detect recursion and make an error message
if detected into the rule ZRF file.

This is true for direct recursion and cross recursion

This is an auto-recursion:
(define recursive add (recursive))

This is cross recursivity:
(define recursive1 add (recursive2))
(define recursive2 add (recursive1))

The funny thing is that Zillions-of-Games will complain
"Macros form infinite recursion."
even if those macros are NOT IN USE in your game (this mean don't need to be expanded).

The good news is that any recursion can be also express without the usage of recursivity.
However, it might be very difficult to translate the recursion.
And you have to do it manualy, I am affraid.

Maybe the definitive answer to your problem is to ask for the support of function definition and call.
That way you can implement recursivity without problem.
However I think function should be limited to "move" or "drop" definition.

There is a last option, is to make static expention of the macro,
but limit it to a certain number of time.
If you know exactly a maximum number of recursive call, this could also solve the problem,
but will generate a lot of "code". This limited expention is not supported by Zillions
and require an external macro processor.

About the parsing error:
------------------------

I don't know exactly what is happening inside Zillions and what error you are talking about...
But I suggest EVERYBODY try to avoid that kind of use of macro parameter.
I mean "xxx$1".

The reason for this is that it is not perfectly supported by Zillions-of-Games.
* Try to use "defi$1" with "$1" equal to "ne".
* Try with "inclu$1" with "$1" equal to "de".
* Try "macro$1" with "$1" equal to "name" and "macroname" being a macro.

I assume this is because of the way Zillions-of-Games implement it's internal macro processing.

Patrick, could you send me a few sample ZRF, not using recursion and showing the problem, thanks.

David GLAUDE (glu@who.net)

Add Your Message Here
Post:
Username: Posting Information:
This is a private posting area. Only registered users and moderators may post messages here.
Password:
Options: Enable HTML code in message
Automatically activate URLs in message
Action: