[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: LOGO-L> closures?




Thanks for the clear explanation of the concept of closure.

I found two way of writing a working make.adder

Make.adder2 seems to be close of the concept of closure,it uses optional inputs as the block of data.

to make.adder :name :num
 define :name list [x] (list  "output ":x    "+ :num) 
end

make.adder "add3 3 ; defines the procedure add3

to add3 :x
output :x + 3
end

show add3 3
6


to make.adder2  :name :num
 define :name   list list "x  list "num :num  [output :x + :num]
end

make.adder2 "add5 5 ; Defines the procedure add5

to add5 :x [:num 5]
output :x + :num
end


show add5 3
8



  

This is comment to :

>Please reply to bh@anarres.CS.Berkeley.EDU (Brian Harvey)  or 
>logo-l@gsn.org   NOT   logo-list@gsn.org  or  me.
> 
>                        -John-
>--Message below re-posted by <jstclair@omsd.cerf.fred.org>
>Date - 26 May 1998 13:34:51 GMT
>From - bh@anarres.CS.Berkeley.EDU (Brian Harvey)
>To - jcstclair@omsd
>Subject - Re: LOGO-L> closures?
>Usenet: comp.lang.logo
>------------------
>Post Usenet mail to comp-lang-logo@ucbvax.berkeley.edu
>------------------
>
>fajoy@uio.satnet.net writes:
>>Is it pertinent to ask: what are closures? 
>
>In Logo, a procedure is just its text -- that is, the only information
>in a procedure is what you typed to define it.  When the procedure is
>called, values for variables (other than the procedure's own inputs)
>come from whatever values they might have when the procedure is called.
>
>A "closure" is a lexically scoped procedure, which has two parts:
>the text, as in Logo, and a record of the variables that are available
>at the time the procedure is *defined*.  It's called a closure because
>the entire meaning of calling the procedure is known when the procedure
>is created -- nothing is open to be discovered when the procedure is
>called.
>
>It really only matters in subtle situations.  Consider the following
>*INCORRECT* Logo session:
>
>? to make.adder :name :num
>> define :name [[x] [output :x + :num]]
>> end
>
>? make.adder "plus3 3
>
>? print plus3 5
>
>The desired result is 8; the actual result is NUM HAS NO VALUE.
>If Logo were lexically scoped, the procedure PLUS3 that's defined
>inside MAKE.ADDER would include not only its text but also the
>information that, at the moment it was defined, NUM had the value 3.
>
>(So why doesn't Logo use lexical scope?  Most computer scientists
>now agree that lexical scope is the right thing.  But Logo's dynamic
>scope allows us to write things like MAP in Logo.  Consider this:
>
>to scale :scalar :vector
>output map [? * :scalar] :vector
>end
>
>? show scale 5 [1 4 9]
>[5 20 45]
>
>Inside MAP, the list [? * :SCALAR] is run.  In a lexically scoped Logo,
>it would refer to whatever value SCALAR had when MAP was defined, if
>any, rather than what we want, which is the value of SCALAR when MAP
>is called.
>
>Lexically scoped languages can, of course, write things like MAP, but
>the techniques required are, imho, harder for a beginner to understand
>than the way Logo does it.)
>                                  
>
>
>


Free web-based email, Forever, From anywhere!
http://www.mailexcite.com
---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home