Home   Archive   Permalink



Tips and Tricks

This topic is for adding useful REBOL tips and tricks. One of the most often asked questions by new users is where to find help on VID words, which are not available with the "help" function. These lines provide a lot of useful information:
    
editor extract svv/vid-styles 2 ; built in widgets
editor svv/vid-words ; layout words
editor svv/facet-words ; adjustable properties of widgets
svv/vid-styles/TEXT-LIST/words ; access the specific words related to individual widgets

posted by:   Nick     23-Aug-2010/9:48:11-7:00



Here is a very nice way to learn how to write functions in Rebolish way?
    
Open console, type "? function!". This will show all the predefined functions which was written by Carl and other Rebol gurus.
So you can learn and improve yourself by examining these functions.
Just pick one of them like INPUT, READ-CGI etc. them type "?? READ-CGI"

posted by:   Endo     24-Aug-2010/10:46:06-7:00



A great extension of that idea is to use the following format to open the source of mezzanine functions in the built-in REBOL text editor:
    
     editor mold :read-cgi ; choose a function
    
You can make changes to the built in functions, and assign new words to your changed functions, like this:
    
     request2: do replace/all mold :request "bold" ""
     request2/ok/type "An alert without bold text" 'alert
    
That's a simple way to dig into code in a hands-on way, and to customize REBOL mezzanines :)

posted by:   Nick     24-Aug-2010/15:56:47-7:00



How to create a block of random number / How Rebol uses series aggressively
    
Well, this is very easy for sure:
     r: [] loop 10 [append r random 100]
    
Here is a better way:
     r: loop 10 [append [] random 10]
    
Or even:
     r: loop 3 [loop 5 [append [] random 10]]
    
As you can see [] is initialized just once and used for whole life cycle of the loops. This is an example of how Rebol aggressively use series!.
    
Or even better:
loop 3 [loop 5 [append r: [] random 10]]
    
Why this is better? Because, your loops can do something and return something else while filling up r.
    
Here is an example:
     loop 3 [loop 5 [append r: [] random 10] print "."]
    
This won't work if you do:
r: loop 3 [loop 5 [append [] random 10] print "."]
    
** Script Error: r needs a value


posted by:   Endo     25-Aug-2010/15:06:57-7:00



Converting tab separated string to html table
I use this function often, so it may help someone else:
    
     to-table: func ["Returns a html table from tab separated string." t /local s] [
         s: copy ""
         append s reduce [ newline]
         foreach row parse/all trim copy t "^/" [
             append s
             foreach col parse/all row "^-" [
                 append s reduce []
             ]
             append s reduce [ newline]
         ]
         append s reduce [
col
newline]
     ]
    
And this is also very useful:
    
     clipboard-to-table: has [s] [
         write clipboard:// s: to-table read clipboard://
         s
     ]


posted by:   Endo     14-Sep-2010/5:31:19-7:00



Between function
    
  
    between: func [
        "Returns true if x is between a and b (a & b included)
        a [number!] b [number!] x [number!]
    ] [1 <> multiply sign? a - x sign? b - x]

    
>> between 5.3 6.9 5.9
== true
    
>> between 10 5 8
== true
    
>> between 5 5 5
== true
    
>> between 2 3 4
== false


posted by:   Endo     6-Dec-2011/12:41:31-8:00



    between: func [
         "Returns true if x is between a and b (a & b included)"
         a [number!] b [number!] x [number!]
     ] [1 <> multiply sign? a - x sign? b - x]


posted by:   Endo     6-Dec-2011/12:42:52-8:00



I released this topic from the top of the page stickies, since the last addition was over a year ago. It will continue to be available, and eventually archived as a normal message.

posted by:   Nick     4-Dec-2012/0:11:31-8:00