-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WISH: how about we reduce on-deep-change*
?
#92
Comments
Side note first: We should extract the ownership notes from https://www.red-lang.org/2016/03/060-red-gui-system.html into object docs or the Reducing code is almost always a good thing, but often doesn't come for free. We lose What I love about this new model is the efficiency of aggregate thinking. It would be interesting is to look at the |
I plugged the ownership content into the ownership page, but it would benefit from more formatting. |
In red/red#4788 I'm proving that:
|
Let's replace
|
Also, insignificant probably, but we don't need Unless.. it's there for some future model where it will be different from |
I take back the idea about 8 of the 13 actions: Example: list of 1M items (a string maybe?), we change the 1st char. In the 4-call model we would have to produce a correct intermediate state of the series after removal, that is, we'll have to shift 999999 items back, call We could add a 'substitution' operation and split mixed operations into two (e.g. change -> substitution + removal/insertion), but that's a complication we probably don't even need (current model certainly never longed for it). So I leave this idea for now. I propose, case-by-case:
It is also tempting to get rid of "before insertion" and "after removal" calls totally. Why do we need them? Since we lose them for 8 or 13 actions anyway, why have them for the other 5? If we do so
|
Answering my own "Why do we need them?" question above, we don't need "after removal" at all IMO. "before insertion" we don't need for observers but we may need it for validators (that throw an error to forbid the change). And that's when it aaaall geeets triiickkyy... The current model does not provide any more validation capabilities than the new one save for the trivial synthetic example in the blog entry. Consider the
We need to know, before items are inserted, what items those will be?
But what about more complex validators? E.g. P.S. considering all said, reasonable tradeoff for me is validation of data "after insertion". It's not validation anymore, but rather "fixing". But on the bright side, no intermediate states needed, and since all data is present, any kind of validation is possible (removal of improper items, reordering, formatting, whatever). It's slow of course, like in the example from the blog post, but will do for small lists. One more point for the idea of getting rid of "before insertion" and "after removal" states altogether. |
@greggirwin what page is that "ownership page" exactly? ;) |
Just a quick thought on the name |
Mockup of this design here: https://gitlab.com/hiiamboris/red-mezz-warehouse/-/blob/master/reactor92.red |
Simple example:
list: [item1 .. itemN]
.list-length = sum map-each item list [item/length]
Instead of recomputing the
list-length
every time I make changes, I could employon-deep-change*
and meticulously write length tracking code for all modifying series actions. There aren't that many:insert change clear append move poke put random reverse sort swap take trim
.First, that makes 13 actions. Each is duplicated (before and after the change), e.g.
append
-appended
,put
-put-ed
, etc. So that makes 26 cases to account for! Madness! I would appreciate a lot if this model could be simplified.Each series-modifying action can be composed from only two elementary actions: insertion and removal of a single item (say hi to Levenshtein). Covering just two such actions in
on-deep-change*
would be a huge lot less painful (transition from one model into another can be done on mezz level, but we want maximum speed for this part). This requires 3 things:index [integer!]
(where?),insert? [logic!]
(what? - insert or remove) anddone? [logic!]
(when? - before or after the change).Adding a
part [integer!]
(item count) to this simplest model makes sense, because there's always some initialization code that we don't wanna repeat for each item.We want to keep track of items that are just rearranged (that is, source = target), e.g. for the example above
random reverse sort
do not affect the length. Let's add amoving? [logic!]
flag to deal with it. Now we know when not to bother.This is the interface I would like to work with:
on-deep-change*: func [owner [object!] word [word!] offset [integer!] part [integer!] insert? [logic!] moving? [logic!] done? [logic!]]
.We can add the action name (list of 13, not 26) here but only for better logging purposes e.g.
"append <here> of <N> items"
.In this model
change
would trigger 4 calls: before removal, after removal, before insertion, after insertion. Obviously, after removal and before insertion is the same state, so to further simplify it we could unifyinsert?
anddone?
intostate = removing | adding | done
, but this seems less useful: e.g. for the above example I would useremoving
to subtract from the length, thendone
to add to it, but how would I differentiatedone
afteradding
(which I would use) fromdone
afterremoving
(which I could care less about)? I would need to save the previousstate
and that's more work.Thoughts?
The text was updated successfully, but these errors were encountered: