World: r3wp
[!REBOL3-OLD1]
older newer | first last |
BrianH 31-Dec-2009 [20552] | Actually, documenting that this function doesn't do any error handling beyond the arguments of + would be good. |
Gregg 31-Dec-2009 [20553] | Agreed. |
Paul 31-Dec-2009 [20554] | Sounds like the function is moving along. Great thing is that if you build the one you have what you need for the product function as well. |
BrianH 31-Dec-2009 [20555x2] | sum: func [block [block! vector!] /local result] [ result: 0 foreach value reduce block [result: result + :value] result ] |
Some error handing, some speedups, and vector support. | |
Steeve 31-Dec-2009 [20557x2] | no need to return the result at the end |
foreach do that | |
BrianH 31-Dec-2009 [20559] | Not for a empty block. |
Steeve 31-Dec-2009 [20560] | right |
BrianH 31-Dec-2009 [20561x2] | And it will just throw an error if the block contains anything not addable. |
That's the R3 way - throw a useful error so the programmer can fix their code, no DWIM :) | |
Paul 31-Dec-2009 [20563x2] | why the :value? |
Your already reducing the block. | |
BrianH 31-Dec-2009 [20565] | In case reducing the block makes a function or some other active value - no double eval. It's a way to trip bad errors quicker. |
Paul 31-Dec-2009 [20566] | ok. |
Steeve 31-Dec-2009 [20567x3] | uggly one-liner version. sum: func[block [block!]][ foreach [v1: v2] next head reduce/into block copy [0 0][v1/1: :v2 + v1/0] ] -_-; |
yeah !!!! i do not use any locals | |
... | |
Gregg 31-Dec-2009 [20570] | It uses a lambda local. :-) |
Steeve 31-Dec-2009 [20571] | i should have used forall, less uggly :-) |
BrianH 31-Dec-2009 [20572] | And faster. Reversing the order of arguments might not be a good idea though - some operators are more forgiving of their left value. |
Steeve 31-Dec-2009 [20573] | i was not seriously doing a proposal :-) |
BrianH 31-Dec-2009 [20574] | v1/1: v1/0 + :v2 |
Gregg 31-Dec-2009 [20575x2] | Yeah, I'm trying to remember (since I didn't comment it) why I coerced the result. Something in my brain says there was a good reason. |
Maybe I'll remember if we write a test suite for it. | |
BrianH 31-Dec-2009 [20577] | We should make a whole module of math functions, with test code. Let the REBOL optimizer at it and then see what we can include. |
Steeve 31-Dec-2009 [20578] | Who's that optimizer ? |
BrianH 31-Dec-2009 [20579] | The "REBOL optimizer" is a running joke. The best way to optimize your REBOL code is to post it publicly in AltME or R3 chat and dare people to improve it. Then the community tries to one-up each other to improve it :) |
Steeve 31-Dec-2009 [20580] | -_-; |
BrianH 31-Dec-2009 [20581] | It's the best optimizer known to man :) |
Steeve 31-Dec-2009 [20582] | sure :) |
BrianH 31-Dec-2009 [20583x2] | For certain project domains, R3 interpreted code can be faster than compiled code, once it's been through the REBOL optimizer. |
That happened with some REBOL-vs-Java code the other day here. | |
Steeve 31-Dec-2009 [20585] | but there is several criteria to optimize something. - Best Speed - Shortest code - shortest memory overhead - best ratio of above criteria |
BrianH 31-Dec-2009 [20586x2] | An interesting example of that is AJOIN. The R3 version has less memory overhead, the R2 version in 2.7.7 is faster. |
Oh, and that means that the mezzanine is faster than the native :) | |
Steeve 31-Dec-2009 [20588] | rare |
BrianH 31-Dec-2009 [20589x2] | Not really, for code that plays to REBOL's strengths. It happens quite often. |
Rare for the kind of thing you tend to do though (emulators, iirc). | |
Rebolek 1-Jan-2010 [20591] | throw/catch does not work in R3? |
Carl 7-Jan-2010 [20592] | Testing. |
BrianH 7-Jan-2010 [20593] | Bolek, THROW and CATCH work in R3 but there is a strange interaction with TRY. |
Graham 10-Jan-2010 [20594] | How about we have some more refinements to read ?? |
Pekr 11-Jan-2010 [20595] | Graham: my reply from R3 Chat: I think that we will not get much refinements for read/write functions. The planned ones were /string (text) and /as (enconding). What you want is read working in a streamed way. We might get it in future, but I doubt we get what you propose. |
Graham 11-Jan-2010 [20596] | Why not? Because refinements slow down 'read? |
Pekr 11-Jan-2010 [20597x2] | And maybe design of read/write was never actually finished ;-) |
16-Apr-2008: Prunning down read and write - http://www.rebol.net/r3blogs/0127.html 11-Nov-2009: Finalising read and write - http://www.rebol.net/r3blogs/0294.html | |
Graham 11-Jan-2010 [20599] | well, I guess we could specifiy it in the /as block |
Pekr 11-Jan-2010 [20600x2] | I don't know. Just read realated discussions - many opinions, what read/write should (not) do ... |
I am with ones proposing having read/write as simple as possible, adding just /as for codec support. Codec API should be defined, the same way as we have Device API, port API, etc. /string should be no excuse .... in the past (1.2 days), Holger posted to IOS: read http://something.com:my-callback | |
older newer | first last |