Comments on: The Story of ALTER

Carl Sassenrath, CTO
REBOL Technologies
4-Apr-2008 0:02 GMT

Article #0124
Main page || Index || Prior Article [0123] || Next Article [0125] || 11 Comments || Send feedback

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
>> flags
== [resize]

>> alter flags 'maximize
>> flags
== [resize maximize]

>> alter flags 'resize
>> flags
== [maximize]

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?



Gregg Irwin
4-Apr-2008 22:18:33
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...

Brian Hawley
5-Apr-2008 0:01:02
In REBOL 3 I would use the new logic! type for flags. Does anyone use ALTER for anything else, other than for flags?
5-Apr-2008 3:44:59
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 ...

Brian Hawley
5-Apr-2008 12:44:10
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.
7-Apr-2008 4:34:35
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.
7-Apr-2008 7:40:10
I like it even I just learned it exists :-|
8-Apr-2008 3:43:39
I use alter for removing from form fields unwanted keyed in characters
Brian Hawley
8-Apr-2008 9:49:57
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.
maxim olivier-adlhoch
10-Apr-2008 13:00:53
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).

12-Apr-2008 16:46:37
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"?

Anton Rolls
27-May-2008 7:07:48
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.


Blog id:



 Note: HTML tags allowed for: b i u li ol ul font span div a p br pre tt blockquote

This is a technical blog related to the above topic. We reserve the right to remove comments that are off-topic, irrelevant links, advertisements, spams, personal attacks, politics, religion, etc.

Updated 24-Mar-2017 - Edit - Copyright REBOL Technologies -