r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Allen
28-Mar-2006
[3867]
Rebolinth: Need you to show an example with the expected results. 
Also are A and B of fixed length or varied?
Gregg
29-Mar-2006
[3868]
Use FIND + INDEX? maybe?
[unknown: 10]
29-Mar-2006
[3869x2]
yes well find and index where not what i searched for...ill drop 
an example...hold on a few hours ;-) back ltr...
...an example...


I build in lisp a latin-square example and rebuil it in rebol.. the 
bottle neck is not the random generator

but its for me the function called 'clean? (can this function be 
exchanged with a rebol buildin funtion? or
even be made smaler?)


; a latin square in rebol

random/seed now

clean?: func [ x /local bb i ][ 

 catch [ foreach bb b [for i 1 9 1 [ if = pick bb i pick x i [throw 
 false] true ]]]]

print "---- running ----"

T1: now/time/precise
insert/only b: copy [] random/seed [ 1 2 3 4 5 6 7 8 9 ]
print first b

while [ < length? b 9 ][  

 if clean? set 'x random [ 1 2 3 4 5 6 7 8 9 ] [ print x insert/only 
 b x ]]

print rejoin [ "Timed: " now/time/precise - T1 ]

wait 0:0:5
quit
Allen
29-Mar-2006
[3871]
As a general rule, try to use native! looping functions, they are 
faster. In the above the native! "repeat" could replace the use of 
"for"
[unknown: 10]
30-Mar-2006
[3872]
talking about speed improvement!! that 'for loop is very slow compaired 
to the 'repeat ;-) thanks..
DideC
30-Mar-2006
[3873]
; Try :
	source for
	source repeat
; and see !!!
Oldes
1-Apr-2006
[3874x2]
Is there someone using a Rebol script to send IF_MODIFIED_SINCE in 
HTTP get header?
ech, I forgot I can use read/custom to set the header easily:-)

read/custom page [header [If-Modified-Since: "Sat, 1 Apr 2006 14:42:13 
GMT"]]
Anton
1-Apr-2006
[3876]
:)
Thør
1-Apr-2006
[3877]
.
Thør
2-Apr-2006
[3878]
,
Anton
2-Apr-2006
[3879x2]
Greetings Thør.
Ok I have a question.


I would like to catch an error inside a function and throw it out 
so the error position is reported "near"

the function itself. As far as I understand we should do that with 
something like this:

check: func [

 [catch]  ; <-- function spec attribute flag which changes the reported 
 position of the error.
][
	load "http://("  ; <-- cause an error on purpose
]

Now I have tried various things:

>> check: func [][load "http://("]
>> check
** Syntax Error: Missing ) at end-of-script
** Near: (line 1) http://(

>> check: func [[catch]][load "http://("]
>> check
** Syntax Error: Missing ) at end-of-script
** Near: (line 1) http://(

>> check: func [[catch]][throw-on-error [load "http://("]]
>> check
** Syntax Error: Missing ) at end-of-script
** Near: 



But none of these seems to be reporting the "Near:" position that 
I'm expecting.

(Indeed, the last one looks kind of buggy reporting to me. Anyone?)
Volker
2-Apr-2006
[3881x5]
>> check: func [][throw-on-error[load "http://("]]
>> check
** Throw Error: ** Syntax Error: Missing ) at end-of-script
** Near: (line 1) http://(
>
You need to throw the error for [catch] to see it
Hmm, that looks like one of your tries.
; usually works like this

>> check: func [[catch]][throw-on-error[1 / 0]] check2: does[check] 
check2 ** Math Error: Attempt to divide by zero
** Where: throw-on-error
** Near: check
>> check: func [[catch]][1 / 0] check2: does[check] check2
** Math Error: Attempt to divide by zero
** Where: check
** Near: 1 / 0
;but load seems really to confuse  the near:

>> check: func [[catch]][throw-on-error[load "("]] check2: does[check] 
check2 ** Syntax Error: Missing ) at end-of-script
** Near:
Anton
2-Apr-2006
[3886x2]
Yes, that's just what I was thinking.. It seems most likely that 
LOAD confused the interpreter about the "Near:" position.
So it looks like a bug to you too ? I would like to check with Ladislav, 
Romano or Gabriele.
Ladislav
3-Apr-2006
[3888]
I suggest you to put it to RAMBO
Anton
3-Apr-2006
[3889]
Ok, submitted.
Thør
4-Apr-2006
[3890]
manual resync
Jerry
5-Apr-2006
[3891]
Outer: context [
	name: "Outer"
	Inner: context [
		name: "Innter"
		get-outer-name: does [
			; I would like to return the outer name.
			; How would I do that? Thank you.
		]
	] 
]

