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

World: r4wp

[Rebol School] REBOL School

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.
Sunanda
30-Jul-2012
[678]
Maxim....Thanks!


I rarely think of using R2-forward to get all those R3 goodies like 
value-of. Makes life much simpler :)


Your only way to fail can be fixed by checking the 'difference of 
the words-of before the main 'all.


Perhaps worth noting for anyone thinking of using the code as written: 
obj2 gets changed in the process.

Thanks again!
Endo
30-Jul-2012
[679x2]
Sunanda: I wrote this function a few months ago for the same task: 
It may not a very good solution but its ok (I think)

similar?: func [
    {Returns true if both object has same words in same types.}
    o [object!] p [object!] /local test
][

    test: [if not equal? type? get in o word type? get in p word [return 
    false]]
    foreach word sort first o test
    foreach word sort first p test
    true
]
It compares words and types, not values.
>> o: context [a: 1 b: "x"]
>> p: context [b: "x" a: 1]
>> s: context [b: "o" a: 1]
>> similar? o p
== true
>> similar? o c
== true
Steeve
30-Jul-2012
[681]
Sunanda,
>> empty? difference third obj1 third obj2
Maxim
30-Jul-2012
[682]
sunanda, actually, I just realized that if I switched the order in 
the all, I can fix the issue :-)

and you are right, I should generate a temp object...  but if you 
put the above in a function it would be like so:

equivalent?: func [ o1  o2 ][

 all [   (words-of   o1) =  (words-of   o2)    o2: make o1 o2     
 (values-of  o1) = ( values-of  (make o1 o2))  ] 	
]
Steeve
30-Jul-2012
[683]
Oups
>> empty? difference/skip third obj1 third obj2 2
Sunanda
30-Jul-2012
[684]
Endo -- thanks....That's a  useful starting point for a function 
that is capable of listing what the differences are.


Steeve -- 'difference on third was my first design ....But it fails 
on (say)
   obj1: make object! [a: 1 b: 2]
   obj2: make object! [a: 2 b: 1]

Maxim .... Nice!
Steeve
30-Jul-2012
[685]
difference/skip doesn't work (I forgot)
Maxim
30-Jul-2012
[686]
note that my function what specifically designed to detect mis-aligned 
words... so this is by design:

>> equivalent? context [a: 1 b: 2] context [b: 2 a: 1 ]
== none
Steeve
30-Jul-2012
[687]
with sort
>> (sort/skip third obj1 2) = sort/skip third obj2 2
Sunanda
30-Jul-2012
[688]
That looks good. Steeve -- thanks!
Arnold
30-Jul-2012
[689]
Hi looking for a better REBOL way to do the next thing: a: [ 1 2 
3 4 5 6 ] I have 1 of the values in this series and  want to do a 
foreach/forall on the series left of this value from right to left 
and also a foreach on the series on the right of this value but now 
from left to right. So say I chose 3 for the value then I need [ 
2 1 ] and [ 4 5 6 7 ]. This is my solution b: reverse copy/part a 
find a 3 and c: reverse copy/part a find reverse a 3 but now >> a
== [6 5 4 3 2 1]

And I don't want that and I don't like undoing the reverse each time. 
Do I need a temp for reverse a because c: reverse copy/part a find/last 
reverse copy a 3
** Script Error: Invalid /part count: 3 2 1
?
Sunanda
30-Jul-2012
[690]
You could use FOR to count yourself down:
     blk: [1 2 3 4 5 6]
     val: 3
     for nn val - 1 1 -1 [print blk/:nn]
       2
       1
Arnold
30-Jul-2012
[691]
Thanks Sunanda for this option. One extra tricky thing is the length 
of the series varies and I feel I am doing to much bookkeeping myself 
already.
Maxim
30-Jul-2012
[692]
yes, Arnold, be very careful with reverse... if you are part/way 
it will only reverse part of the series.
MaxV
31-Jul-2012
[693x2]
a: [ 1 2 3 4 5 6]
b: copy  find/tail a 3 ; you get [4 5 6]
c: reverse copy/part a ((index? find a 3 ) - 1)
and so you get [2 1]
Arnold
31-Jul-2012
[695x3]
See, there are other ways. Thanks fo the input all!!
And now for something completely different. I have a php based form 
I want to make into a REBOL cgi program. It is to upload some fields 
into an article-base in my mysql database. Where action is article.php 
in the php version I changed this to article.r for the REBOL version. 
I have now the article form shown and when I fill in some fields 
(but not all) and send the form I get the cgi object ( I use safe-cgi-data-read) 
but the contents of the formfields is now empty? Any clues what may 
be the case please?
It is POST data.
SWhite
31-Jul-2012
[698x2]
I believe that if you do not fill in a field on the form, you do 
not get an item in the cgi objectl.  I seem to recall being confused 
by that for a while.
I might have been wrong on the above comment, or it might apply only 
to checkboxes (that is, if not checked then not present in the object).
Maxim
31-Jul-2012
[700x2]
web forms do not send data fields when they are empty or "off", this 
is true for all types IIRC.
arnold seems to say that the fields which have data are not sent.