Since I've seen a number of postings reference Paul Graham's writings, I started going through all of them. I came across a specific detail as an example in his essay on designing programming languages:
In Common Lisp I have often wanted to iterate through the fields of a struct-- to comb out references to a deleted object, for example, or find fields that are uninitialized. I know the structs are just vectors underneath. And yet I can't write a general purpose function that I can call on any struct. I can only access the fields by name, because that's what a struct is supposed to mean.
Now, in Perl 5 the contents of anything can be inspected and iterated. There are two kinds of collections: arrays and hashes. Either can be iterated, so objects using a collection for a list of instance data can be iterated. Why do this? Think Data::Dumper. It's handy for debugging and exploring, not to mention persistance. And his examples of combing out references to something deleted or checking for undef's isn't a bad idea in Perl, either.

Obviously, it's possible to write non-iterating objects in Perl 5, since you can choose any implementation you like. The instance data can be a blessed scalar cookie, and the real data visible only to the access methods.

Now Perl 6, from what I've heard, is exactly this way. The object's state is stored in a manner known only to the implementation, and all access is really done though access method function calls.

How can you Dump that?

Even if you must call the approved functions to get the values, simply having a list of what those functions are would be handy. That is, a list of members available as meta-data.

This might be possible as a result of other features. For example, scan the package's symbol table for subs, and figure out which are methods (leading dot in the name? associated properties? How to tell the difference between a simple accessor and more complex functions?). I think the designers should make sure this is possible. Perhaps publishing a list of functions that were generated as accessors to named instance data is the only for-sure solution to enable something like Data::Dumper to be general-purpose.

—John


In reply to Make sure Perl 6 is introspective enough by John M. Dlugosz

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.