The above non-recursive example is what you gave to explain why you
wanted a recursive version in Perl. If we are not to assume that you
are just babbling incoherently, then the most reasonable assumption is
that you for some reason thought the above was recursive. Otherwise
using it as an example is just bizarre.
You missed the point. I didn't mention the Erlang script to begin with
because it wasn't relevant to the question. I only mentioned it in the
context of providing an explanation of the original post. Perl doesn't
have list comprehensions, as far as I know, so you are correct in that
asking for a Perl script for finding Pythagoriean triples would indeed
be bizarre. But that wasn't the point.
The point was -- Can you find Pythagorean triples in Perl using
recursion? If you want a generalization, how do you solve a problem
that calls for triple recursion. PJH provided one solution that I
didn't like, but the next day I spend almost the entire day trying to
better it, and I failed. I'm not convinced that it can't be done in a
simpler way, but I don't think I can do it.
To make a larger point, Paul Graham has pointed out that different
languages are different, plugging Lisp. MJD showed how to write Perl
using Lisp-like constructs. Someone, I don't remember who, commented
that Perl can do everything Lisp can do except for Lisp macros.
Several years ago, Time Bray authored a famous blog attempted to use
Erlang to construct a database application, and concluded that Erlang
wasn't suited for the job, yet CouchDB uses Erlang.
And please don't point out that Erlang is derived from Prolog, not
Lisp. I know that. I also know that Lisp has iterative constructs, but
Erlang doesn't. The tie to Erlang was that the particular example used
list comprehensions, and I wondered how you could use Perl to do the
same kind of job, and recursion was as close as i could come to
Erlang's list comprehensions.
In one sense, this thread is simply an idle conversation, something
that you kick around in the break room. In another sense, discussing
how a particular algorithm can be implemented in Perl (or any other
language) is the kind of thing that 'sharpens the axe.'
If you think it's 'incoherent babble' you are free to ignore the
thread. If you think you can code a recursive Pythagorean triple
finder in Perl, you are welcome to try.
CC.