World: r3wp
[Core] Discuss core issues
older newer | first last |
Graham 27-Dec-2007 [8959x3] | passes the first tests :) |
I'll plug her in and see if it works ... | |
I think it's working :) Thanks Gregg. | |
Anton 27-Dec-2007 [8962] | (don't forget to declare locals res-x and res-y) |
Gregg 28-Dec-2007 [8963] | Glad to hear it Graham. Thanks for catching that Anton; quick hack you know. :-\ |
Henrik 30-Dec-2007 [8964x2] | I was wondering why this happens: >> a: does [try [2 / 0]] >> a ** Math Error: Attempt to divide by zero ** Where: a ** Near: 2 / 0 >> try a ** Math Error: Attempt to divide by zero ** Where: a ** Near: 2 / 0 >> error? a ** Math Error: Attempt to divide by zero ** Where: a ** Near: 2 / 0 Whereas when ERROR? is put inside the function, it catches the error properly. >> a: does [error? try [2 / 0]] >> a == true Is returning a value or an error considered an extra step that causes ERROR? not to catch the error in time? |
sorry, couple of malformed lines in the above example. I hope you can read it. | |
Oldes 30-Dec-2007 [8966] | 'try returns "armed" error. That's why there is 'disarm function |
Henrik 30-Dec-2007 [8967x2] | >> a: does [try [2 / 0]] >> disarm a ** Math Error: Attempt to divide by zero ** Where: a ** Near: 2 / 0 |
I'm just wondering what is happening at the moment of value return. There must be an extra step. | |
Anton 30-Dec-2007 [8969] | The armed error! value is very "hot". error? is the only function able to trap this error! value. |
Henrik 7-Jan-2008 [8970] | is it possible to embed/serialize binding information? I have a fairly complex object where functions in it are supposed to be bound to their parent context, but when loading, they are bound to 'system (or nothing). to solve this, I manually rebind every function, which seems rather clumsy. is there a more direct way? |
Chris 7-Jan-2008 [8971] | ; I'm not sure you can bind whole objects, but you can at least make short work of the manual process. Here's a quickie I've used: reconstitute: func [object [object!] /local bindings][ append bindings: [] object foreach word next first object [ switch type?/word word: get in object word [ function! [foreach context bindings [bind second :word :context]] block! [foreach context bindings [bind :word :context]] object! [reconstitute :word] ] ] remove back tail bindings object ] |
Henrik 7-Jan-2008 [8972] | is there an in-memory version of save/header "" header-obj ? |
Chris 7-Jan-2008 [8973x2] | save/header data: #{} "" [Title: "Data"] |
probe to-string data | |
Henrik 7-Jan-2008 [8975x2] | thanks |
(still reviewing your previous answer, so I'm not just thanking you for that ;-)) | |
Chris 7-Jan-2008 [8977] | On the previous answer, you could probably modify it to incorporate objects nested in blocks. Also, it does not reconstitute some of the subtle uses of nested objects, such as the reusable 'feel objects in faces. Sadly. |
Henrik 7-Jan-2008 [8978] | yes, that's why I wanted to make binding cues inside the object, so I can load it, and it will automatically bind to wherever is needed. |
Chris 7-Jan-2008 [8979] | Yep, if you were to do -- context: [a: b: :an-object] -- while you could bind a reconstituted 'a and 'b to 'an-object, it would be clones. Possibility: where you are working with faces, you could specifically change eg. the feel to lit-word/path before saving, then allow a 'reconstitute-like function replace that value with the related object. It's a little messy, but still such functions could still be nearly as short... |
Henrik 7-Jan-2008 [8980x2] | I think I'll keep my method for now. It's actually simpler for me to understand than the above. :-/ |
thanks for your work. | |
Henrik 8-Jan-2008 [8982x2] | anyone know of a function to calculate the relative path between two branches in a file system? |
I think I'm figuring it out. will post the function when I'm done. | |
amacleod 11-Jan-2008 [8984] | I want to sync some files on a server. what is the usual method? This file will be a rebol script so I thought placing a "version:" in the rebol header would be logical. I tried to "load/header" but I get the whole script and its no evaluated so I can not just get the version value. |
Anton 11-Jan-2008 [8985] | Yes, you must write your own version parsing function which loads only a part of the file. |
btiffin 12-Jan-2008 [8986] | Alan; You can try var: load/header/next first var will be the header as object, second var will be the rest of the script as a string. var/1/version should be your tuple! (assuming you use tuple). In terms of the evaluation it is deemed "light", values but not code. So version: 3.2.1 ok, version: to tuple! [3 2 1] won't be a tuple, var/1/version will be 'to So Anton is correct. Another thing to check out the mezzanines (from View) load-thru read-thru and the source for exists-thru? These may have some hints for what you want. |
Robert 12-Jan-2008 [8987] | Is there an opposite function to SUFFIX? like PREFIX? or so to get the filename without extension? |
Will 12-Jan-2008 [8988x2] | head clear find/last copy a #"." |
to file! head clear find/last copy %prefix.suffix #"." | |
Ashley 12-Jan-2008 [8990x2] | copy/part f -1 + index? find f "." |
to file! first parse f "." | |
ChristianE 13-Jan-2008 [8992] | If it wasn't for that extra TO-FILE in SUFFIX?, you'd just use COPY/PART: >> suffix?: func [path [any-string!] "Return the suffix (ext) of a filename or url, else NONE."] [if all [path: find/last path %. not find path #"/"] [path]] >> file: %my.test.file.txt == %my.test.file.txt >> copy/part file suffix? file == %my.test.file |
Anton 13-Jan-2008 [8993] | AMacleod, I found my version? function in http://anton.wildit.net.au/rebol/library/dir-utils.r (after remembering where my website is) |
[unknown: 5] 13-Jan-2008 [8994] | I'm just curious if there is a way to make a function think an argument was passed to it even though an argument wasn't passed to it. |
Henrik 13-Jan-2008 [8995] | a: func [b [word! unset!]] [] |
[unknown: 5] 13-Jan-2008 [8996] | but could B be used if needed |
Henrik 13-Jan-2008 [8997x2] | inside the function? |
I haven't tested, but perhaps you can test for 'value? | |
[unknown: 5] 13-Jan-2008 [8999x3] | yes |
that might work Henrick, I'm trying a few things now. | |
Yep that will work. Thanks Henrik | |
Henrik 13-Jan-2008 [9002] | no problem |
amacleod 13-Jan-2008 [9003] | Thanks, Anton. I think it is just what I'm looking for. |
Anton 13-Jan-2008 [9004] | no worries. |
Oldes 14-Jan-2008 [9005x2] | Is there any script which can convert for example -1.8E-5 to -0.000018 ? |
formDecimal: func[ number [decimal!] digits [integer!] /local negative? p result ][ if digits <= 0 [return form to-integer 0.5 + number] if negative?: number < 0 [number: - number] p: power 10 digits result: form to-integer number * p + 0.5 if number < 1 [ insert/dup result "0" (1 + digits - length? result) ] if negative? [ insert result "-" ] head insert skip tail result negate digits #"." ] | |
Graham 14-Jan-2008 [9007] | should have a native that does this |
Gregg 15-Jan-2008 [9008] | There was an old one from Eric Long, that might be in REBOL.org. I don't think I ever tackled that with my FORMAT function. |
older newer | first last |