It's strange, but I'd rather go the other way and define most things that use a name to access a value using the tie interface. Everyone who uses Perl rapidly learns how to use hashes and what methods (exists, each slices etc.) are available to operate upon them.

That means that if I present a tree or trie or Bag or map or whatever using the tied hash interface, then every Perl programmer familiar with hashes instinctively knows how to use (and read) code that uses this new data type with the familair interface.

The alternatives, whether OO or functionally abstracted, require them to ponder the documentation to find out how to use them.

Whilst the tie interface has its limitation, especially with respect to nesting, that (as far as I understand them) are limitations of the implementation rather than the concept, the simplicity of

tie %trie, 'Tie::Trie'; $trie{ fred } = 10; $trie{ bill } = 20; $trie{ total } = sum values %trie;

versus

my $trie = Trie->new(); $trie->add( 'fred', 10 ); $trie->add( 'bill', 20 ); my $temp = sum map{ $trie->lookup( $_ ) } 'fred', 'bill'; $trie->add( 'total', $temp );

or

my $trie = maketree(); extend-trie( $trie, 'fred', 10 ); extend-trie( $trie, 'bill', 20 ); ## Does your lisp stuff define a way of iterating the keys? my $temp = sum lookup( $trie, 'fred' ), lookup( $trie, 'bill' ); extend-trie( $trie, 'total', $temp );

Is self evident (to me).

If the autovivification of nested tied structures wasn't buggy, I could see myself defining whole OO-style inheritances using this kind of notation. I haven't seen an OO implementation that really worked well with collections of objects rather than individual instances.

$collection->set( 3, $collection->get( 3 ) + 1 );

Is just no substitute at all for

$collection[ 3 ]++;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

In reply to Re: Using functional abstraction in Perl by BrowserUk
in thread Using functional abstraction in Perl by spurperl

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.