Comments on: The Story of ALTER
Alter is a mezzanine function that is a shortcut for alternating between insert and remove of a value.
Alter looks to see if a specified value is already part of a collection (in block). If not, it adds it. Otherwise, it removes it.
Here is an example:
>> flags: 
>> alter flags 'resize
>> alter flags 'maximize
== [resize maximize]
>> alter flags 'resize
Alter came about during the creation of VID(2), where we wanted to add or remove flag values from various blocks of flags.
Some users have suggested that the function is not worthwhile and should be removed from REBOL.
Should it be removed?
What about calling it TOGGLE? It could also be used for bitsets, and logic, including the new R3 named logic values. Is TOGGLE more meaningful than NOT?
For non-series values, you would have to pass in a referring word of course. And then you have to decide if it will be confusing, if VID has a 'toggle style.
I never use ALTER, so I can't say for sure if a name change will make a lot of difference. The functionality seems useful, but I've never even aliased ALTER as TOGGLE, so...
In REBOL 3 I would use the new logic! type for flags. Does anyone use ALTER for anything else, other than for flags?|
First - toggle is much better name, as we know toggle from VID for years.
Second - dunno if it is usefull as is, but I would welcome one additional refinement for that /replace. E.g. with SQLite, I very much welcomedn INSERT OR UPDATE clause, which saves some code and can be used often - sometimes you simply want to:
either not found? find series value [insert series value][.... replace code here not so easy ....]
But - it probably does not make sense for single value, but for pair of key, value, it does ...
ALTER doesn't support pairs of values or any other record-oriented use, but the map! type does. An insert-or-update function (named differently) may be a good idea though.|
I like ALTER very much (not the name, it can be changed to TOGGLE, I don't mind) and if it's removed from REBOL, I have to write my own version (as I did in the past), so please, do not remove it.|
I like it even I just learned it exists :-||
I use alter for removing from form fields unwanted keyed in characters|
jds, what do you do if the characters are not entered? ALTER would add the characters if they are not there. Perhaps REMOVE FIND would be better for you.|
please rename it to 'TOGGLE
although I have never used it in a decade of almost daily REBOL coding, just changing its name might have made me think of it more often (and might have changed a few expressions through the years, I guess).
I agree that the concept should be kept in the language. Flag series are a useful concept. It allows you to unify an association between a flag and a value associated with that flag (ie: the value being ALTERed can also hold code or data that the program needs to perform or return, in addition to serving as a flag). If used well it can reduce the amount of searching and cross-referencing someone reading the source code has to do (because of the afore mentioned unification of flag and value).
I disagree with naming it "TOGGLE". The reason being that ALTER appends the value to the end, whereas "TOGGLE" implies that it has remained in the same position (like a light switch), thus the name "TOGGLE" increases the chance of confusion.
However, I'm not sure if "ALTER" is the best name for it either. Perhaps change the word to "FLAG"?
I would like ALTER be renamed to TOGGLE.|
I just remember whenever I reached for ALTER, it didn't do quite what I wanted. What I wanted was "append if not found" (and its orthogonal sister "remove if found" now served by REMOVE FIND).
Post a Comment:
You can post a comment here. Keep it on-topic.