[honu] add string comparison. add test.xml file for linq example

This commit is contained in:
Jon Rafkind 2011-09-14 12:52:12 -06:00
parent 0790efd585
commit 18b18aaded
5 changed files with 38 additions and 0 deletions

View File

@ -37,6 +37,7 @@
[honu-map map]
[honu-flow \|]
[honu-dot |.|]
[honu-string=? string_equal]
[honu-cons ::]
[honu-and and] [honu-and &&]
[honu-or or] [honu-or \|\|]

View File

@ -170,6 +170,7 @@
(define-binary-operator honu-or 0.5 'left or)
(define-binary-operator honu-cons 0.1 'right cons)
(define-binary-operator honu-map 0.09 'left map)
(define-binary-operator honu-string=? 1 'left string=?)
(define-unary-operator honu-not 0.7 'left not)

View File

@ -22,8 +22,10 @@
null
null?
length
substring
(rename-out [honu-cond cond]
[null empty]
[string-length string_length]
[racket:empty? empty?]
[racket:first first]
[racket:rest rest]))

View File

@ -30,6 +30,10 @@ loadXml(file){
}
}
starts_with(start, what){
substring(what, 0, string_length(start)) string_equal start
}
var xml = loadXml("test.xml");
printf("xml ~a\n", xml);
printf("data: ~a\n", xml.getData());
@ -48,3 +52,11 @@ printf("addresses ~a\n", addresses);
for add in addresses do {
printf("name ~a address ~a\n", add.name, add.address);
}
printf("+++\n");
for xs in linq from foo in xml.Descendants("Table1")
where starts_with("x", foo.Element("familyName").Value())
select foo.Element("familyName").Value() do {
printf("only x: ~a\n", xs)
}
// printf("---\n");

View File

@ -0,0 +1,22 @@
<root>
<Table1>
<ID>3</ID>
<familyName>x1</familyName>
<address>xa</address>
</Table1>
<Table1>
<ID>4</ID>
<familyName>y1</familyName>
<address>ya</address>
</Table1>
<Table1>
<ID>5</ID>
<familyName>hub</familyName>
<address>away</address>
</Table1>
<Table1>
<ID>5</ID>
<familyName>xeno</familyName>
<address>banana</address>
</Table1>
</root>