[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Map and filter without intermediate tables
- From: joao lobato <btnfdp.lobato@...>
- Date: Thu, 7 Jun 2012 13:06:00 +0100
On 6/7/12, steve donovan <email@example.com> wrote:
> On Thu, Jun 7, 2012 at 1:06 PM, Geoff Leyland <firstname.lastname@example.org>
>> Yes, but if you have a function generating a sequence and a series of
>> sequence processors that might do things like map or filter that sequence,
>> then you might consider avoiding intermediate tables, since there was
>> never a table in the first place.
> That was the idea behind pl.seq
>> f = stringio.open 'one\n\ntwo\nthree'
> TWO THREE
> But I've never bothered to check the speed - I suppose the thing about
> iterators is that they are 'lazy lists', potentially infinite.
>> seq(function() return math.random(1,10) end):take(5):printall()
> 4 9 9 8 2
> Personally, I prefer method chaining to functional application, since
> my brain tends to work best left-to-right.
> steve d.
Yes, I can see why method chaining seems easier to follow when reading
code, but it is in contravention of  and I don't want to be stopped
by the police :-) .
Things like list comprehensions, pattern matching as it exists in
Haskell or Erlang, unification and backtracking in Prolog, deal with
"white boxes". By using them one is foregoing most encapsulation. When
programming in the large, encapsulation is everything. Of course they
are useful tools, but sometmes they feel like a very particular and
proprietary Phillips screwdriver. You keep those in the toolbox, the
hammer (the for loop in Lua or the recursion in a functional language)
should be in your belt.