FWIW, the code is not meant to be efficient, or real-world useful. It is meant to be an example of the argument pattern matching style of ML with perl6.

I understand that. The problem is, whenever I look for any examples of FP-style programming, these are the same examples that are always given--like they exemplified the virtues of FP?

However, it does illustrate the style of programming which is free of both assignment statements and side effects. This style is an area of interest in the study of concurrent programming (both non-assignment and single assignment variables actually). By not introducing side effects and limiting assignment you can remove an entire class of concurrent programming issues

Thankyou for that last sentance!

That is the first time in nearly 4 months of looking that I have seen, what appears to be--on the surface at least--a good reason for wanting to use "the style of programming which is free of both assignment statements and side effects".

Most every other text I've read that attempts to justify this style of code--where they bother at all--attempts to do so on the basis of provability. An argument that simply doesn't hold water--but I think I debunked that claim enough elsewhere.

I'm not entirely convinced that the concurrency argument works, but it certainly gives me another angle to research. Thanks.

It is also useful to not think of this style of programming the way you view procedural execution.

I hope you'll excuse me for saying this, but that sounds a bit like saying not to compare getting from Beachley, Wales to Aust, England by:

  • following the left and right banks of the River Severn via the source.

    with:

  • Crossing the Severn Bridge.

    Both would work, but even with the bridge toll, you probably won't get many takers for the former.

    If you were to write these functions in prolog (or something similar like Erlang) the code would be quite similar, but since the execution model is much different, they are not as in-efficient as you might think.

    This I would like to understand? Any pointers on how the mutually recursive is_odd()/is_even() method of determining a numbers oddness can be made efficient?

    Unless of course the interpreter/compiler recognises the pattern and optimises it to x & 1, in which case it is similar to perl5 sort in as much as

    sort{ $a<=>$b }@array

    never actually sets $a or $b or transfers control to the block. In reality, the entire construct is simply recognised to mean

    sortNumericallyAscending( @array )
    .

    Whilst that makes sense for Perl in terms of backwards compatibility, I don't follow the logic of creating entire languages that purport to hold to some ideal of academic purity, only to then need to create hugely complex optimising compilers with hardcoded recognition of the common, elegantly inefficient, idealised idioms and convert them wholesale to standard code. That just makes the idealism a source level sham.

    And if you were stranded on a deserted isle with only functions and simple logical and comparison operators, and all your assignment statements, for & while loops, if statements etc, were lost at sea. You would have to program like this too.

    Given those rather unlikely circumstances arose, I would spend my first week programming a string type that only needed to calculate it's length when assigned to--I guess I'd have to re-invent assignment first--bitwise and, for & while loops and if statements. And the next week writing a C compiler that could compile itself...


    Examine what is said, not who speaks.
    Silence betokens consent.
    Love the truth but pardon error.

    In reply to Re^4: Functional Perl 6/PUGS by BrowserUk
    in thread Functional Perl 6/PUGS by stvn

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.