Re: Argument for "foreach"

new topic     » goto parent     » topic index » view thread      » older message » newer message

Kenneth Rhodes wrote:
> 
> Jason Gade wrote:
> > 
> > I was going to say that for a language that has a flexible sequence as its
> > main
> > data type that foreach would make a lot of sense, but I already said it in
> > the
> > thread that you posted. blink
> > 
> > You could always write a foreach routine that takes a routine ID:
> > }}}
<eucode>
> > procedure foreach(object list, integer rid)
> >     -- define your called procedure so that it takes an object and an index
> >     for i = 1 to length(list) do
> >         call_proc(rid, {list[i], i})
> >     end for
> > end procedure -- foreach
> > </eucode>
{{{

> > You could also define a function called map that does the same thing but
> > calls
> > a function and returns a modified sequence instead:
> > }}}
<eucode>
> > function map(object list, integer rid)
> >     sequence out
> >     
> >     out = list -- allocate enough memory to start
> >     
> >     -- define your called function so that it takes an object and an index
> >     for i = 1 to length(list) do
> >         out[i] = call_func(rid, {list[i], i})
> >     end for
> > 
> >     return out
> > end function -- map
> > </eucode>
{{{

> > There are other sequence operations that I would like to see built in, like
> > sum(), but what can you do?
> > 
> 
> I've been trying to understand benefit of translating/compiling routines
> into *.dll or *.so files. Wouldn't these types of routines benefit most
> from being tanslated/compiled and wrapped? And once wrapped, could they
> be called as easily as the euphoria source code above?
>   I have been
> studying the examples in Euphoria documentation and demo files - all
> seems very obscure to me, hence I am eager to see Jeremy's wrapper hit
> the contribution page.

I don't know as I've never done it. I don't think that it would gain you much
for such short routines as above. I imagine that routines with > 10-15 lines and
which are heavily used by your program would benefit the most.

Plus, like Rob replied to my optimization post, you would lose some
troubleshooting information from ex.err.

Remember to debug and profile before you try to optimize!

--
"Any programming problem can be solved by adding a level of indirection."
--anonymous
"Any performance problem can be solved by removing a level of indirection."
--M. Haertel
j.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu