• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[Rebol School] REBOL School

Maxim
4-Jul-2012
[628x3]
here is a simple way to get the code for a face within the layout 
function ( I found it the easiest to remember):

view layout [
	across
	text "1"
	my-radio: radio on 
	do [probe my-radio]
	text "2"
	radio
]


the advantage of this system is that you get the actual face with 
any facets setup as they really are in your gui.  this is often the 
easiest way to identify just where and how a specific facet affects 
a face... probe it without your change, and then run it again, with 
your change... comparing both probes in a diff or merge tool.
the other way is to use get-style.   the advantage here is that is 
preserves the init block, instead of clearing it after VID has done 
its work


a good look at the 'init block is often useful to understand why 
changing some of the face values is ineffective (like changing face/color 
is often useles... since that face is setup to use face/colors). 
 

this block is run after all the facets have been applied. 

note that you can set or append to this block in your own styles.
HTH  :-)
ChristianE
4-Jul-2012
[631x2]
get-radio-buttons: does [
    reduce [
        get-face option-1
        get-face option-2
        get-face option-3
    ]
]

reset-radio-buttons: does [
    clear-face option-1
    clear-face option-2
    clear-face option-3
]

view layout [

    option-1: radio-line "Option 1" of 'options [probe get-radio-buttons]

    option-2: radio-line "Option 2" of 'options [probe get-radio-buttons]

    option-3: radio-line "Option 3" of 'options [probe get-radio-buttons]

    btn "reset radios" [reset-radio-buttons]
]
Best to use the getter-/setter-methods wherever they are implemented.
Ladislav
4-Jul-2012
[633]
anyone know which one of these would be the correct one to use?
1. 
percentile: func[s p /local n][n: round/floor (p * (length? s) + 
0.5) return s/(n - 1)]
2. percentile: func[s p /local n][n: round/floor 
(p * (length? s) + 0.5) return s/(n)]

 - I cannot recommend any of them. (ROUND/FLOOR is not what is recommended 
 in Wikipedia, also the percentile calculated this way is not compatible 
 with the "standard median definition". I recommend to use interpolation 
 on Hazen ranks as mentioned in Wikipedia under "interpolation", or 
 on Mean ranks as recommended by NIST - also can be found in WP)
Arnold
4-Jul-2012
[634]
I have view.txt in my rebol/script folder a copy from system/view, 
it is 80000 lines mostly object definitions and images. quite different 
from the ancient one http://www.rebol.com/view/vid.rthat at least 
makes some sense to me ;-)
Arnold
5-Jul-2012
[635]
getter/setter is a nice theoretical concept, nice for OO purposes. 
Radio buttons of a group should function like this: always 1 selected, 
the default to begin with, each option should have a value that is 
copied to the radiogroup's /data field, so to know what was selected 
can be found just like that. Not more not less.
rg: radiogroup rg1
radio on 'rg1  "Text 1" "A" 
radio     'rg1 "Text 2" "B"
and in your program 
switch rg1/data [
A
 [do this]
B
 [do that]]
Henrik
5-Jul-2012
[636x2]
Arnold, take a look at the VID Extension Kit. It attempts to make 
VID more complete, although it's no longer directly compatible with 
VID.
One thing to note about VID: It was a demo toolkit that Carl wrote 
about 10 years ago in a couple of weeks. He expected someone to come 
up with something better.
Arnold
5-Jul-2012
[638x2]
It is hard to beat in its simplicity. But also hard to improve in 
its current state. More a modular way would have been nicer. So it 
would have been clear where to start if you want to improve (or first 
find out) the behaviour of radio buttons for example.
Same thing as he expected the community to come up with the new bindings 
of REBOL3 to about all other Open Source operating Systems (Rebolution!) 
whereas the REBOL kernel source stays closed source. Not much animo 
since. Au contraire. Could have been the final nail...
Chris
7-Jul-2012
[640x2]
Arnold, I came up with one solution to the radio question here:

http://stackoverflow.com/questions/6401469/how-do-i-get-the-radio-button-value-in-rebol
It may be overkill, but it iterates through all faces looking for 
the 'of relationship, returning the selected face.
Arnold
7-Jul-2012
[642]
Hi Chris! Thank you. I consulted this site also. But there is better 
news to this! In stead of the words on and of you have to use the 
words true and false and the problems are solved! Didn't even have 
to initialize the /data fields between creating the layout and calling 
it in action with view.

Not documented but stil possible. (Like it is also undocumented on 
the REBOL site that you can have a checkbox followed by an action 
block.And this is also possible on text-labels making them clickable 
and have an mouse-over effect.)
Arnold
11-Jul-2012
[643]
Today I experimented with calling a REBOL script from my php script. 
Thanks to previous contributions of a.o. Ralph Roberts of abooks.com 
from 1999(!) and an entry on the PHP site I found out how to do this 
on my apache driven site.

It was not quite as straightforward as Robert said like: include 
("rebolnow.r");
Nor was it as simple as: system("rebolnow.r 2>&1", $myout);
echo $myout;

But it worked when I called out for the REBOL program first. Both 
two of the next examples worked for me:
system("/path/to/cgi-bin/rebol -c %rebolnow.r 2>&1", $myout);
echo $myout;
AND secondly
echo system("/path/to/cgi-bin/rebol -c %rebolnow.r");
Work!

The REBOL script must be in the same dir as your PHP script (Not 
in your cgi-bin directory)(I didn't test sub dirs and other dirs 
but I suppose they work like usual)
The script does not need the #!/path/to/rebol line at the top.
The script should not print http-headers and

When printing stuff the last line should read print "" because the 
last printed line will be repeated.

Hope this helps more people to switch from php scripting to REBOL 
scripting for their websites.
Izkata
11-Jul-2012
[644]
If you want to just echo the REBOL output, I would suggest using 
PHP's passthru() instead - it was designed for that:  http://php.net/manual/en/function.passthru.php
Arnold
12-Jul-2012
[645x2]
This says it is for binary data like images. In the first lines of 
this post http://www.mail-archive.com/[list-:-rebol-:-com]/msg01452.html 
it is mentioned as bringing not the solution to this wish. I passed 
this by, I'll stil have a second look, things in php could have 'suffered' 
improvements..
Does anybody have any experience in controlling servo motors using 
REBOL through USB devices/ports?
Henrik
12-Jul-2012
[647]
isn't that sort of time-critical?
Arnold
12-Jul-2012
[648]
I'm not in a hurry?! :)
Kaj
12-Jul-2012
[649]
I think Henrik means that you can get bitten by REBOL hanging for 
short periods of time in the garbage collector
Arnold
12-Jul-2012
[650x2]
It is interacting with the real world, robotica, control engineering..
Then the garbage should be separatedly collected. The paper, the 
glass, the compostable material, heavy metal's and rest-garbage. 
:)
Henrik
12-Jul-2012
[652]
You can turn off garbage collecting and do it in the "coffee breaks", 
with this.

recycle/off
Arnold
12-Jul-2012
[653x4]
With the 'large' programs I have in mind there will never be lots 
of garbage to collect. I don't know much/anything about robitics 
and control engineering by the way, I am interested in this because 
I realized using REBOL to do things like this could have large potential. 
And I want to move a little car with a photocamera and taking photo's 
from centain positions. The car may also be guided by a rail of some 
sort.
centain=certain
Domotica could also be a nice DSL.
PHP: I tried the passthru function. It worked, but I do not see any 
benefit from the exec function. I prefer exec over passthru. Saves 
typing, not that I do any. I always cut and paste code offcourse.
Arnold
13-Jul-2012
[657]
I meant system. exec didn't work. I still prefer system above passthru. 
I have integrated my first REBOL module within my website. I needed 
to add a cookie section to obey the new cookie law anyway. I even 
used a REBOL script to generate all cookie pictures to the same size 
and png format.
Endo
23-Jul-2012
[658]
How can I get the error text when I use TRY, I want to show the original 
error text to the user: 
if error? set/any 'err try [1 / 0] [probe disarm err]


I think I saw something similar in UniServe sources but couldn't 
find it.
DocKimbel
23-Jul-2012
[659]
This function should help you:

form-error: func [err [object!]][
	foreach w [arg1 arg2 arg3][
		set w either unset? get/any in err w [none][
			get/any in err w
		]
	]
	reform [
		"***" system/error/(err/type)/type #":"
		reduce system/error/(err/type)/(err/id) newline
		"*** Where:" mold/flat get in err 'where newline
		"*** Near: " mold/flat get in err 'near newline
	]
]
Endo
23-Jul-2012
[660]
Great! Thanks a lot Doc.
Gabriele
24-Jul-2012
[661]
this is my version: http://www.rebol.it/power-mezz/mezz/form-error.html

