Home   Archive   Permalink



Your best/most use rebol one to five liners are...

I am planning on using examples of 1-5 lines rebol script as a basis for an educational tool in order to introduce rebol concepts to interested parties.
    
Your input are appreciated.

posted by:   Danie     18-Feb-2016/2:12:27-8:00



These links should be a help http://www.rebol.com/oneliners.html & http://www.rebol.net/cookbook/

posted by:   Peter Wood     18-Feb-2016/5:03:56-8:00



Do you mean five-line code "snippets" that one uses often in larger programs, sort of like "REBOL idioms," or do you mean complete programs that condense some useful operation into about five lines?
    
I remember having a lot of trouble understanding some of the more compact programs I would find in various places. On the other hand, I suspect that a well-done complete five-line program PLUS a real person explaining it, word by word if necessary, would be very helpful in getting a person "off on the right foot" so to speak.

posted by:   Steven White     18-Feb-2016/20:26:49-8:00



These are my favorite short scripts:
    
http://re-bol.com/short_rebol_examples.r
    
There a few of my favorite one liners at the end, and a variety of really short ones throughout.

posted by:   Nick     18-Feb-2016/23:44-8:00



Steve, my thoughts are to use the snippets in a tool like nano-sheets or rebocalc. Also introduce a way to simulate program flow - branching, loops etc.
    
Thanks to both of you, Nick and Peter for your input.

posted by:   Danie     19-Feb-2016/1:04:18-8:00



Here is a little item I use a bit. I think it came from the REBOL cookbook. The version I use is a little more verbose because I like it that way, but it can be trimmed down to about five lines. It is the operation of reading any file and converting it to what I believe is base 64 encoding so it can be embedded in a program. The version below does have one interesting feature that could be confusing to a beginner, depending on background.
    
Often when one sees an "if" statement (or "either" in REBOL as a shortcut for "if...else"), one expects a condition after the word "if." But "if" in REBOL seems to be different. It is a function that takes some value that can be evaluated as true or false. That value can be the value of a word, and if the value is "none" the "if" will evaluate to false, but if the value is "not none," that is, anything else, the "if" will evaluate to true. That is why one can run the functions together on the line of code below, where the "request-file" function will return either a file name or "none" if the "cancel" option is selected, and the resulting file name will be set as the value of the word IMAGE-FILE, and then the value of IMAGE-FILE can be passed to the "either" function to determine if a file was selected. In other words, seeing a condition word like "if" or "either" followed by something that does not look like a condition, can be confusing, until one uses it so much it becomes second nature, and then one can't understand why someone else can't understand.    
    
So anyway, here is the program, complete, five lines of code but a few extras as headers and such.
    
R E B O L []
system/options/binary-base: 64
either IMAGE-FILE: request-file/only [
     save clipboard:// read/binary IMAGE-FILE
     alert "File is loaded on clipboard"
] [
     alert "No file specified"
]

posted by:   Steven White     19-Feb-2016/16:12:58-8:00



And in the category of the clipboard, here is something I made extensive use of during a little burst of documenting. I needed a quick way to indent a bunch of text lines by the standard four spaces. The procedure became to select the text lines in the text editor, CUT them to the clipboard, then run the program below, then past the clipboard back into the place where the lines were initially cut. Five line, plus the header.
    
R E B O L []
TEMP-LINES: read clipboard://
insert/dup TEMP-LINES " " 4
replace/all TEMP-LINES newline rejoin [newline "    "]
write clipboard:// TEMP-LINES
alert "Clipboard loaded"
    
I extracted the above from a web site where I am attempting to store some documentation that I have produced, plus some useful code examples. I could be retiring in a couple years, and I will have left behind what has turned out to be quite a few REBOL programs, more than I have time to rewrite in something more mainstream. The only alternative I see is to make sure that what I have done is well-documented.
    
http://www.cobolrebol.com/pages/documentation/RebolBites.html


posted by:   Steven White     19-Feb-2016/16:25:07-8:00