On 11/29/07, James Fuller wrote:
well, if my previous posts didn't attract flames.... this post certainly will ;)

Nah, this is getting into the interesting language part! (Technically, it should be perl6+xml-language... but then the goal of perl6 is to be infinitely flexible, so I guess it is on topic!)

but you did say 'from a users perspective' ... so I will play 'make believe' with some syntax

I mentioned in my previous message that there is a technical side to the issue of standards. That involves questions about what makes for a "good" XML (etc.) module (which raises the question, "Good for *what*?" -- a practical answer is, what's good for a lot of the people a lot of the time. Maybe there's no single answer even to that question, so perhaps there are multiple standards in some cases; that's fine. And of course, there will always be de facto standards based on whatever "most people" happen to be using at any given time. That's fine too.)

But one of the obvious things that makes a module technically good -- and the one that's most relevant here -- is what its "dialect' is like, how its syntax works, how perlish it is; in other words, how well it fits in with design goals of perl6 as a language. We've all seen modules that worked but didn't feel very perly (and a good Python XML module might look very different from a good Perl one).

So I think what a P6 XML module would look like (as opposed to how it works) is certainly worth discussing here. (Or indeed, any other module, as far as its linguistic aspects go.) The first thing that caught my eye about James's examples was the way he plunked XML (that looked like XML) in the middle of Perl (that looked like Perl).

my $sales = <sales vendor="John">
    <item type="peas" price="4" quantity="6"/>
    <item type="carrot" price="3" quantity="10"/>
    <item type="chips" price="5" quantity="3"/>
no surrounding quotes seems about right.

Having just been admiring Aurdrey's XML::Literal module the other day, I was wondering whether it could work in Perl6. P6 already works the angles pretty hard -- you couldn't make them quote a piece of XML without giving up their standard string-quoting function. But hey, maybe that's worth it if you're doing a lot of XML. Could P6 still recognise a hash-key quoted %like<this> as a special non-XML case? (Should it? Would XML-keys be particularly useful?) Or is it better to pick some other characters as the XML-quoters and have the code "almost" look like XML?

Having your XML look like XML carries definite advantages, and having things look like what they are is definitely part of Perl's philosophy. But on the other hand, XML is kind of bulky and awkward, so maybe the Perly thing to do would be to translate it into something that looks like how it works: XML documents are trees, so maybe they ought to look more like ordinary hashes.

(E.g. on 11/29/07, Patrick R. Michaud wrote:
    my $doc = Document.new;
    $doc<some><content> = 'here';

-- much better than a here-doc, which wouldn't provide you with syntax-checking, syntax-colouring, or syntax-anything-else.)

[...]I like my 'scanability' to be in xpath form ala:
    my $select_li_elements  = $html[/html/body/span/ul/li];
and then u have the expressive power of xpath inside of these brackets.

Perl would more likely use something like $html<html/body> (or even $html<html><body>), since square brackets mean ordinal indices (though you could make that work too). You could have $html<html/body> and $html.html.body both work. Perhaps more interesting is to consider something like:
        my $select_li_elements = /$html/body/span/ul/li;

( as an aside, is there any concept of the native types, Scalar, Array, Hash being in a different namespace then all the other symbols e.g. could I override Scalar type ?)

I guess the idea would be to have unspecified scalars default to the XML type (instead of type Any)? Sure! (I don't know exactly how, I just know P6 lets you do anything you want.) Of course, if you have special quotes, there might be no need: if Perl knows that <foo/> is XML data, then "my $f=<foo/>" will do the right thing.

This would replace text context node of <div id="mydivid"/>
    $html[/html/body/[EMAIL PROTECTED]'mydivid'] ] = "new text value";

$html<html><body><divp>:id<mydivid> = "new text value"; ?

I am unsure of what an append scenario  would look like.

push?  ~=?  .append()?

Perhaps one would like to be able to decide if this xml must be checked for validaty against some schema technology (DTD and relaxNG as basic) .... are there any 'adjectives when declaring a type ... I guess I am suggesting a new sigil enforcing an XML context ;0

That wouldn't be a new sigil (despite Perl6 letting you do anything, I think this is one area where it would look the other way and pretend not to hear you unless you got really insistent); probably you'd say:
        my XML::Doc $foo is validated($dtd);

should print out the value of each div contained in html
for $myxmlvar[/html/body/div]]{
    print; # prints $_, the current loop variable

Yup (although I think that should be: for =$myxmlvar[etc...]).

I will stop here ... so I can put on my flame proof suit.

I find nothing to flame here, but lots to discuss.


Reply via email to