note that it does not make arg1, arg2 and arg3 global.
Endo
24-Jul-2012
[662]
Thanks Gabriele.
Arnold
26-Jul-2012
[663x2]
I am busy with a little chess program. Just the board and the pieces 
to be moved on the board. (I have seen the examples on rebol.org). 
It is meant to be for a chess learning/training program and possibly 
demonstration/game review and maybe have a coupling with an open 
source chess engine like Stockfish.. I am going to write a little 
script to determine all possible legal moves.  

 I want some information for what is an appropriate way to represent 
 the board and moves in REBOL, for example the 8-bit white/black init-position 
 king queen rook bisschop kNight pawn and board could be a1-h8 or 
 an array of 64 elements or a block (of blocks)
Suggestions welcome please. Tia.
In the script display-chess-board.r on rebol.org there is this part
   ;;  counter is now an image -  note the 'key effect 
    ;;  user to make the black in the image transparent.
    ;;  ------------------------------------------------
    counter: box 30x30 effect [key 0.0.0 oval]
 

This does not work, when keyword merge is added the middle part is 
transparent when the tuple is replaced with an integer, but only 
the other way around or the oval is limiting the working of merge 
to the inside of the circle?
Maxim
26-Jul-2012
[665]
you must add merge to the begining of effects, when you want images 
to pass thru faces.
Arnold
26-Jul-2012
[666x3]
Yes I tried all variations [merge oval key 127] [merge key 0.0.0 
oval] etc. I got a hole in the middle at some points but never the 
other way around like the comment mentions :(
The chess program I want to make give the moves of a piece like on 
the shredder site http://www.shredderchess.com/daily-chess-puzzle.html
and it will have a minimal validation routine so my kids (and me 
too) can beat the machine.
(I got the images from this site now I mention it here)
Sunanda
30-Jul-2012
[669]
Anyone want to have a try at this little puzzle? I have a working 
solution, but I am sure there is way more REBOLish way.


I have two objects that each contain simple REBOL values (ie imagine 
they've just been created from some serialised data, so no recursive 
blocks or anything tricky):
    obj1: make object! [aaa: 1 bbb: "xx"]
    obj2: make object! [bbb: "XX" aaa: 1]


All I want to do is confirm that they contain identical words and 
values under normal REBOL comparison rules -- so obj1 and obj2 should 
be treated as identical, while the next few are not identical to 
obj1 or obj2:
    obj3: make object! [bbb: "xx"]    ;; no 'aaa word
    obj4: make object! [bbb: "XX" aaa: 1 ccc: 3]  ;; extra word

    obj5: make object! [bbb: "XX" aaa: -1]  ;; different 'aaa word value


I am sure there is a simple one-line 'parse solution .... Isn't there 
always!? Thanks!
Maxim
30-Jul-2012
[670x2]
if you really want a one-liner  ;-)



all [  obj2: make obj1 obj2     (words-of   obj1) =  (words-of   
obj2)    (values-of  obj1) = ( values-of  (make obj1 obj2))  ]
the only way the above can fail is if a word in obj1 is set to none 
and that word is missing in obj2
Arnold
30-Jul-2012
[672x2]
Two little questions. I have a block like [ 0 0 0 0 ]. When first 
'declared' should I use a: [ 0 0 0 0 ] or a: copy [ 0 0 0 0 ]? (I 
know I should use copy when c: copy a). Second question when to use 
b: make block [ 0 0 0 0 ] in stead of just b: [ 0 0 0 0 ]??
(that should be: make block!
)
Kaj
30-Jul-2012
[674x3]
Depends on how you intend to use it. If you declare a series without 
COPY or MAKE, it references the data in what you usually think of 
as your source code
This is one of the standard REBOL pitfalls. You can think of such 
data as a constant. If you change it anyway, you're changing the 
representation of your program code
So if you're not going to use the data as constant, use COPY or MAKE. 
For a block with scalar values in it, it doesn't make much difference
Arnold
30-Jul-2012
[677]
I make in init block b: [ 0 0 0 0 ] and use the c: copy b and d: 
copy b as variable block.