scoped crm114 script variables --> in case you were wondering about match/bound vars, or: two mind altering substances that come out of MA, USA

Ger Hobbelt <[email protected]>
Newsgroups gmane.mail.spam.crm114
Message-ID <[email protected]>
No worries then. The current (yet unpublished) code keeps the bound
var intact, when the other variable has become invisible due to going
out of scope.

Take this test code:

--------------------------
#
# check survival of bound variables residing in outer scope:
#
window


   isolate (:a:) /Foo!/        # a is of global scope
   call /:capture_func:/
   output /:*:_cd:: :a: is :*:a:, :z: is :*:z:, :b: is :*:b:\n/
   call /:bu1:/
   output /:*:_cd:: :a: is :*:a:, :z: is :*:z:, :b: is :*:b:\n/
   call /:bu2:/
   output /:*:_cd:: :a: is :*:a:, :z: is :*:z:, :b: is :*:b:\n/
   call /:bu3:/
   output /:*:_cd:: :a: is :*:a:, :z: is :*:z:, :b: is :*:b:\n/

   exit /0/


   :capture_func:
   isolate (:z:) /abcdefghijklmnop/           # make :z: be local
   match [:z:] /...(...).../  ( :: :a: )      # capture :a: into :z:
   match <keep> [:z:] /(......).../  ( :: :b: )      # capture :b: into :z:
   output /:*:_cd:: :a: is :*:a:, :z: is :*:z:, :b: is :*:b:\n/
   alter (:z:) /If it sprouts legs, I don't want to know about it./
   output /:*:_cd:: :a: is :*:a:, :z: is :*:z:, :b: is :*:b:\n/
   return

   :bu1:
   isolate (:z:) /yucky! no.1!/
   output /:*:_cd:: :a: is :*:a:, :z: is :*:z:, :b: is :*:b:\n/
   return

   :bu2:
   isolate (:z: :a:) /yucky! no.2!/
   output /:*:_cd:: :a: is :*:a:, :z: is :*:z:, :b: is :*:b:\n/
   return

   :bu3:
   isolate (:a:) /toodels/
   alter (:z:) /ook! ook! banana!/
   output /:*:_cd:: :a: is :*:a:, :z: is :*:z:, :b: is :*:b:\n/
   return
--------------------------

This will produce on bleeding edge GerH, which has full support for
scoped variables:

------------------------
1: :a: is def, :z: is abcdefghijklmnop, :b: is abcdef
1: :a: is now, :z: is If it sprouts legs, I don't want to know about
it., :b: is If it sprouts legs, I don't want to know
0: :a: is now, :z: is :z:, :b: is If it sprouts legs, I don't want to know
1: :a: is now, :z: is yucky! no.1!, :b: is If it sprouts legs, I don't
want to know
0: :a: is now, :z: is :z:, :b: is If it sprouts legs, I don't want to know
1: :a: is yucky! no.2!, :z: is yucky! no.2!, :b: is If it sprouts
legs, I don't want to know
0: :a: is now, :z: is :z:, :b: is If it sprouts legs, I don't want to know

crm114: *WARNING*
Attempt to alter the value of a nonexistent variable, so I'm creating
an ISOLATED variable.  I hope that's OK.  The nonexistent variable is:
3/3: ':z:'/':z:'
I'll try to keep working.
This happened at line 41 of file
/windows/G/prj/3actual/crm114/tests/var_scope_check1.crm:
    alter (:z:) /ook! ook! banana!/
(runtime system location: crm_var_hash_table.c(1206) in routine:
crm_destructive_alter_nvariable)
1: :a: is toodels, :z: is ook! ook! banana!, :b: is If it sprouts
legs, I don't want to know
0: :a: is now, :z: is :z:, :b: is If it sprouts legs, I don't want to know
------------------------

and on vanilla it outputs this:

------------------------
1: :a: is def, :z: is abcdefghijklmnop, :b: is abcdef
1: :a: is now, :z: is If it sprouts legs, I don't want to know about
it., :b: is If it sprouts legs, I don't want to know
0: :a: is now, :z: is If it sprouts legs, I don't want to know about
it., :b: is If it sprouts legs, I don't want to know
1: :a: is now, :z: is yucky! no.1!, :b: is If it sprouts legs, I don't
want to know
0: :a: is now, :z: is yucky! no.1!, :b: is If it sprouts legs, I don't
want to know
1: :a: is yucky! no.2!, :z: is yucky! no.2!, :b: is If it sprouts
legs, I don't want to know
0: :a: is yucky! no.2!, :z: is yucky! no.2!, :b: is If it sprouts
legs, I don't want to know
1: :a: is toodels, :z: is ook! ook! banana!, :b: is If it sprouts
legs, I don't want to know
0: :a: is toodels, :z: is ook! ook! banana!, :b: is If it sprouts
legs, I don't want to know
------------------------

Now, about those bound vars, you were saying? Did you expect :a: to
end up like that after that alter-mod to :z:?
I didn't.
And :b: also sees an interesting change, which isn't entirely sensible.
Which proves indirectly that I didn't dig into that binding/altering
code, other than kill some invertebrates in the area.
All I can say is I'm glad GerH is truly compatible with vanilla in
that regard: both are trippy, though.


Anyway, what you're seeing here as well is the effect of :z: going out
of scope every time.
And isolate having the effect of 'overriding' (i.e. 'hiding') the
outer scope variable of the same name (no <keep> in :bu2: nor :bu3:,
eh?), an effect which, of course, disappaears as soon as the inner
scope :a: instance goes out of scope.
Not shown here is the fact that :z: is not 'static', i.e. :z: remains
invisible, even when :bu2: is already running, but has not yet reached
the :z:-instantiating 'isolate' statement.

Also note that here is a prime example of the more profound error
checking done by GerH: alter isn't expected to have to act on a
nonexistent var, so GerH (correctly) yaks about it, if ever so softly
(not a trap, just a warning). vanilla just barges on.

Last but not least: note the use of the internal :_cd:, which is used
to good effect here as it shows exactly what the scope level is at the
time each of these lines is printed (global scope: level = 0).


-- 
Met vriendelijke groeten / Best regards,

Ger Hobbelt

--------------------------------------------------
web:    http://www.hobbelt.com/
        http://www.hebbut.net/
mail:   [email protected]
mobile: +31-6-11 120 978
--------------------------------------------------

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.