Hi folks,
After my previous post about a model which could extract a part of a
complex structure inside another model, I had a go at it myself as follows:
TUPLE: partmodel < model master extractor updater ;
: partmodel-fetch ( partmodel -- )
dup [ master>> value>> ] [ extractor>> ] bi call( master -- part ) swap
set-model ;
: new-partmodel ( master extractor updater class -- partmodel )
f swap new-model swap >>updater swap >>extractor [ add-dependency ] [
swap >>master ] 2bi dup partmodel-fetch ;
M: partmodel model-changed
nip partmodel-fetch ;
M: partmodel update-model
dup master>> locked?>> [ "Warning: partmodel failing to update master"
. drop ] [
dup [ master>> value>> ] [ value>> ] [ updater>> ] tri call(
mastervalue newslavevalue -- )
master>> [ [ update-model ] [ notify-connections ] bi ]
with-locked-model
] if ;
: <partmodel> ( master extractor updater -- partmodel ) partmodel
new-partmodel ;
: <nthmodel> ( master index -- partmodel )
[ '[ _ swap nth ] ] [ '[ _ rot set-nth ] ] bi <partmodel> ;
Notice that I ended up having to roll my own notification inside
update-model because using set-model doesn't seem appropriate given that
the reference to the higher level structure will not change and most of the
functions for updating parts of complex structures act in place and pop the
old reference form the stack.
The problem however occurs when I create a <partmodel> whose master is an
<arrow>. In this case, even when I add it to a UI element, the <arrow> does
not seem to be activated and does not fetch its value. This seems odd as
the partmodel should have the arrow added to its dependency list in
new-partmodel before being activated itself. Am I doing something terribly
wrong?
Mark
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk