<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<br>
Daniel Keep escribi&oacute;:
<blockquote cite="mide3ecf0$1kuo$1@digitaldaemon.com" type="cite">
  <pre wrap="">antonio wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">As I introduced in <a class="moz-txt-link-freetext"
 href="http://www.dsource.org/forums/viewtopic.php?t=967">http://www.dsource.org/forums/viewtopic.php?t=967</a>
object relations could be seen as hierarchycal structures.

&iquest;Why not to introduce native syntax to "navigate into"/"Selec from" this
kind of hierarchies?


ex 1: Add Peter to the friends of people named Andrew and older than 18.

Person peter = ...;
Person[] people = ...;

people[name=="Andrew" &amp;&amp; age&gt;18].friends ~= peter;


    </pre>
  </blockquote>
</blockquote>
...<br>
<blockquote cite="mide3ecf0$1kuo$1@digitaldaemon.com" type="cite">
  <blockquote type="cite">
    <pre wrap="">
---

The main discussion about this idea was focused in 2 points:
1. "dot" or "not dot":
    people[.married &amp;&amp; .age&gt;18]
    vs
    people[married &amp;&amp; age&gt;18]

   "not dot" is more "D" syntax compliat (thanks to csaul).

2.Array syntax vs "Template" syntax:
    people[married &amp;&amp; age&gt;18]
    vs
    people![married &amp;&amp; age&gt;18]

  Personally, I prefer "Array syntax":
    Person p = people[5];
    Person[] p = people[3..5]; // 3..5 is a "condition"
    Person[] p = people[5]; // &iquest;why not?
    Person[] p = people[married];
    Person[] p = people[age&gt;18 &amp;&amp; married];
     
    
    </pre>
  </blockquote>
</blockquote>
...<br>
<blockquote cite="mide3ecf0$1kuo$1@digitaldaemon.com" type="cite">
  <pre wrap="">As I said, I agree with the idea: it's a very nice piece of syntactic
sugar.  The problem is with the syntax you've chosen.  One of D's
strengths is that the grammar is context-free, making it easy to implement.

But, without knowing anything about context, what does this mean:

        people[i]

Well, if "i" is an integer, then it's indexing the array.  If "i" is a
member of the elements of the people array, then it would be a
conditional expression.  But what if it's a member, and "i" is an
integer?  Is it a conditional or an index then?
  </pre>
</blockquote>
integer expresion refers always to the index.&nbsp; a
char[] expresion refers to a key (associative array), etc...<br>
<blockquote cite="mide3ecf0$1kuo$1@digitaldaemon.com" type="cite">
  <pre wrap="">And what if both are defined?
  </pre>
</blockquote>
class Person {<br>
&nbsp;&nbsp;&nbsp; public in i;&nbsp;&nbsp; <br>
}<br>
void main( ) {<br>
&nbsp;&nbsp;&nbsp; int i;<br>
&nbsp;&nbsp;&nbsp; Person p = new Person();<br>
<br>
&nbsp;&nbsp;&nbsp; with( p ) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; i = 5; // property of p<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; .i = 3; // dot signifies: one level out of this scope... the int
i declared one.<br>
&nbsp;&nbsp;&nbsp; }<br>
}<br>
<br>
then<br>
<br>
people[i] for member <br>
people[.i] for out of scope declared integer<br>
<br>
<blockquote cite="mide3ecf0$1kuo$1@digitaldaemon.com" type="cite">
  <pre wrap="">Even if the compiler can work out a way to distinguish this, the syntax
in its current form looks very hard for humans to parse in certain
fringe cases.

As you said, an alternative is "templateish" syntax:

        people![i]

I like this more, since it's *explicit* about what's going on.  That "!"
means "Hey, don't actually index the array; select elements of it only".
  </pre>
</blockquote>
Yes... I think explicit yntax is really more clean:: <b>you
convinced to me :-)</b><br>
<br>
Let's go with the new proposed syntax:<br>
<br>
<u><b>STEP 0</b>:&nbsp; drinking from oter sources... XPATH syntax...</u><br>
<br>
xmlNode.SelectNodes("tagNameA[conditionA]/tagNameB[conditionB]")...<br>
<ul>
  <li>"[condition]" signifies: evaluate this condition on left side
tagNode contents.</li>
</ul>
<ul>
  <li>When no condition is imposed XPath assumes "[true]";</li>
</ul>
then&nbsp; xmlNode.SelectNodes("<b>tagNameA/tagNameB[conditionB]</b>") is
equivalent to xmlNode.SelectNodes("<b>tagNameA[true]/tagNameB[conditionB]</b>")...<br>
<br>
<br>
<u><b>STEP 1</b>:&nbsp; lets propose something:</u><br>
<br>
The syntax used by the XPath D expression must be "autodefined", becuse
whe dont want to use the "xmlNode.SelectNodes( ... )" method :-p.&nbsp; One
solution is using specific <b>![Condition]</b> that defines "this is
an XPath condition"... <br>
.<br>
<br>
<b>AggregateExpression</b>![<b>condition</b>] signifies: evaluate the
condition on left side aggregated elements and build an aggregated
result with elements that passed condition (the result could be a
dynamic array)<br>
<br>
<u><b>STEP 2</b> : what to do with not aggregate expressions :-(</u><br>
<b><br>
ex:<br>
</b>Person[] youngGrandmothers =&nbsp; people![childs.length!=0].<b>mother![age&lt;36]</b><br>
<br>
<b>NotAggregateExpression</b>![<b>condition</b>] signifies: evaluate
the
condition on left side Element and build a dynamic result array with 0
or 1 elements (depending on the condition evaluation result).<br>
<br>
<u><b>STEP 3:</b> whe have to use ![] in all hierarchy node:</u><br>
ex: <br>
<blockquote>// whe can asume than <b>![] is equivalent to ![true]</b><br>
countries![population&gt;10000000].people![age&lt;3].mother![].mainHome![].rooms![windows&gt;2]&nbsp;
  <b></b><br>
</blockquote>
some exceptions: the last hierarchy node doesn't need to be followed by
the ![] in some cases:<br>
<ul>
  <li>When the node is a Method:<br>
  </li>
</ul>
<blockquote>
  <blockquote>ex:<br>
&nbsp;&nbsp;&nbsp; people![married].<b>doSomething();</b><br>
  </blockquote>
</blockquote>
<b></b>
<ul>
  <li>When the node is a property and it's on the left side of an
assignment </li>
</ul>
<blockquote>
  <blockquote>ex:<br>
&nbsp;&nbsp;&nbsp; people![married]<b>.name = "Peter";</b><br>
&nbsp;&nbsp;&nbsp; people![married]<b>.childs ~= new Person();</b><br>
&nbsp;&nbsp;&nbsp; people![birdtha=today]<b>.age++; </b>// This introduce an implicit
right side assignment property evaluation... I suppouse this is an
"exception" because compiler can solve this easily.<br>
  </blockquote>
</blockquote>
<br>
<u><b>STEP 4: </b>right side must be a member. </u><br>
<br>
Expression![condition].<b>member</b><br>
<b></b><br>
<u><b>STEP 5:</b> How compiler expands this expression.</u><br>
<br>
I suppouse Walter must decide between a preorder or inorder evaluation<br>
<ul>
  <li>preorder:&nbsp; first all parents, then their childs : <br>
  </li>
</ul>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; A![].B![].C![]<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; could be evaluated like this:<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; foreach(a in A)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; tmpA~=a;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; foreach(a in tmpA) foreach(b in a.B)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; tmpB~=b;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; foreach(b in tmpB) foreach(c in b.C)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; tmpC~=c<br>
<br>
<ul>
  <li>inorder: first parent, then their chids... when childs evaluated
next parent... and so on<br>
  </li>
</ul>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; A![].B![].C![]<br>
&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; could be evaluated like this<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; foreach(a in A)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; foreach(b in a.B)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; foreach (c in b.C)<br>
<br>
Well... I'm not an expert, but how hierarchy is evaluated is a compiler
work and programmer must be isolated about the compiler solution. <br>
<br>
We can assume than <b>result elements order can't be predicted</b>
(like realtional model).&nbsp; Results needs to be postprocessed (distinct,
sort, ...) if needed.<br>
<br>
<blockquote cite="mide3ecf0$1kuo$1@digitaldaemon.com" type="cite">
  <pre wrap="">At any rate, nice proposal, and I look forward to seeing something come
of it :)

  </pre>
</blockquote>
I agree... this is, basically, my dream:&nbsp; People writes constantly FOR
+ IF structures&nbsp; that can be easily expressed with this propossal.<br>
<blockquote cite="mide3ecf0$1kuo$1@digitaldaemon.com" type="cite">
  <pre wrap="">Oh, one other thing that suddenly occured to me: what if "people" isn't
an array?  You use 'foreach' in your expansions, but what if "people"
CAN be iterated over, but isn't an array in of itself?  Then the syntax
becomes downright misleading!
  </pre>
</blockquote>
D propose an standard implementation for "aggregate" classes... the
main goal now is to propose something D compatible:<br>
<ul>
  <li>Is there a standard I_Iterable interface?<br>
  </li>
  <li>foreach( ) recognizes this I_Iterable interface?</li>
  <li>Array acomplish with the I_Iterable interface?</li>
</ul>
I_Iterable is not part of D programming Language.... and this is
another discussion :-):<br>
<ul>
  <li>It could be perfect some standard Interfaces recognized by the
compiler, like c# foreach or using staments (IIterable and IDisposable
interfaces).<br>
  </li>
</ul>
<blockquote cite="mide3ecf0$1kuo$1@digitaldaemon.com" type="cite">
  <pre wrap="">P.S.  Your English is better than many people I've seen who don't know
any other languages.  Also, that upside-down "?" is nifty :)
  </pre>
</blockquote>
Spanish sintax :-).&nbsp; thanks a lot<br>
Antonio<br>
<br>
</body>
</html>