Hi Ed,
So the main overhead there is the two calls to concat, which result in
a lot of unnecessary copying of data -vs- the make version.
In any case the entire program won't be functional since its writing
to a file at the end, but suppose we did what Erlang does, and allowed
'write' to take either a string, or a list of strings, or a list of
lists of strings, etc.
"Hi" write
{ "Hello " { "W" "orld" } } write ! same as "Hello World" write
Then we could write 'render' as
: render ( -- data )
height [ width swap '[ _ c pixel color ] map ] map ; inline
And pass the return value to 'set-file-contents', without having to
use concat, flatten or anything else to flatten it into one big
sequence of bytes. This would be quite efficient, and 'render' at
least would be purely functional.
Slava
On Thu, Sep 11, 2008 at 7:57 AM, Eduardo Cavazos <[EMAIL PROTECTED]> wrote:
> Slava,
>
> I messed around with a "functional" version of mandel. In this
> version 'mandel' is:
>
> : mandel ( -- data ) ppm-header render append ;
>
> I.e. 'ppm-header' and 'render' return byte arrays which are then appended.
>
> The current 'render' is:
>
> : render ( -- )
> height [ width swap '[ _ c pixel color % ] each ] each ; inline
>
> To get the functional version, throw out the '%' and convert the calls
> to 'each' with 'map concat':
>
> : render ( -- data )
> height [ width swap '[ _ c pixel color ] map concat ] map concat ; inline
>
> Taking the 'ppm-header' from my previous note and converting it:
>
> : ppm-header ( -- data )
> width number>string height number>string
> -> WIDTH HEIGHT
> { "P6\n" WIDTH " " HEIGHT "\n255\n" }
> concat >byte-array ; inline
>
> Of course this version of mandel is slower than the versions where a byte
> vector is appended to. Is there a chance that a functional version along
> these lines might someday be just as fast?
>
> Ed
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Factor-talk mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk