World: r3wp
[Core] Discuss core issues
older newer | first last |
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 [3928x3] | also, since this gets often overlooked: |
>> get-modes system:// 'endian == little | |
the debase trick is the most portable, although it's slow; still better than load rejoin though. | |
Vincent 11-Apr-2006 [3931] | but not for /View 1.2.1 : no system:// port, and debase crashes sometimes. A little better than "load rejoin" : load join "#{" [to-hex value "}"] |
JeffM 11-Apr-2006 [3932] | Not sure the best forum to put this on (to where Carl will see it). Are there plans in the future for actual bit operations besides and/or/xor? RIght now, bit shifting, rotating, etc. are extremely painful (and slow compared to what they should be) to do. |
Gabriele 11-Apr-2006 [3933] | rebcode supports shifting; not sure if it makes sense to have a native too, maybe yes. |
JeffM 11-Apr-2006 [3934] | shifting is a very basic operation. I don't understand how it couldn't be part of the core, native functions. The same could be said of AND and OR, and just make them logical operators instead of bitwise. |
Gabriele 12-Apr-2006 [3935] | well, shifting is very lowlevel, and there are not many use cases outside of rebcode. |
JeffM 12-Apr-2006 [3936] | I disagree, but that's fine. I imagine the majority of those using REBOL are using it for non-low level things. I just don't happen to be one of them. REBOL is a great language for making domain specific languages, and many DSLs would benefit from a little more low-level control. |
Henrik 12-Apr-2006 [3937] | I have to disagree as well. I've bumped into a few examples where bit-operations would be very nice to have, if you want to use REBOL for prototyping bit-operations in another environment. Afterall we can create bitsets, why not allow full manipulation of them? |
Gregg 12-Apr-2006 [3938x3] | Well, you can write your own; if just prototyping, the speed isn't critical (we did 160 bit math for Maarten, using bitsets, at one point). That said, if you can use a version with rebcode, just wrap a mezzanine around the ops. That said, I wouldn't mind having standard SHIFT and ROTATE funcs that can operate on integer, or series values. Bit ops are also necessary for implementing certain algorithms. |
Here are prototype funcs for SHIFT and ROTATE (plus a couple supporting funcs). Is it worth some time to come up with good ones and submit them for inclusion in R3? | |
; used in SHIFT below dup: func [value len [integer!] /local type] [ type: either series? value [value] [either char? value [""] [[]]] head insert/only/dup make type len value len ] ; used in SHIFT below make-blank-value: func [type] [ any [ attempt [make type 0] attempt [make type ""] attempt [make type []] attempt [make type none] ] ] ; The new PAD/JUSTIFY func might be used to implement this as well. shift: func [ "Shift values in a series; length doesn't change." series [series!] /left "Shift left (the default)" /right "Shift right" /part range [number!] "Shift this many positions" ; TBD series! support? /with fill "Fill vacated slots with this value" /local pad ][ range: any [range 1] if any [empty? series 0 = range] [return series] pad: dup any [fill make-blank-value last series] range either right [ head insert head clear skip tail series negate range pad ][ append remove/part series range pad ] ] rotate: func [ "Rotate values in a series." series [series!] /left "Rotate left (the default)" /right "Rotate right" /part range [number!] "Rotate this many positions" ; TBD series! support? /local offset pad ][ range: any [all [range range // length? series] 1] if any [empty? series zero? range] [return series] either right [ offset: does [skip tail series negate range] pad: copy offset head insert head clear offset pad ][ pad: copy/part series range append remove/part series range pad ] ] | |
Anton 12-Apr-2006 [3941x3] | I am trying right now to write a file to an FTP server. What I would like to do is: - open the port - try to write the file - if that fails, create the parent directory if necessary - try to write the file again - close the port |
The difficult part is keeping the port open. | |
... and I have my head deep in FTP handler... :) | |
Anton 16-Apr-2006 [3944x2] | Ah... figured out how to do that :) The solution is to disable close-on-fail in the handler, so that a failure in open does not close the ports. This allows the command port to be reused for other commands, such as make-dir. |
Now to make it nice... | |
Graham 16-Apr-2006 [3946] | Anyone know how to write to the parallel port ? |
older newer | first last |