LOGO-L> parsing to make a variable 
Author Message
 LOGO-L> parsing to make a variable

Hi,

I and some of my students are trying make a Tic_Tac_Toe game.

In checking to see if a move was a legal move (a - the position had already
been selected, or b- it was not this player's turn), i am thinking that a
sub-procedure can be used .

Instead of

To X3
    If :P3 >0 [illegal_move STOP]
    . . .
End

I thought we should be able to do something like:

To X3
   make "mv 3      or    make "mv "p3
   check_move_x :mv
   . . .
End

To check_move_x :mv
     If *** >0 [illegal_move STOP]
     If :trn = 0 [illegal_move STOP]
End

How does *** become :P3?

Does it make sense to use WORD, or LIST or something else or a combination?
This seems to be a question of parsing pieces together to make a variable.

One of my students indicated that since STOP was not in the original
procedure only the sub-procedure is stopped.  Does this require that a value
is then returned to the procedure X3, and how is that accomplished?

Thank you in advance for your answer(s) and your thought and effort.  If
there is confusion feel free to contact me, and I will try to clarify the
concerns.

I am not going to try to tell anybody this is the best way to attack the
problem, but I believe that this CAN be accomplished.
______________________________________________________
Get Your Private, Free Email at http://www.*-*-*.com/

---------------------------------------------------------------





Tue, 25 Jun 2002 03:00:00 GMT  
 LOGO-L> parsing to make a variable

Quote:

>To X3
>   make "mv 3      or    make "mv "p3
>   check_move_x :mv
>   . . .
>End

>To check_move_x :mv
>     If *** >0 [illegal_move STOP]
>     If :trn = 0 [illegal_move STOP]
>End

>How does *** become :P3?

First, a slight digression to connect this with another thread:  Could
you tell us why you write the X3 procedure as you do, with a MAKE
followed by the call to CHECK_MOVE_X, instead of saying
        to x3
         check_move_x "p3
         ...
        end

Now, to answer your question.  If the input is the complete variable
name (P3 in your example) then you say
        if (thing :mv) > 0 [illegal_move ...]
The primitive operation THING takes a variable name as its input and
outputs the value of that variable.

If the input to check_move_x is just the number 3, then you use WORD
to construct the variable name:
        if (thing word "p :mv) > 0 [...]

(By the way, the :VAR notation in Logo is just an abbreviation for
THING "VAR; Logo could have been designed without :VAR at all, but
it was felt that that would lead to unpleasantly much typing for a
common case.)

Quote:
>One of my students indicated that since STOP was not in the original
>procedure only the sub-procedure is stopped.  Does this require that a value
>is then returned to the procedure X3, and how is that accomplished?

That's right; STOP stops only the current procedure call.  If you want
to stop *everything*, some versions of Logo provide the notation
        if ... [illegal_move THROW "TOPLEVEL]
This is a special case of a more general nonlocal exit mechanism in which
the input to THROW is a label that has to match the label of a corresponding
CATCH that encloses whatever you want to stop.

In Logo dialects without CATCH and THROW, you must, as you suggest,
return a value to the caller:

        to X3
         if check_move_x "p3 [stop]
         ...
        end

        to check_move_x :mv
         if (thing :mv) > 0 [illegal_move  output "true]
         if :trn = 0 [illegal_move  output "true]
         output "false
        end

[posted and mailed]



Wed, 26 Jun 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. LOGO-L> Making web links with MW2

2. LOGO-L> MW game making

3. parsing ls -lAR

4. Parsing ls on telnet window

5. LOGO-L> variable size pictures

6. LOGO-L> Apple logo/MSW Logo

7. LOGO-L> Wierdness with variables

8. LOGO-L> variable

9. LOGO-L> deleting variable

10. LOGO-L> Watch out for hiding variables

11. LOGO-L> Need help with variables

12. LOGO-L> local and global variables

 

 
Powered by phpBB® Forum Software