author: patrick philipot date: 9-feb-2002 purpose: help mostly for newbies
Here is a list of FAQ I have collected while learning the basics of rebol. This material has been submitted, and validated, to and by the rebol-list. HTH.
This page has been generated with Robert M. Münch make-doc-pro.r. You can download make-doc-pro from Robert site :
http://www.robertmuench.dein system/locale/days and system/locale/months
foreach item system/locale/days [print item] Monday Tuesday Wednesday Thursday Friday Saturday Sunday foreach item system/locale/months [print item] January February March April May June July August September October November December
Using append/only
>> a: array [2 2] == [[none none] [none none]] >> b: func [n][compose [(n) (n)]] >> b 3 == [3 3] >> append a b 3 == [[none none] [none none] 3 3]
However b 3 returns a block, append will use only the values.
>> append/only a b 3 == [[none none] [none none] 3 3 [3 3]]
The /only refinement is an answer to this problem.
Using compose or reduce
b: func [n][return [n n]] b 3 ;== [n n]
The result of b 3 is [n n] where one obviously expects [3 3].
new-b: func [n][return compose [(n) (n)]] new-b 3 ;== [3 3] ; or new-b: func [n][return reduce [n n]] new-b 3 ;== [3 3]
Compose forces the evaluation of the parens (n).
Reduce evaluate the block contents.
Using 'get in object-name 'function-name
We want to assign a function with another function which is defined in an object.
Direct assignment is not allowed.
Example of direct assignment.
write: :print write "Hello World!" ; Hello World!
Example with an object function
obj: make object! [ i: 3 print-i: does [print i] ] fn: :obj/print-i 3 ** Script Error: fn needs a value ** Where: do-boot ** Near: fn: :obj/print-i
fn: get in obj 'print-i fn 3
With 'on right after
In the following layout, both checks are unchecked, which is the default.
Rebol [title: "FAQ"] view center-face layout [ banner "Check-boxes" across check text "check box n° 1" check text "check box n° 2" ]
Just using on or off (yes, no, true, false) will suffice..
Rebol [title: "FAQ"] view center-face layout [ banner "Check-boxes" across check on text "check box n° 1" check off text "check box n° 2" ]
Thanks to the helpful contribution from: Allen Kamp
Using 'get
An object function must be set to an outside function.
obj: make object! [ name: "obj" obj-func: none ] fn1: does [print "Hello Rebollers"] fn2: func [ f [function!] ][ print "My task is to affect obj/obj-func with fn1" obj/obj-func: f ] >> fn2 fn1 Hello Rebollers ** Script Error: fn2 expected f argument of type: function ** Where: do-boot ** Near: fn2 fn1 >>
Get must be used twice: (1) in the fn2 definition. (2) in the fn2 call.
fn2: func [ f [function!] ][ print "My task is to affect obj/obj-func with fn1" obj/obj-func: get 'f ] fn2 get 'fn1 My task is to affect obj/obj-func with fn1 obj/obj-func Hello Rebollers
Using as-is and a negative height such as 400x-1
rebol [] ; This program shows a one line text. ; The multi-line text to display ; multi-line: {view center-face layout [ banner "Test" button "OK" ] } win: layout/size [ style code text black silver bold code 360x100 multi-line ] 400x200 view center-face win
win: layout/size [ style code text black silver bold as-is code 360x-1 multi-line ] 400x200 view center-face win
Two things are needed : (1) the use of as-is in the style, (2) a pair with a negative height.
Note: this answer comes from Carl Sassenrath's easyvid.r.
Note (thanks to Allen Kamp): the negative height is not needed. The pair can be replaced by an integer representing the width.
win: layout/size [ style code text black silver bold as-is code 360 multi-line ] 400x200 view center-face win
Using 'find/last, 'copy/part and 'append
Changing from %program.r to %program.bak . It cannot be done with a simple find and replace. Find and replace will fail in some case like the following:
/d/rebol/prog.r/program.r -> /d/rebol/prog.bak/program.r
/d/rebol/prog.r/program.r -> /d/rebol/prog.bak/program.bak
1. The file extension is found with 'find/last
infile: %/d/rebol/prog.r/program.r ;== %/d/rebol/prog.r/program.r file-extension: find/last infile "." ;== %.r
With find/last, we explore a serie from the tail towards the head returning a serie.
2. The filename (without extension) is extract with 'copy/part.
temp: copy/part infile file-extension ;== %/d/rebol/prog.r/program
Copy/part copy the part of infile that is limited by file-extension.
;== %/d/rebol/prog.r/program.r ; ^ ^ ; | | to ; | from
3. The new extension is added with 'append
outfile: append temp ".bak" ;== %/d/rebol/prog.r/program.bak
4. The final reduced version
outfile: append copy/part infile find/last infile "." ".bak" ;== %/d/rebol/prog.r/program.bak
Filename: func [File [file!]][copy/part File find/last File "."] Extension: func [File [file!] Extension [file!]][join Filename File Extension] extension %program.r %.bak ;== %program.bak
file: %/c/d/e/f.ext-with clear change find/last file "." ".r" probe file file: %/c/d/e/f.ext-with change/part find/last file "." ".r" tail file probe file
Documentformater copyright Robert M. Münch. All Rights Reserved.
Formatted with Make-Doc-Pro Version:1.0.0 on 9-Feb-2002 at 19:15:21