World: r3wp
[Core] Discuss core issues
older newer | first last |
Graham 25-Jan-2010 [15667] | form-decimal: func [ num [number!] cifre [integer!] /local sign str poscifre int frac pow ][ sign: either negative? num [#"-"] [""] str: make string! 16 either zero? num [ insert str #"0" if cifre > 0 [ insert/dup insert tail str #"," #"0" cifre ] ] [ num: abs num num: form add multiply power 10 cifre to-decimal num 0,5 ; mainly WINE bug workaround - might also work for larger numbers on Windows if find num "E" [ parse num [copy int to "." skip copy frac 15 to "E" skip copy pow to end] pow: to integer! pow either pow >= 0 [ insert/dup insert/part insert clear num int frac skip frac pow #"0" pow - length? frac ] [ num: "0"] ] clear any [find num "." ""] poscifre: skip tail num negate cifre insert/part insert str sign num num: skip num 1 + remainder subtract index? poscifre 2 3 while [(index? poscifre) > (index? num)] [ insert/part insert tail str #"'" num num: skip num 3 ] if empty? str [insert str #"0"] if not tail? poscifre [ insert insert/dup insert tail str #"," #"0" cifre - length? poscifre poscifre ] ] str ] |
Pekr 25-Jan-2010 [15668] | quite long :-) |
Janko 25-Jan-2010 [15669] | is form-decimal for scientific format for really large/small numbers like 1.25e+100 ? or is it for stuff like money 12.300,00 ? I have a function for the money :) (formating) , it's quite short if I remember correct. |
Graham 25-Jan-2010 [15670] | That's a good point, if you only need a couple of decimal places, the form decimal could be much shorter |
Gregg 25-Jan-2010 [15671] | SPEED? == 2'450 here. I very much like the idea of combining heuristics with profiling. But if we're just going for rough estimates, we only need to know if a machine is extraordinarily fast or slow. Then we say "is 20K calls/sec acceptable in terms or order of magnitude?" |
amacleod 25-Jan-2010 [15672x3] | form-decimal 4.17E-3 == "0.0017" form-decimal 4.17E+3 == 4170.0 positive version seems to work. |
using Henriks function | |
first convertion does not work... | |
Pekr 26-Jan-2010 [15675] | negative version is correct too, no? Mine form-decimal returns the same ... |
amacleod 26-Jan-2010 [15676x2] | sorry, Pekr's version... |
should it not be 0.00417? | |
Pekr 26-Jan-2010 [15678x2] | ah, yes, it is buggy. "4" somehow disappeared :-) |
amacleod - the fix is easy - just replace "insert tail tmp rest" by "insert tail tmp join main rest" | |
amacleod 26-Jan-2010 [15680x2] | Thanks Pekr...I did not have time to look at it but I''m working on an app that need this function. Thanks. |
What's the easiest way to convert from money! back to decimal or integer? | |
Sunanda 26-Jan-2010 [15682] | In r2: >> second $12.33 == 12.33 |
amacleod 26-Jan-2010 [15683] | Ok, I see...its a combo of string and decimal.. |
james_nak 26-Jan-2010 [15684] | I think I asked this before or figured it out but now the mind has lost the answer. I build strings (via a join) that reference existing objects. Obviously the joining part is easy but of course I end up with a string. |
Graham 26-Jan-2010 [15685] | >> to-path "a/b/c" == a/b/c |
james_nak 26-Jan-2010 [15686] | Graham, here's the issue: I have some vid objects such as ua-fname: field. They follow a pattern in that the "ua" stands for "User Add" and the rest corresponds to the actual field name in the DB. The function I am writing is created in a way to be very generic and knows how to handle an insert into the DB based on a few parameters. What I am looking for is a way to "create" a name by joining "ua-" and field name which refers to the actual vid gadget. |
Graham 26-Jan-2010 [15687] | fldname: do join "ua-" db-field-name |
james_nak 27-Jan-2010 [15688] | Graham, you are the man. That works perfectly. Thanks for the info and saving me a ton of time. That's one of those "How in the world did you know that?" things to me. I guess that "do" says "What does this mean to me?" - the "me" being Rebol . I appreciate your help (once again). |
Graham 27-Jan-2010 [15689] | James it works because data is code |
Gregg 27-Jan-2010 [15690x3] | Has anyone extended the FOR* funcs to have special handling options for the first and last elements? Gab's power-mezz, and an idea from another template generator made me think of how I do that today. Here's the basic idea: |
forskip+: func [ "Like FORSKIP, but with local FIRST? and LAST? support." [throw catch] 'word [word!] {Word set to each position in series and changed as a result} skip-num [integer!] "Number of values to skip each time" body [block!] "Block to evaluate each time" /local orig result ][ if not positive? skip-num [throw make error! join [script invalid-arg] skip-num] if not any [ series? get word port? get word ] [ throw make error! {forskip/forall expected word argument to refer to a series or port!} ] orig: get word use [first? last?] [ first?: true last?: false body: bind/copy body 'first? while [any [not tail? get word (set word orig false)]] [ if tail? skip get word skip-num [last?: true] set/any 'result do body set word skip get word skip-num first?: false get/any 'result ] ] ] | |
b: [a b c d e] forskip+ b 1 [ if first? [print 'first] print b/1 if last? [print 'last] ] | |
BrianH 27-Jan-2010 [15693x2] | FIRST? seems like HEAD? with an assumed parameter, and LAST? seems like SINGLE? with an assumed parameter. |
SINGLE? is in R3 and will be in 2.7.8. | |
Gregg 27-Jan-2010 [15695x2] | The idea is that it could apply to all the interator funcs, so you don't have different types of checks for FOR/LOOP/REPEAT, FORSKIP, or FOREACH. |
And LAST? wouldn't be like SINGLE? in the context of FORSKIP with a bump value other than 1. | |
BrianH 27-Jan-2010 [15697] | Ah, good point. Too bad we can't write mezzanine loop functions in R3 yet :( |
Graham 27-Jan-2010 [15698x2] | Can the R2/forward stuff be used with 2.7.6 or does it require 2.7.7 ? |
I think you said you were aiming for 2.7.5 | |
BrianH 27-Jan-2010 [15700x3] | I'm aiming at 2.5.0, but I've only hit 2.7.5 so far. |
Much of the R2/Forward stuff has been incorporated into 2.7.7 already, and most of the rest (except maybe 3 functions) will be in 2.7.8. | |
It's a good thing the Power Mezz package is license compatible too, since some of those seem like good, non-disruptive adds. | |
Graham 27-Jan-2010 [15703x2] | Ok I'll see if I can use them inside the sdk... |
I've been writing stuff using R3 functions ... and it seems a waste of my time to rewrite for R2 | |
BrianH 27-Jan-2010 [15705x3] | That's why I wrote R2/Forward in the first place :) |
The R2/Forward functions that are unlikely to be incorporated in R2 directly are APPEND, REMOLD and LIST-DIR; the first two because they demonstrate the problem with adding too many options to a function, and the latter because it isn't good enough yet, even in the R3 version. | |
Watch out for native functions that already existed in R2 and which were changed in R3: Those changes haven't been backported. | |
Graham 27-Jan-2010 [15708] | oh .... nothing straight forward |
BrianH 27-Jan-2010 [15709x4] | There aren't many native changes in R3 except architectural: R3's main changes: - Fixes the off-by-one error for PICK and POKE (and path indexes) of non-positive indexes - Ordinal functions now return #[none] on out-of-bounds rather than throwing an error - Expansion of capabilities of FOREACH, subjects of SELECT - Datatype conversion changes, mostly minor except to/from binaries - Removed "features" that were more trouble than they were worth, and have been replaced by new features (backported) - Removed features that haven't been replaced yet (like [throw] function attributes) - Major changes in the port and GUI models and PARSE |
Note that the off-by-one error of AT with non-positive indexes probably won't be fixed. | |
CureCode dismissed tickets are a good place to start - most of those were requests for R2 compatibility where inappropriate. | |
I apologize - most of the CureCode dismissed tickets are requests by meijeru for consistency. Only some are compatibility requests. | |
Maxim 28-Jan-2010 [15713] | is there a listing of changed natives? I rarely find that they make things better, if they change the api of a function. |
BrianH 28-Jan-2010 [15714x2] | There hasn't yet been a final list, but someone (probably me) should go through CureCode and make a draft list in DocBase. And there's the change list for the releases too, though that is mostly CureCode references. |
Almost all of the changes have been for the better, though some were mostly for greater consistency. Changing the API is OK if the old one was really bad, and if there is a rationale for having any change be OK. For instance, changes are much more restricted in new R2 releases since the continuing existence and development of R2 is the justification for allowing the more radical changes in R3. | |
Maxim 28-Jan-2010 [15716] | if it means I have to revise 5 MB of code, any change isn't welcome ;-) |
older newer | first last |