bind - What is the summary of the differences in binding behaviour between Rebol 2 and 3? -
the current in-depth documentation on variable binding targets rebol 2. provide summary of differences between rebol 2 , 3?
there isn't summary somewhere, let's go on basics, perhaps little more informally bindology. allow ladislav write new version of treatise r3 , red. we'll go on basic differences, in order of importance.
object , function contextshere's big difference.
in r2, there 2 kinds of contexts: regular object contexts , system/words. both had static bindings, meaning 1 time bind function run, word binding pointed particular object real pointer.
the system/words context able expanded @ runtime include new words, other objects weren't. functions used regular object contexts, hackery switch out value blocks when phone call function recursively.
the self word regular word happened first 1 in object contexts, display hack not show the first word in context; function contexts didn't have word, didn't display first regular word properly.
in r3, of different.
in r3 there 2 kinds of contexts: regular , stack-local. regular contexts used objects, modules, binding loops, use, functions, , expandable system/words (yes, "was", we'll that). old fixed-length objects gone. functions utilize stack-local contexts, (barring bugs haven't seen yet) aren't supposed expandable, because mess stack frames. old system/words can't shrink contexts, because removing words context break bindings of words out there.
if want add together words regular context, can utilize bind/new, bind/set, resolve/extend or append, or other functions phone call those, depending on behavior need. new behavior bind , append functions in r3.
bindings of words regular , stack-local contexts static, before. value look-up matter. regular contexts value look-up pretty direct, done simple pointer indirection static block of value slots. stack-local contexts value block linked stack frame , referenced there, find right frame have stack walk o(stack-depth). see bug #1946 details - we'll why later.
oh, , self isn't regular word anymore, it's binding trick, keyword. when bind blocks of words object or module contexts, binds keyword self evaluates reference context. however, there internal flag can set says context "selfless", turns self keyword off. when keyword turned off, can utilize word self field in context. binding loops, use , function contexts set selfless flag contexts, , selfless? function checks that.
this model refined , documented in involved curecode flame war, much r2's model documented rebol mailing list flame war in 1999-2000. :-)
functions vs. closureswhen talking stack-local function contexts above, meant contexts used function! type functions. r3 has lot of function types, of them native functions in 1 way or another, , native functions don't utilize these stack-local contexts (though stack frames). function types rebol code function! , new closure! type. closures different regular functions.
when create function!, you're creating function. constructs stack-local context, binds code body it, , bundles code body , spec. when phone call function makes stack frame reference function's context , runs code block. if has access words in function context stack walk find right frame , gets values there. straight-forward.
when create closure!, on other hand, create function builder. sets spec , function body pretty much same function!, when call closure makes new regular selfless context, bind/copy of body, changing references function context references new regular context in copy. then, when copied body, closure word references static of object contexts.
another difference between 2 in how behave before function running, while function running, , after function done running.
in r2, function! contexts still exist when function isn't running, value block of top-level phone call of function still persists too. recursive calls new value blocks, top-level phone call keeps persistent value block said, hackery. worse, top-level value block isn't cleared when function returns, improve create sure aren't referencing sensitive or want recycled when function returns (use also function clean up, that's made for).
in r3, function! contexts still exist when function isn't running, value block doesn't exist @ all. function calls deed recursive calls did in r2, except improve because it's designed way way down, referencing stack frame instead. scope of stack frame dynamic (stalk lisp fan if need history of that), long function running on current stack (yes, "current", we'll that), can utilize 1 of words @ values of most recent call of function. 1 time of nested calls of function return, there won't values in scope, , you'll trigger error (the wrong error, we'll prepare that).
there's useless restriction on binding out-of-scope function word on todo list prepare soon. see bug #1893 details.
for closure! functions, before closure runs the context doesn't exist @ all. 1 time closure starts running, context created , exists persistently. if phone call closure again, or recursively, another persistent context created. word leaks closure refers context created during particular run of closure.
you can't word bound function or closure context in r3 when function or closure isn't running. functions, security issue. closures, definitional issue.
closures considered useful ladislav , both ported them r2, independently @ different times resulting in similar code, weirdly enough. think ladislav's version predated r3, , served inspiration r3's closure! type; version based on testing external behavior of type , trying replicate in r2 r2/forward, it's amusing solution closure ended beingness similar ladislav's original, didn't see until much later. version got included in r2 starting 2.7.7, closure, to-closure , closure? functions, , closure! word assigned same type value function! in r2.
here's things interesting.
in bindology there big amount of article talking distinction between "global" context (which turned out system/words) , "local" contexts, of import distinction r2. in r3, that distinction irrelevant.
in r3, system/words gone. there no 1 "global" context. regular contexts "local" in sense meant in r2, makes meaning of "local" useless. r3, need new set of terms.
for r3, difference matters whether contexts task-relative, useful meaning "global" contexts ones not straight task-relative, , "local" contexts ones task-relative. "task" in case task! type, os thread in current model.
in r3, @ moment, things far task-relative (barely) stack variables, means stack-relative function contexts supposed task-relative too. why stack walk necessary, because otherwise we'd need maintain , maintain tls pointers in every single function context. regular contexts global.
another thing consider according plan (which unimplemented far), user context system/contexts/user , system intended task-relative, r3 standards considered "local". , since system/contexts/user closest thing r3 has r2's system/words, means scripts think of beingness "global" context supposed task-local in r3.
r3 have couple of scheme global contexts called sys , lib, though used quite differently r2's global context. also, module contexts global.
it possible (and common) there globally defined contexts referenced task-local root references, create contexts in effect indirectly task-local. happens when binding loops, use, closures or private modules called "user code", means non-module scripts, bound system/contexts/user. technically, case functions called modules (since functions stack-local) references assigned module words, global.
no, don't yet have synchronization either. still, that's model r3's design supposed have, , partly already. see module binding article more details.
as bonus, r3 has real symbol table instead of using system/words ad-hoc symbol table. means word limit r2 used nail pretty gone in r3. i'm not aware of app has reached new limit or determined how high limit is, though apparently on many 1000000 distinct symbols. should check source figure out, have access it.
minor details. use function initializes words none instead of leaving them unset. , because there no "global" context way there in r2, load doesn't bind words @ all. context load binds depends on circumstances mentioned in module binding article, though unless specify otherwise explicitly binds words system/contexts/user. , both mezzanine functions.
r3 same r2 in this, word bindings default case-insensitive. words case-preserving, , if compare them using case-sensitive methods see differences between words differ in case.
in object or function contexts though, when word mapped value slot, word bound context or looked @ runtime, words differ case considered same word , map same value slot.
however, found explicitly created aliases made alias function spelling of aliased words differed in other ways case broke object , function contexts drastically. in r2 resolved these problems in system/words, made alias simply awkward utilize in other demo, rather actively dangerous.
because of this, removed externally visible alias function altogether. internal aliasing facility still works because aliases words considered equivalent context lookup, means contexts don't break. recommend localization , other tricks alias used in demos, if never in practice, done using old-fashioned method of assigning values word new spelling.
the issue! type word type. can bind it. far, no-one has taken advantage of beingness able bind issues, instead using increased speed of operations.
that's pretty much it, intentional changes. of rest of differences might side effects of above, or maybe bugs or not-yet-implemented features. there might r2-like behavior in r3 result of bugs or not-yet-implemented features. when in doubt, inquire first.
binding bind rebol rebol3 rebol2
No comments:
Post a Comment