Hi, Mark,

[EMAIL PROTECTED] wrote:
> 
> Joel Neeely [sic]/ everybody,
> 
> perhaps you misunderstood my previous post,
>

Perhaps the wording of the previous post was capable
of being understood in different ways...

>
> my concern was that uninitialised local words
> are treated differently between contexts and
> function-contexts.
> 
> Please see below,
> 
> >> use [my-word] [print unset? get/any 'my-word]
> true
> >> my-func: has [my-word] [print unset? get/any 'my-word]
> >> my-func
> false
> >> my-func: has [my-word] [print none? get/any 'my-word]
> >> my-func
> true
> >>
> 
> In a use context they are initialised to the unset! value
> if they are not set BUT in a function context they are
> initialised to the none! value and that's what bothers me.
> 

Is this a philosophical bothering, or is there some specific
problem that arises from the distinction?

>
> I don't see a reason or logic for the distinction, can
> anybody please explain why these contexts are treated
> differently, as from what I can see it is possible to use
> uninitialised words in function contexts, well they're not
> actually uninitialised as REBOL sets them to 'none during
> function context creation, but WHY?
> 
> What makes function contexts a special case?
> 

I don't know about the original design thinking or intent
but we *do* know a little bit about the difference between
FUNC and USE that might be relevant.

1) The naive use of FUNC creates a value that will persist
   (for some time) between evaluations.  Since REBOL retains
function contexts between uses, perhaps there was some
perceived benefit (either for user or implementor) to
ensuring that each word in the context is associated with
*some* value at all times -- even before first evaluation.

2) The naive use of USE creates a "temporary" context that
   allows one to perform an evaluation using some temporary
word names without worrying about whether those names are
already in use in the surrounding environment.  Perhaps
there was more of an assumption that the user would have
an immediate purpose for declaring the words of the new
context and would naturally initialize them appropriately
anyway.

Two caveats with the above:

1) I used the word "naive" above not to give offense, but
   to distinguish the simplest and most obvious uses of
those features from the more subtle uses normally made by
more experienced (or devious ;-) programmers:

   a) One can certainly create anonymous functions for
      ad hoc usage (such as the comparison of SORT)
   without expecting the function to persist for any
   significant amount of time.  (Someone who is tempted to
   reply that the comparision function can be called many
   times in a single invocation of SORT should be skilled
   enough to think of plenty of use-once examples...)

   b) One can certainly utilize USE in the construction of
      closures, which *are* expected to persist.  (However
   someone who is skilled enough to write closures should
   be able to manage initialization...)

In any case, we sometimes see design decisions (in many
languages in addition to REBOL) driven by the expectations
of the "commonest" use of a language feature.

2) We should probably be cautious about assuming this
   difference in behavior was deliberate and not simply a
matter of different code, perhaps written by a different
person, perhaps at a different time, exhibiting different
behavior for no preconceived purpose.

Sometimes things are the way they are just because that's
how they are.

-jn-

-- 
; sub REBOL {}; sub head ($) {@_[0]}
REBOL []
# despam: func [e] [replace replace/all e ":" "." "#" "@"]
; sub despam {my ($e) = @_; $e =~ tr/:#/.@/; return "\n$e"}
print head reverse despam "moc:xedef#yleen:leoj" ;
-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to