LOGO-L> scope problem 
Author Message
 LOGO-L> scope problem

My son started using MSWLogo recently.  As he's just learning to type, he
appreciated the abbreviations fd, lt, etc.  When we started looking at
variables he asked whether there was an abbreviation for 'show'.  I told
him that there was not, but that we could make one:

to sh :a
  show :a

Then he wanted an abbreviation for 'repeat'.  We tried:

to re :a :b
  repeat :a :b

We soon ran into a scope problem:

make "a 100
re 3 [fd :a]

The intention was to fd 100 (three times), but what we got was fd 3 (three
times).  Any suggestions on how to avoid this problem, and how to explain
it?  Thanks, and many thanks to Mr. Mills for MSWLogo.


Sun, 29 Jul 2001 03:00:00 GMT  
 LOGO-L> scope problem


>to re :a :b
>  repeat :a :b

>We soon ran into a scope problem:

>make "a 100
>re 3 [fd :a]

Yeah, this is the downside of dynamic scope.  The general solution is to
use obscure variable names for inputs to procedures that involve running
command lists:

to re :re.long.name.a :re.long.name.b
 repeat :re.long.name.a :re.long.name.b

The above will work in any Logo.  In UCBLogo and MSWLogo, you can also
solve the problem differently, by saying

copydef "re "repeat

which will make RE another name for REPEAT.  That's probably the easiest
and best solution.

Sun, 29 Jul 2001 03:00:00 GMT  
 LOGO-L> scope problem

>Any suggestions on how to avoid this problem, and how to explain it?  

The brief explanation is that when [fd :a] is to be executed the value of
:a is 3.
Such problems arise in Logo always when you create a command, which accepts
a list of instructions and that command later executes these instructions.
If the list contains variable names then there is always a risk that those
variable's values can change between the point where the list was written
and where it will be executed. Or (as in your case) the name can become
different meaning (will denote another variable and the original one will
be shadowed) at the point of execution.

One common technical solution of this problem is to use long and 'strange
long' names to name inputs of commands which accept command lists as inputs
(as your command named re):


meaning in Logo therefore it can be used to form names of variables. I have
also inclided the command's name inside the inputs' names to be sure that I
will not give the same name to another similar command which may invoke
this one. Using the above procedure is much more safe then your one because
it is a little chance that somebody will name a variable using such strange


Peter Tomcsanyi

My favourite Logo:


Sun, 29 Jul 2001 03:00:00 GMT  
 [ 3 post ] 

 Relevant Pages 

1. LOGO-L> Re: Dynamic scope in Logo

2. LOGO-L> Re: Logo saving problem

3. LOGO-L> Problem with LOGO PCX encoding

4. LOGO-L> Computer Science Logo Style problem

5. LOGO-L> Logo problems

6. LOGO-L> Logo procedure problem

7. LOGO-L> Apple logo/MSW Logo

8. LOGO-L> Reseach Machines Logo (RM LOGO)

9. WTD: 'ls -lR '->HTML code

10. LOGO-L> one small problem

11. LOGO-L> problems with ver 6.2

12. LOGO-L> Little MicroWorlds Problem


Powered by phpBB® Forum Software