REBOL Technologies

Bring Out Your Idioms for R3

Carl Sassenrath, CTO
REBOL Technologies
28-Oct-2010 20:44 GMT

Article #0494
Main page || Index || Prior Article [0493] || Next Article [0495] || 30 Comments || Send feedback

Now that the sys/lib/user context split has been completed for R3, over the next few weeks/months we will be evaluating possible idioms for inclusion into the standard mezzanine layer. These functions will be available to all programs on startup.

The best idioms are patterns that you encounter often while coding, and a name can be found that accurately represents them (a good abstraction.) The worse idioms are ones that you imagine you want, but have never actually used, or ones for which no good name can be found.

Here's a good candidate for an idiom. It's a code pattern that I use quite often: repeatedly find specific values in a string, binary, block or other series and do something with them. It looks like:

while [series: find series value] [
    do-something series
    ++ series
]

It's somewhat like w:forall so in A110 I've added an idiom called w:find-all that does it:

find-all series value [
    do-something series
]

So, w:find-all does something useful that I write quite often, and it has a good name.

Here's another pattern I encounter often: modifying the value that's found by a w:select (the w:next of a w:find) or w:append it if not found. The pattern is:

either w: find series id [
    change next w value
][
    append append series id value
]

It's not easy to name. Perhaps "modify". Abstractly it is a w:change-select but that name isn't great. The usage would be:

modify series id value

But, that name isn't final. Got a better one?

If you have an idiom that you use often, and you'd like to see it become part of R3, you can submit it in the idioms group as a message or a file.

Example of how you submit an idiom in R3:

carl:R3>> fh idiom
  754 H Idioms                                        21 Carl     2m ago

carl:R3>> 754
R3/Language/Idioms:

Alerts and Banners:
For proposing common idioms. [banner 755]
Last 32 messages...
  2539   I don't get it; to check in a loop u use t   754 Steeve   6-Mar-2009
  2540   More i think about small idioms , more i t   754 Steeve   6-Mar-2009

carl:R3/Language/Idioms>> p
Enter public message (in #14) Use . to send, / to cancel, ! to paste.
FIND-ALL is an idiom I use often:
   while [series: find series value] [
       do-something series
       ++ series
   ]

or, if you have it coded, you can submit the file:

carl:R3/Language/Idioms>> submit find-all.r
Add comment (/ to cancel submit): FIND-ALL

We will review all submitted idioms, and if they look useful, we will be included in coming releases.

30 Comments

Updated 11-Nov-2024   -   Copyright Carl Sassenrath   -   WWW.REBOL.COM   -   Edit   -   Blogger Source Code