LOGO-L> Re: Dynamic scope in Logo 
Author Message
 LOGO-L> Re: Dynamic scope in Logo

Quote:
Brian Harvey writes:
> 1.  Serious versions of Logo (which included LCSI versions prior to
> LogoWriter) have a pause-on-error feature that's a real help in
> debugging.  In case of an error, you get a Logo prompt in the
> environment in which the error occurred.  This lets you use Logo
> itself, rather than some special debugging language, to investigate
> the state that gave rise to the error -- specifically, the value of
> variables.  But it's quite common that if procedure A calls B which
> calls C which calls D, an error in A can give faulty inputs to B,
> which aren't caught until one of them becomes an input to a
> primitive down in D.  In dynamically scoped Logo, at the moment of
> the error, all of the local variables of A, B, C, and D are
> naturally available in the error environment.  In a lexically scoped
> language, only D's local variables -- which won't help you find the
> problem -- are available in the error environment.  This is why all
> the Scheme de{*filter*}s I've seen have special instructions, not part
> of Scheme itself, that say "switch to the dynamically previous
> scope" and things like that.  Well, that's okay once you understand
> what an environment *is*, which comes about half way through my
> course for undergraduate CS majors.  It's no good for beginners.

It would be possible to write a de{*filter*} that walked back through the
scopes to find the referenced variable (or create a new scope which
contained all the local variables of the other scopes).  While this
behavior comes for free with dynamic scoping, it doesn't require
dynamic scoping.

Of course, the two different behaviors could cause confusion.  For
example, if you get a "my.var has no value" error then type PR :MY.VAR
at the debugging prompt and it works because MY.VAR was defined in a
different scope.  It's not perfect.

- Show quoted text -

Quote:
> 2.  In a dynamically scoped language, it's possible to write control
> structures without having to think about environments and without having
> to wrap closures around the code you want to execute.  For example, in
> Logo I can say

>    to while :condition :action
>    if not run :condition [stop]
>    run :action
>    while :condition :action
>    end

> and I can use it like this:

>    to countdown :num
>    while [:num > 0] [print :num  make "num :num-1]
>    print "blastoff!
>    end

> I couldn't do it that simply in Scheme.  I'd have to write a version
> using thunks, and then probably write a macro to invoke that.  Again,
> not so bad once you understand lambda and scope, but a big cognitive
> burden for a beginner.

But, as you point out yourself in the UCBLogo manual, this wouldn't
work:

        to my.repeat :num :instructions
        if :num=0 [stop]
        run :instructions
        my.repeat :num-1 :instructions
        end

        to example
        print [Guess my secret word.  You get three guesses.]
        my.repeat 3 [type "|?? | ~
                     if readword = "secret [pr "Right! stop]]
        print [Sorry, the word was "secret"!]
        end

(the problem being that the STOP in EXAMPLE stops MY.REPEAT and not
EXAMPLE)

This is in the context of justifying .DEFMACRO, which does provide a
solution, but macros aren't easy to work with either.  Macros and
their use to create control structures is identicle to Scheme, so it's
not much of a win.

Wrapping things in thunks (or closures) is a syntactic issue.  [a
thunk is a piece of code that can be executed at a later time]
Declaring a thunk doesn't have to be difficult.  Scheme doesn't do
this well because thunks are syntactically ugly (with words like
"lambda" and a few too many parenthesis), but Smalltalk might be a
better example.  It uses "[]" to express a thunk (taken, I believe,
from Logo) and uses these for all its control structures quite
successfully: both user-defined control structures and standard
control structures can (and are) defined in Smalltalk.

I don't think closures are all that conceptually difficult to deal
with on the simplest level.  On the simplest level they are equivalent
to what Logo already has.  Just like dynamic scope/RUN, there are
hidden difficulties with closures.  Neither is totally intuitive.  But
closures do allow better scaling.

I think scaling matters.  Maybe no child is going to write programs
with thousands of lines, but wouldn't it be nice for them to work in
an evironment surrounded by thousands of lines of Logo code?  

Quote:
> Now I learn about the legislature in (I think it was) Tennessee voting on
> a bill to make pi equal to 4, and I can say

It was in this fine state of Indiana, actually, and the bill was going
to make pi equal to 3 to fit with the Biblical scripture which
offhandedly mentions a fountain that is 10 cubits (or other old unit)
across and 30 cubits around.

<------------------------------------------------------------------->

< drawer #419 Earlham College |   http://www.*-*-*.com/ ~bickiia >
< Richmond, IN 47374          |  (765) 973-2824                     >
<------------------------------------------------------------------->
---------------------------------------------------------------





Sun, 27 May 2001 03:00:00 GMT  
 LOGO-L> Re: Dynamic scope in Logo

Quote:

>It would be possible to write a de{*filter*} that walked back through the
>scopes to find the referenced variable

But I don't think any de{*filter*} for a lexically scoped language does so,
probably because...

Quote:
>Of course, the two different behaviors could cause confusion.  For
>example, if you get a "my.var has no value" error then type PR :MY.VAR
>at the debugging prompt and it works because MY.VAR was defined in a
>different scope.  It's not perfect.

In any case, I'm not trying to argue that dynamic scope is perfect, either.
I'm arguing that the unquestioned superiority of lexical scope for serious
programming has a high cost in required expertise, and that for beginners
the cost may outweigh the benefit.  Dynamic scope is, imho, part of the
"no threshold" promise of Logo.


Mon, 28 May 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. LOGO-L> Apple logo/MSW Logo

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

3. LOGO-L> scope problem

4. LOGO-L> Welcome to logo-l

5. LOGO-L> INFO re SIG-LOGO

6. LOGO-L> Logo speed

7. LOGO-L> Logo foundation site

8. LOGO-L> Logo Workshops

9. LOGO-L> Logo for MAC

10. LOGO-L> Object Logo for PC

11. LOGO-L>UCB Logo

12. LOGO-L> Re: Logo inside Scheme

 

 
Powered by phpBB® Forum Software