<div class="gmail_quote">On Thu, Mar 15, 2012 at 11:54 AM, Per Melin <span dir="ltr"><<a href="mailto:per.melin@gmail.com">per.melin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">I wrote:<br>
<br>
> I'd happily do away with selectors for Erlang, but I doubt I could create an API that would be nearly as expressive in a way that takes any less effort to learn.<br>
<br>
</div>I wish I hadn't been quite so quick to make that statement.<br>
<div class="im"><br>
<br>
> E.g. "div#foo span.bar:first-child" matches any <span> with class "bar" that is the first child of its parent element and also a descendant of a <div> with id "foo".<br>
<br>
</div>This (expressing the same rule as above) would arguably take less effort to learn at least:<br>
<br>
brim:descendant(<br>
brim:id(foo, brim:element(div)),<br>
brim:first_child(brim:class(bar, brim:element(span)))<br>
)<br>
<br>
But it is too verbose.<br>
<br>
So we are tempted to start down this road (Jack Moffitt saw it coming):<br>
<br>
{descendant,<br>
{id, foo, {element, div}}},<br>
{first_child, {class, bar, {element, span}}}<br>
<br>
If either is easier to read comes down to whether you know the (small) grammar of selectors, I guess.<br>
<br>
We'd do away with the string parsing, and both of the above are composable. Double big win. But still too long I think, even if we shorten the keywords. On the other hand, because they are composable we would not have to write the full thing every time.</blockquote>
<div><br></div><div>You could also consider going down the road of parse transforms to keep the string syntax but get rid of the runtime string parsing.</div><div><br></div><div>Personally I like the CSS selector syntax. It's terse but not hard to understand, and you already know it if you've done pretty much any client-side web development. Even with an alternative syntax you're still going to need to learn a subset of the same keywords (id, first_child, etc.) which is I think much more work than picking up the grammar.</div>
<div><br></div><div>-bob</div><div><br></div></div>