World: r3wp
[Core] Discuss core issues
older newer | first last |
Henrik 7-Jan-2008 [8981] | 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. |
Gabriele 16-Jan-2008 [9009] | i have one i've used for a long time too... also adds ' every three digits... i added support for scientific notation recently (because form always gives sci notation on Wine) |
Henrik 24-Jan-2008 [9010] | how is it again that I can rebind a function to a different context? |
Anton 25-Jan-2008 [9011] | >> c1: context [var: "orig" f: func [][print var]] >> c1/f orig >> c2: context [var: "hello"] >> bind second get in c1 'f c2 == [print var] >> c1/f hello |
Henrik 25-Jan-2008 [9012x4] | it seems not to work, if the function starts out as global |
>> a: does [print b] >> c: make object! [b: 4] >> a ** Script Error: b has no value ** Where: a ** Near: print b >> bind second :a 'c == [print b] >> a ** Script Error: b has no value ** Where: a ** Near: print b | |
solved with: bind second :a c | |
thanks, Anton | |
[unknown: 5] 25-Jan-2008 [9016] | Can someone explain the reason why bind would work but bind/copy wouldn't? |
BrianH 25-Jan-2008 [9017x2] | You don't rebind the function, you rebind its code block - not quite the same thing. Bind/copy wouldn't work because it creates a copy rather than rebinding the original block. You can alter the contents of the code block of a (R2) function, but you can't change the function's reference to that block to point to another block. |
If you can create a new function, you can use bind/copy. It is occasionally possible to arrange your algorithm so that it is possible to replace a function without worrying about aliased references, but usually not. | |
[unknown: 5] 25-Jan-2008 [9019] | yeah I understand that but why would bind/copy ever fail where bind itself worked? |
Anton 25-Jan-2008 [9020] | bind/copy goes deep. |
[unknown: 5] 25-Jan-2008 [9021x2] | yeah |
shouldn't it still work regardless | |
Anton 25-Jan-2008 [9023] | I think I remember, bind/copy is just a short equivalent to bind copy/deep. |
[unknown: 5] 25-Jan-2008 [9024] | but if bind works and then you try the same code with bind/copy should it cause an error? |
Anton 25-Jan-2008 [9025] | Just used when you don't want to modify the bindings of the original. |
[unknown: 5] 25-Jan-2008 [9026] | yeah that is the way I understand it also which is why it suprised me in my code that bind works but when I simply add bind/copy in then it breaks the code. |
Anton 25-Jan-2008 [9027x2] | Well, probably no error straight after binding, but if some other code rebinds it perhaps causes error later. |
It depends on the situation. What is the situation you are in ? | |
[unknown: 5] 25-Jan-2008 [9029] | yeah that might be it |
btiffin 30-Jan-2008 [9030] | What is the deal with mod and modulo? What should mod 10 3 mod 10 -3 mod -10 3 mod -10 -3 return? Not what REBOL returns ... what's the math of it supposed to be. I accept 1 and 2, but -4 (mod -10 -3) freaks me out. I don't use mod very often (and never with negative divisors or dividends), but it came up in a conversation with some student programmers (and I'm trying to convince them to give REBOL a try). |
older newer | first last |