World: r3wp
[I'm new] Ask any question, and a helpful person will try to answer.
older newer | first last |
Will 4-Mar-2008 [1369] | what is the best way to convert this 4E-2 to 0.004 ? |
Oldes 4-Mar-2008 [1370x4] | 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 #"." ] >> formDecimal 4E-2 4 == "0.0400" |
>> formDecimal (4E-2 / 10) 3 == "0.004" | |
hm.. maybe not the best as there is this issue: formDecimal 4E-3 2 == "0.00" | |
it depends what do you need... if is important the value or how the rounded value looks like | |
Will 4-Mar-2008 [1374] | thank you Oldes, I thought there was a native or mezz for that |
sqlab 9-Mar-2008 [1375] | a little bit late form-dec: func [ number [decimal!] ] [ form case [ number > 1 [number] number > 0 [ join "0" at form number + 1 2 ] number > -1 [ join "-0" at form number - 1 3 ] true [number] ] ] |
JohanAR 14-Mar-2008 [1376] | why does join 'a 'b return "ab" instead of 'ab ? |
Sunanda 14-Mar-2008 [1377] | join always returns a string unless the first value is of type? series. >> join 1 2 == "12" Try source join to see the actual code. |
[unknown: 5] 14-Mar-2008 [1378] | JohanAR, use this instead: attach: func [a b][to type? a join a b] |
JohanAR 14-Mar-2008 [1379x2] | thanks! |
On to the next question :) Why is '= valid but '< or '> aren't? | |
Geomol 14-Mar-2008 [1381x2] | My guess is, that it's becuase < and > are part of tag type, like <tag>. So it's a restriction to make value evaluation easier internally. |
>> blk: [=] == [=] >> blk: [<] ** Syntax Error: Invalid tag -- < ** Near: (line 1) blk: [<] >> blk: [<tag>] == [<tag>] | |
BrianH 14-Mar-2008 [1383] | >> type? first [<] ** Syntax Error: Invalid tag -- < ** Near: (line 1) type? first [<] >> type? first [ < ] == word! |
Geomol 14-Mar-2008 [1384] | hehe, funny! :) |
BrianH 14-Mar-2008 [1385x4] | I guess it is special-cased in the loader. |
>> attempt [[<]] ** Syntax Error: Invalid tag -- < ** Near: (line 1) attempt [[<]] >> attempt [load "[<]"] == none | |
This relates to the sandboxing discussion I was just having with Paul. | |
The first error isn't caught because the load happens before the attempt is called. | |
JohanAR 14-Mar-2008 [1389] | you can ofcourse use to-word "<" but it's not very good looking if you have to cover all of <, <=, >, >=, <> etc.. managed to avoid the case by using compose instead of reduce though |
JohanAR 15-Mar-2008 [1390] | Is it possible to define a function, which takes another function as argument and that the argument func must take exactly two arguments in it's turn? |
PeterWood 15-Mar-2008 [1391x5] | This is how you can pass a function to a function: >> a: func [a [function!]] [ print a 1 2] >> b: func [x [integer!] y [integer!]] [add x y] >> a :b 3 |
Sorry about the formatting; let my try again: >> a: func [a [function!]] [ print a 1 2] >> b: func [x [integer!] y [integer!]] [add x y] >> a :b 3 | |
I think you will need to "manually" check that the supplied function uses the correct number of arguments | |
>> c: func [a [function!]] [if 2 = length? first :a [print a 1 2]] >> c :b 3 | |
>> d: func [][print "no args"] >> c :d == none | |
JohanAR 15-Mar-2008 [1396x3] | Mm, I ended up writing something similar to that. Found out that I also have to check if third first :a is /local, which would also be a valid function |
getargs: function [ :fun "Get arguments from this function" ][ out pblock ][ out: make block! 10 parse third :fun [ some [ string! ; Strip comments | [ [word! | get-word! | lit-word!] (pblock: [any-type!]) opt [string!] opt [set pblock block!] opt [string!] (append/only out pblock) ] ] ] out ] | |
a little messy, but it appears to work :) | |
BrianH 15-Mar-2008 [1399x6] | You don't have to manually check to see if the function takes two arguments; this is good, because doing so is awkward. All you really need to do is call the function in parentheses ( ) or at the end of a code block, so that it can't take more than two arguments even if it tries. If it takes less than two arguments, who cares? |
Be sure to assign the use or assign the result of the function call inside the parentheses, rather than outside them, in case the function takes less than the number of arguments you are expecting it to. | |
Do source replace in REBOL 2.7.6 for an example of this - look for the parentheses. | |
The ARRAY function in 2.7.6 does the end-of-the-code-block method for function value arguments. | |
If the datatypes the function value is expecting don't match the data that your function is passing to it, no problem: A nice error message will be generated at runtime that the developer of the function value can use to fix their function value. :) | |
assign the use -> "use" | |
Gabriele 16-Mar-2008 [1405] | Carl had a nargs mezz somewhere (maybe he posted it on the ml?) |
Gregg 17-Mar-2008 [1406] | http://www.fm.tul.cz/~ladislav/rebol/argstake.html |
RobertS 23-Mar-2008 [1407] | ; what is the rationale, I wonder of the difference >> lit-word? first [ 'thang thing] == true >> lit-word? 'thang == false >> type? first ['thang thing] == lit-word! >> type? 'thang == word! |
BrianH 23-Mar-2008 [1408] | type? first ['thang] 'thang is not being evaluated type? 'thang 'thang is being evaluated. The result of that evaluation is a word! |
Sunanda 23-Mar-2008 [1409] | .....But with 'reduce, 'thang is being evaluated, so: type? first reduce ['thang] == word! |
RobertS 23-Mar-2008 [1410] | thang -ks |
Henrik 26-Mar-2008 [1411] | I can't believe I missed all those REBOL tutorials available on Youtube by Nick Antoniacco. Here's the complete list, in case newbies missed them too: http://musiclessonz.com/rebol_video_links.html |
Reichart 26-Mar-2008 [1412x2] | Interesting guy http://rockfactory.us/Teachers.html |
He is the top one "Nick" | |
Gregg 27-Mar-2008 [1414] | Didn't RT link to those from REBOL.com at some point? If not, they really should. |
Will 27-Mar-2008 [1415] | looking at source of 'send, am I right, if there is an error executing send, than the port is not closed, this will leave a lot of open connections when batching? |
BrianH 27-Mar-2008 [1416] | Ports are closed when the garbage collector gets them. If you are batch sending, the next time you call the SEND function it will assign none to the smtp-port local variable, rendering the previous reference assigned to that variable into garbage. The next time RECYCLE is run, any open ports in the garbage will be closed. |
Will 27-Mar-2008 [1417x2] | ok, but between recycles, I could reach the maximum connections limit of the smtp server? |
also, 'send should probably return a value of type logic! | |
older newer | first last |