Comments on: Calling all idioms!
REBOL Technologies

Comments on: Calling all idioms!

Carl Sassenrath, CTO
REBOL Technologies
25-Jan-2009 17:05 GMT

Article #0387
Main page || Index || Prior Article [0386] || Next Article [0388] || 8 Comments || Send feedback

I want to add some common idioms to R3.

Idioms are kind of like the salt you add at the end of the stew. You don't want to add the salt too soon, because you need to taste the flavor first.

I've held back on adding idioms over the years, because such things are not very useful unless they get documented. Now that we have the DocBase wiki, that documentation can be added and maintained.

Also, idioms don't take much space, and they enhance the language with a standard, meaningful vocabulary.

But, in order to qualify, the idiom must be short, clear, useful, and have a good name. If I don't understand the code, it won't get added. And, if a good name cannot be found, then maybe the idiom isn't such a good one?

As an example idiom, here's a pattern many of us write fairly often when we write included script files:

unless value? 'fee [fee: 10]

The line says: if fee is not already defined, then give it a value. It wants a default value for a variable.

The idiom could be:

default fee 10

Yes, we've talked about this one before.

The definition would be:

default: func [
   "Sets word to a default value if not already set."
   'word [word!]
   unless value? word [set word value]

Ok, if you have a favorite, you can post it using the R3 CHAT command under #754 (R3/Idioms). If you do not have R3, watch the website over the next day or so. If you cannot wait, or do not plan to try R3 soon, then you can post it here in the comment section or on one of the many AltME worlds where someone can relay it to the R3 team.



just me
25-Jan-2009 12:09:07

idea is nice but do we need another reserved word in global context? "default" is quite popular name for variable.


fee: any [fee 10]

Grant Rettke
25-Jan-2009 12:31:13
just me:

If the module system allows for renaming on import you won't have to worry about stuff like this.

Brian Hawley
25-Jan-2009 14:39:12
Modules make the your problem go away, just me - there are no more reserved words in REBOL 3, even to the limited extent there ever were in REBOL.

I like this DEFAULT function, though it should also set the word if its value is NONE before, to handle the common case of function parameters made optional using refinements.

Greg Schofield
25-Jan-2009 15:07:48
I don't know if this suggestion is what you are thinking about, but a default value being set, needs to be easily reset to the default.

Ie, "reset fee" ideally resets the variable to its default values, anyhow something better than "fee: fee/default-value"

For the penalty of keeping copies of values adding in "reset" (first setting the value to the refinement "fee/default-value" then "reset fee" = "fee: fee/default-value"

I am too much of a newbie to have any opinion whether the extra clutter is worthwhile, theoretically I can see a bonus of working with the one word to get things done to make the script clearer and simpler to read. My usual fix which is to keep the default values separate and reassign them is not elegant.

Brian Hawley
25-Jan-2009 15:40:58
Greg, what you are talking about is much higher level than default values in the REBOL language. In REBOL all variables are by default either unset (for globals and object fields) or none (for everything else).

You are talking about keeping track of what the default value is supposed to be after the variable was set. We are talking about figuring out whether the variable has been set at all, and then choosing a different default than just unset or none.

Peter W A Wood
25-Jan-2009 16:05:37
If these idioms are all going to be mezzanine functions, it would make sense for them to be collected in a module that is optionally loaded and not added to the Rebol core.

In fact, it would be ideal if all the mezzanines which are designed to make coding quicker (e.g. to-string, to-integer, func, function, context) were moved to optionally loadable modules.

This would then give people the choice of running a really lean Rebol.

Carl Read
25-Jan-2009 16:58:03
I don't like the idea of modules for commonly used words. It'd mean having to include some of them with most every script you write, making even simple scripts look a bit cumbersome. And it adds another layer to the learning of REBOL - namely which module is word X in.
Greg Schofield
25-Jan-2009 23:35:42
Thanks Brian, thought I was probably off track.

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 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 17-Nov-2017   -   Copyright Carl Sassenrath   -   WWW.REBOL.COM   -   Edit   -   Blogger Source Code