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

World: r3wp

[Core] Discuss core issues

Anton
2-Apr-2006
[3880]
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}
DideC
10-Apr-2006
[3917]
It's what "be a guru" means ;-)
Vincent
10-Apr-2006
[3918]
struct! is byte-order sensitive (different results on PC/Macs), but 
it's the fastest way.
BrianH
10-Apr-2006
[3919]
You can use reverse on the result if you need to.
Vincent
10-Apr-2006
[3920]
yes - but to have the same code running on both little and big endian 
platforms, it needs some work (when to apply 'reverse)
BrianH
10-Apr-2006
[3921]
That's easy, you just set a conversion function at the beggining 
of your app, picking a bigendian or littleendian one based on the 
platform, and then just use it like a black box. A bigger problem 
is that struct! is currently only available on /Pro, /View/Pro or 
/Command, which means that you can't run the code on Mac right now 
anyways. Making struct! available in /Core and /Base has been requested 
though.
Vincent
10-Apr-2006
[3922]
struct! is not limited to /Pro. It's available on /View since at 
least 1.2.1 (not license needed). Absence in /Core is a problem, 
as there isn't usable alternatives for float conversion.
BrianH
10-Apr-2006
[3923]
It has been aailable in versions of View that can be upgraded to 
View/Pro with a license, even when the Pro features are disabled 
by the lack of a license. However, the struct! type is implemented 
by the library extension, along with routine! and such. Can anyone 
confirm that struct! is available in versions of View that do not 
have the library extension at all, like View for Mac?
Henrik
10-Apr-2006
[3924]
it's in View for mac alright...
BrianH
10-Apr-2006
[3925x2]
Which version? it wasn't in View for Mac Classic...
Still, it's not in Core or Base yet. Probably will be in REBOL 3 
though.
Henrik
10-Apr-2006
[3927]
works in the OSX version but that one is also built on 1.3
Gabriele
11-Apr-2006
[3928x2]
also, since this gets often overlooked:
>> get-modes system:// 'endian
== little