Commit 909f2714 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2005-04-20 22:23:42 by beppe] Empty log message

Original author: beppe
Date: 2005-04-20 22:23:42+00:00
parent 3ae1721f
USER MANUAL
===========
Add a table with complete syntax of type and patterns.
Add a table with complete syntax of type and patterns at the end of the
chapter on types and patterns.
Add syntactic sugar of references (pag 12)
Define exactly @ at page 10
TUTORIAL
========
- update syntax for new elements DONE PLEASE CHECK
- DONE PLEASE CHECK: update syntax for new elements
- explain syntax (x:? t) and why it is better for load xml in page 5
- finish the sections on patterns and references
- rewrite section on queries
ALL
===
......
......@@ -358,17 +358,29 @@ is equivalent to <code>[ x::Int* _* ]</code>.
</p>
<p>
If it possible in some circumstances to use the <code>@</code>
It possible to use the <code>@</code>
operator (sequence concatenation) on types, including in recursive
definitions. E.g.:
</p>
<sample><![CDATA[
type t = [ <a>(t @ t) ? ] (* [s?] where s=<a>[ s? s? ] *)
type x = [ Int* ]
type y = x @ [ Char* ] (* [ Int* Char* ] *)
type t = [Int] @ t | [] (* [ Int* ] *)
]]></sample>
<p>
however when used in recursive definitions <code>@</code> but be right linear so for instance the following definition are not allowed:
</p>
<sample><![CDATA[
type t = t @ [Int] | [] (* ERROR: Ill-formed concatenation loop *)
type t = t @ t (* ERROR: Ill-formed concatenation loop *)
]]></sample>
</section>
</box>
......@@ -600,4 +612,14 @@ to denote the OCaml abstract type <code>t</code>.
</p>
</box>
<box title="Complete syntax" link="syntax">
<p>
Below we give the complete syntax of type and pattern, the former
being patterns without capture variables
</p>
<p>
<b style="color:#FF0080">TO BE DONE</b>
</p>
</box>
</page>
......@@ -76,8 +76,8 @@ fun ( x :[Any*]):[t*] =
fun (e : [Any*]):[ T*] =
let f( accu :[T*] , x :[Any*]):[T*] =
match x with
[ h&T&<_>(k&[Any*]) ;t] -> f( accu@[h], k@t)
| [ <_>(k&[Any*]) ;t] -> f( accu, k@t)
[ h&T&<_ ..>(k&[Any*]) ;t] -> f( accu@[h], k@t)
| [ <_ ..>(k&[Any*]) ;t] -> f( accu, k@t)
| [ h&T ;t] -> f( accu@[h], t)
| [ _ ;t] -> f( accu, t)
| [] -> accu
......@@ -85,9 +85,9 @@ fun (e : [Any*]):[ T*] =
]]></sample>
<p>Note that this implementation may generate empty branch warnings in particular</p>
<ul>
<li>for the first branch if <code>T&amp;&lt;_>(k&amp;[Any*])</code> is <code>Empty</code></li>
<li>for the second branch if <code>&lt;_>(k&amp;[Any*])</code> is smaller than <code>T&amp;&lt;_>(k&amp;[Any*])</code></li>
<li>for the first branch if <code>t</code> is smaller than <code>&lt;_>(k&amp;[Any*])</code></li>
<li>for the first branch if <code>T&amp;&lt;_ ..>(k&amp;[Any*])</code> is <code>Empty</code></li>
<li>for the second branch if <code>&lt;_ ..>(k&amp;[Any*])</code> is smaller than <code>T&amp;&lt;_>(k&amp;[Any*])</code></li>
<li>for the first branch if <code>t</code> is smaller than <code>&lt;_ ..>(k&amp;[Any*])</code></li>
</ul>
</section>
......
......@@ -56,9 +56,9 @@ particular we allow the programmer to omit the surrounding <code>{{(` )}}</code>
when <code>%%expr1%%</code> is an atom, and to omit the surrounding <code>{{{ }
}}</code> and the infix semicolons <code>{{;}}</code> when
<code>%%expr2%%</code> is a record value. This is why we can write
<code>&lt;table align="center" valign="top">[</code>...<code>]</code>, rather than
<code>&lt;table align="center" valign="top">[ </code>...<code> ]</code>, rather than
<code>&lt;$$(`$$table$$)$$ $$({$$align="center"$$;$$ valign="top"$$})$$
>[</code>...<code>]</code>
>[ </code>...<code> ]</code>
</p>
<p> While these abbreviations are quite handy, they demand some care when used in record patterns. As we said, the general form of a record pattern is:
......@@ -148,9 +148,9 @@ As an example to summarize what we said above, consider the the elements
transitional XHTML these elements can have an attribute <code>bgcolor</code>
which is deprecated since in strict XHTML the background color must be specified
by the <code>style</code> attribute. So for instance <code>&lt;table
bgcolor="#ffff00" style="font-family:Arial"></code><i>some_content</i><code></code>
bgcolor="#ffff00" style="font-family:Arial"></code>...
must be rewritten as <code>&lt;table style="bgcolor:#ffff00;
font-family:Arial"></code><i>some_content</i><code></code> to be XHTML strict compliant. Here is a function
font-family:Arial"></code>... to be XHTML strict compliant. Here is a function
that does this transformation on a very simplified version of possibly nested
tables containing strings.
</p>
......@@ -331,11 +331,11 @@ string <code>"no contact"</code>:
</p>
<sample><![CDATA[
let preferred_contact(Person -> String)
<_>[ _ _ ( _*? <tel kind="work">x) | (_* <email>x) | <tel>x ] -> x
<_>[ _ _ ( _*? <tel kind="work">x) | (_* <email>x) | <tel ..>x ] -> x
| _ -> "no contact"
]]></sample>
<p>
(note that <code>&lt;tel>x</code> does not need to be preceded by any wildcard pattern as it is
(note that <code>&lt;tel ..>x</code> does not need to be preceded by any wildcard pattern as it is
the only possible remaining case).
</p>
</box>
......
......@@ -13,6 +13,11 @@ test it on the <a href="cgi-bin/cduce">online interpreter</a>.
<box title="Select from where" link="sel">
<b style="color:#FF0080">WE SHOULD REWRITE THIS SECSION TO
GET READY OF THE MANY TYPE DEFINITIONS. JUST USE THE ONE
OF USE CASES</b>
<p>
CDuce is endowed with a <code>select_from_where</code> syntax to perform some SQL-like queries. The general form of select expressions is
</p>
......@@ -50,10 +55,10 @@ transform %%e1%% with %%p1%% ->
<p>
They are syntactic sugar for :</p>
<sample> <![CDATA[flatten(select x from <_>[(x::t | _ )*] in e)]]> </sample>
<sample> <![CDATA[flatten(select x from <_ ..>[(x::t | _ )*] in e)]]> </sample>
<p> and </p>
<sample><![CDATA[
select x from <_ a=x>_ in e]]>
select x from <_ a=x ..>_ in e]]>
</sample>
</box>
......@@ -303,7 +308,8 @@ We first give the corresponding CDuce types. We leave the user in charge of cre
<sample><![CDATA[
type Bib = <bib>[Book*]
type Book = <book year=String>[Title (Author+ | Editor+ ) Publisher Price]
type Book = <book year=String id=?String>[
Title (Author+ | Editor+ ) Publisher Price]
type Author = <author>[Last First]
type Editor = <editor>[Last First Affiliation]
type Title = <title>[PCDATA]
......@@ -360,7 +366,7 @@ This version of the query is very efficient. Be aware of patterns.
<books-with-prices>
select <book-with-price>[t2 <price-amazon>p2 <price-bn>p1]
from <bib>[b::Book*] in [biblio],
<book>[t1&Title _* <price>p1] in b,
<book ..>[t1&Title _* <price>p1] in b,
<reviews>[e::Entry*] in [amazon],
<entry>[t2&Title <price>p2 ;_] in e
where t1=t2
......@@ -390,7 +396,7 @@ If one wants to write more explicitly:
</p>
<sample><![CDATA[
select <book (a)> x
from <book (a)>[ (x::(<(_\`editor)>_)|_ )* ] in bib
from <book (a)>[ (x::(<(_\`editor) ..>_)|_ )* ] in bib
]]>
</sample>
<p>Back to the first one:</p>
......@@ -402,12 +408,13 @@ If one wants to write more explicitly:
</sample>
<p>
This query takes any element in bib, tranforms it in a book element and
removes sub-elements editor (but you will get a warning as capture variable book in the from is never used.
removes sub-elements editor, but you will get a warning as capture variable <code>book</code> in the <code>from</code> is never used: we should have written <code>&lt;(_) (a)></code> instead of <code>&lt;(book) (a)></code>
the from
</p>
<sample><![CDATA[
select <(book) (a)> x
from <(book) (a)>[ (x::(Any\Editor)|_ )* ] in bib
]]
]]>
</sample>
<p> Same thing but without tranforming tag to "book".
More interestingly:</p>
......@@ -424,13 +431,13 @@ More interestingly:</p>
from <(b) (a)>[ (x::(Any\Editor)|_ )* ] in bib
]]>
</sample>
<p>Changes attribute id=x into bing=x
However, one must be shure that each element in bib has an "id" attribute
if such is not the case the expression is ill-typed. If one wants to perform this only for those elements which certainly have an "id" attribute then:
<p>Changes attribute <code>id=x</code> into <code>bing=x</code>
However, one must be sure that each element in <code>bib</code> has an <code>id</code> attribute
if such is not the case the expression is ill-typed. If one wants to perform this only for those elements which certainly have an <code>id</code> attribute then:
</p>
<sample><![CDATA[
select <(b) (a\id+{bing=a.id})> x
from <(b) (a&{id=_}))>[ (x::(Any\Editor)|_ )* ] in bib
from <(b) (a&{id=_ ..}))>[ (x::(Any\Editor)|_ )* ] in bib
]]>
</sample>
</section>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment