[REBOL] REP: Extend 'change 'poke functionality ...
From: petr::krenzelok::trz::cz at: 26-Dec-2000 15:37
If we want to change some value in a series, we have 'change function available.'Change
itself doesn't provide us with global functionality, as e.g. 'replace/all does. But using
'replace is not handy in many cases, as we have to know "what" we want to replace, which
is not the case all the time.
Let's assume following scenario:
img: make image! 100x100 
By above code we get 100x100 bitmap, and we can go immediately for display by simple
expression like "view layout [image img]".
Let's assume we want to change pixel values. We have two options:
1) traversing thru all pixels by iteration on per-pixel basis
2) and faster one - using change/dup, e.g. "change/dup img to-binary [255 255 255 0]
img/size/x * img/size/y"
In 2) you can see, that some global changes are much faster using change/dup, than pokeing
values into image in a loop.
In any way, those were just very simple operations, but what if I would like to change
every pixel in an image according to some expression/rule?
Some kind of dialect similar in principle to 'sort function dialect (when using /compare
refinement) could be introduced, allowing simple math expression to count pixel values
e.g., but could be used for any other purpose upon any kind of series ....
change/compare/dup img [value + 3] img-size
.... maybe even some dialect keywords for reading value at certain index could be introduced?
[v: value + (skip v 4)] etc ....
should /skip be introduce here too, if we have /dup and /part already?
Similar "dialect" extension could be available to other functions, as poke for e.g.
We now have 'parse, 'open, 'sort dialects, which proved themselves being extremly usefull.
Why prevent ourselves from introduction of other ones, if it could make certain operation
Comments welcomed as well ...