; Making the get-outer-name function return Outer/name is not
; a good idea, since Outer can be cloned and its name can be
; changed, as follows 

Outer2: make Outer [ name: "Outer2"]
Outer2/Inner/get-outer-name

; Any help will be appreciated.
Sunanda
5-Apr-2006
[3892]
As you say, the context doesn't have a name.

it could be anonymous, or multiple words could be assigned to it, 
so there is no one "name"
outer2:  :outer
outer3: :outer2
Anton
5-Apr-2006
[3893x3]
You have to maintain a parent attribute.
>> outer: context [inner: context compose [parent: (self)]]
>> probe outer/inner/parent
make object! [
    inner: make object! [
        parent: make object! [...]
    ]
]
It works by composing the block before making it into an object. 
So self at that moment evaluates to the outer object.
When cloning the outer object, you will have to make sure to also 
clone the inner object (ie. you must implement deep recursive clone 
yourself), making sure to maintain parent correctly.
Jerry
5-Apr-2006
[3896]
Thanks. Anton and Sunanda.
JeffM
8-Apr-2006
[3897x2]
Is there any way to get the RGB data from a loaded image?
I assume there is a simple refinement to do so (like /size to get 
the size of the image), but I can't seem to find it.
Gabriele
8-Apr-2006
[3899]
>> logo.gif
== make image! [100x24 #{
252525141414141414141414141414141414141414141414141414141414
14141414141414141414141414141414141414141414...
>> logo.gif/rgb
== #{
2525251414141414141414141414141414141414141414141414141414141414
141414141414141414141414141414141414141414141414141414141414...
>> logo.gif/alpha
== #{
0000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000...
JeffM
8-Apr-2006
[3900]
thanks! exactly what i needed :-)
james_nak
8-Apr-2006
[3901]
I was curious what the "/only "  refers to. I know what it does but 
does anyone have an idea of the reasoning behind the wording? It's 
been one of those things that has bugged me. :- )
JeffM
8-Apr-2006
[3902]
i always assumed it meant "only the top level" (as in not recursive)
[unknown: 9]
9-Apr-2006
[3903]
KEY123 (ignore this please)
JeffM
10-Apr-2006
[3904x3]
Can REBOL/SDK define functions that will be called from C and passed 
to a C function? For example:
c-logger: make routine! [ "Define the callback function for error 
tracking."

    logger: [string!] "using string! since a function ptr is just a pointer"
    return: [integer!]
] my-lib "C_Logger"

rebol-logger: func [s] [ print s ]

c-logger :rebol-logger
also, sorry, i probably shoudl have posted this into the SDK group 
-- still getting used to AltMe
Jerry
10-Apr-2006
[3907]
How can I convert an integer! value to 2-byte hex binary! value? 
Say, 

>> do-something 15
== #{000F}

Thanks.
Graham
10-Apr-2006
[3908]
>> to-hex 15
== #0000000F
Pekr
10-Apr-2006
[3909]
to-binary [15]
Sunanda
10-Apr-2006
[3910]
Though that method, Petr, is awkward for values above 255:
to-binary [1234]
== #{D2}      ;; not the obvious result!
to-binary [12 34]   ;; need to separate out the bytes

== #{0C22}      ;; each octet is converted separately, so may still 
not be what was expected.
Pekr
10-Apr-2006
[3911x2]
i know - that method was suggested to me by Oldes IIRC. Because in 
other way, that is one of rebol's aspects I don't like and I regard 
it being inconsitent - to-binary 15 - It is a NUMBER, not two chars 
1 and 5, so I don't understand, why it tranlates each char .... it 
should change for 3.0
so the way to go is to use to-hex, but when you need a binary e.g. 
for struct!, you have to compose it, at least I did it that way in 
the past iirc :-) But maybe I am missing something obvious. But if 
not, those things should be looked into fro 3.0 .... as so far I 
like Carl's aproach = willingness for change, if the change makes 
sense of course and improves consistency ....
Jerry
10-Apr-2006
[3913]
I got it. The LOAD function is the magic.
 
>> load rejoin [ "#{" to-string to-hex 15 "}" ]
== #{0000000F}


I start to think that LOAD is not only for loading something, but 
also for converting a string to something.
Anton
10-Apr-2006
[3914]
Two bytes:

>> to-binary reduce [(i and 65280 / 256) (i and 255)]
== #{01B0}
Gabriele
10-Apr-2006
[3915x2]
>> debase/base to-hex 15 16
== #{0000000F}
>> s: make struct! [val [integer!]] [0]
>> s/val: 15
== 15
>> third s
== #{0F000000}