World: r3wp
[Core] Discuss core issues
older newer | first last |
Oldes 22-Feb-2007 [7296] | And there should not be any references into string values in my block (I hope:) |
Anton 22-Feb-2007 [7297] | Is your some-block local to your recursion function ? |
Oldes 23-Feb-2007 [7298] | No. If it would be local, I would not need to clear it and store myself, wouldn't I? |
Henrik 23-Feb-2007 [7299x2] | Does anyone miss a function that tells with true/false if a variable can be converted to a different datatype? I find myself doing lots of test on input from text fields with attempt blocks. something like: to-integer? 'test == false |
>> a: "6" >> to-integer a == 6 >> a: "u" >> to-integer a ; script fails here so we need to handle it ** Script Error: Invalid argument: u ** Where: to-integer ** Near: to integer! :value >> attempt [to-integer a] ; useful, but less clear what fails. Is 'a not a value or can it not be converted to integer? == none >> to-integer? a ; 'a definitely exists, but can't be converted to integer. == false | |
Oldes 23-Feb-2007 [7301x2] | >> to-integer?: func[a][ not error? try [to-integer a]] >> to-integer? "1" == true >> to-integer? "a" == false |
to-integer?: func[a][ not error? try [to integer! a]] | |
Henrik 23-Feb-2007 [7303] | yes, something like that, thanks |
Oldes 23-Feb-2007 [7304x2] | And I must say it again... I use ATTEMPT only in cases where I do not expect error. Many people use it just a shortcut for error? try which I don't lik. As I understand attempt as higher function for reporting not wanted errors (for example on server). If you use it in cases, where like attempt [to-integer "a"] it's not good as it would report many errors (in some bigger context) |
And Henrik, I don't think Carl will add it into Rebol as it's too easy to implement yourself. | |
Henrik 23-Feb-2007 [7306] | Oldes, probably not, though this is just one case. A more complex datatype like date! requires more complex checking schemes. |
Oldes 23-Feb-2007 [7307] | And I would not use it, as I usually use something like this: if error? try [a: to integer! a][a: 0] |
Henrik 23-Feb-2007 [7308x2] | And date! does not behave like integer!: >> a: 1 == 1 >> b: "2" == "2" >> c: "u" == "u" >> to-date reduce [a b c] ** Script Error: Invalid argument: 2 ** Where: to-date ** Near: to date! :value |
This is probably a dumb case since endusers don't determine the types themselves. | |
Oldes 23-Feb-2007 [7310] | and if I would use it, I would probably use it like: to-date?: func[a][ not error? try [a: to date! a]] |
CharlesS 23-Feb-2007 [7311] | can the to function translate to user defined structures / objects ? if so how, is there a special method name in the object you want to convert to ? |
Sunanda 23-Feb-2007 [7312] | If I understand your question, Charles, you may be looking for construct/with......It's a way of using an existing object as a template for a new one, eg: my-obj1: make object! [a: 99 b: 2 c: "string"] my-obj2: construct/with [b: 9999] my-obj |
Henrik 24-Feb-2007 [7313] | hmm... is it possible to find () elements in a block? they don't have a specific datatype. find [a b c (code) d] ?? ; what type? |
Sunanda 24-Feb-2007 [7314] | Is this a start? find [a b c (code) d] paren! |
Henrik 24-Feb-2007 [7315x2] | ah, precisely, thanks. didn't know there was a type for them |
because: type? () == unset! | |
Sunanda 24-Feb-2007 [7317] | And, perhaps worse: type? (1) == integer! which is not what you might expect..... You have to do this to get type? to work: type? first [(1)] == paren! |
JaimeVargas 24-Feb-2007 [7318x2] | The parens! triger evaluation so type? (1) = type? 1 ;== integer! |
But parens inside blocks are not evaluated. | |
Robert 25-Feb-2007 [7320x2] | Is there a way to find out if a loaded file is encrypted with CLOAK? |
Or do I have to read it and try to DECLOAK it? | |
Sunanda 25-Feb-2007 [7322] | As far as I know, an encloaked string is just a jumbled up, binary version of the original string: it carries no prefix signature so you can't tell at a glance it is an encloaked string rather than another bit of binary. So, yes, as far as I knoww, you'll have to read and attempt decloaking. Or, if you have control over the writing, ensure some sort of identifiable prefix is added) |
Henrik 25-Feb-2007 [7323] | >> do to-path reduce ['now 'none] ** Script Error: now/none has no refinement called none ** Near: do to-path reduce ['now 'none] >> do to-path reduce ['now none] == 25-Feb-2007/20:40:18+1:00 >> do probe to-path reduce ['now none] now/none == 25-Feb-2007/20:40:28+1:00 >> now/none ** Script Error: now has no refinement called none ** Near: now/none I guess the difference is between 'none and none!, but I thought it was curious that the none! is accepted as a refinement. |
Anton 25-Feb-2007 [7324x2] | >> now/#[none!] == 26-Feb-2007/14:28:03+11:00 |
Actually it looks like you can put any issue! >> now/#hello == 26-Feb-2007/14:28:43+11:00 | |
Gabriele 26-Feb-2007 [7326] | functions just ignore anything that is not a word in the path. |
Robert 26-Feb-2007 [7327] | DECLOAK: I have the problem that a random char is added as the first char to a decloaked string. Is this a known problem? |
Anton 26-Feb-2007 [7328x3] | Not to me it isn't. What version of rebol ? |
It's not in Rambo. | |
encloak / decloak seem pretty stable to me. Be aware that these functions modify the string you pass it. | |
Robert 26-Feb-2007 [7331] | I only have the problem when not using read/binary but just have used WRITE and READ... strange. |
Oldes 26-Feb-2007 [7332] | Just don't use just WRITE with encloked data as these data are binary data. |
Gregg 26-Feb-2007 [7333] | I've never had a problem with encloak/decloak, but I would also avoid string ops that might translate the binary data somehow. |
Anton 27-Feb-2007 [7334] | Yes, READ and WRITE are in text mode and translate line terminators, so LF can become CRLF and vice versa. |
Oldes 27-Feb-2007 [7335] | Is there any better way how to convert issue! to binary! than this silly one? issue-to-binary: func[clr ][load head insert tail insert next mold clr "{" "}"] |
Maxim 27-Feb-2007 [7336] | and what do you want... the string or the value? |
Oldes 27-Feb-2007 [7337] | I want binary value |
Maxim 27-Feb-2007 [7338x2] | so four byte issue gives 32 bite value... |
or is initial issue a decimal type integer? | |
Oldes 27-Feb-2007 [7340x3] | >> issue-to-binary #ff0000 == #{FF0000} |
at this moment as-binary is working like: >> as-binary #ff0000 == #{666630303030} | |
which i really don't like | |
Maxim 27-Feb-2007 [7343x3] | I know... both are valid . |
same for tuples, etc. | |
for going to-from hex... I don't have a solution. | |
older newer | first last |