Developer story: Foreign data types (example with HTML)

Aaron Optimizer Digulla <[email protected]> Sun, 10 Aug 2003 14:01:53 +0200
Newsgroups gmane.comp.programming.pragmatic
Message-ID <[email protected]>
** The Problem --------------------------------------------------------

Many languages allow to create new data types (classes, typedefs, etc)
but they don't allow new semantics with them.

For example, I can't say:

    HTML div = <Div class="demo">
	<b>
	    This is some text.
	</b>
    </Div>;

or even improve on that syntax:

    HTML div = Div (
	class="demo",
	Bold ('Some text'),
    )

** Proposed Solution --------------------------------------------------

Pragmatic should allow to extend the compiler with new data types
and new syntax with new semantics. In the end, I should be able to
say things like this:

    HTMLFragment a = HTML (url="http://some.doma.in/path/to/document.html")//Div[@class == "demo"]

where "//Div[@class == "demo"]" is an XPath expression that selects
all Div elements which have the attribute "class" with the value
"demo".

The syntax extension should allow to change sematics without
any additional keywords. For example, when I have an XML file
which contain information about items in stock:

    <root>
	<item>
	    <name>CD-RW</name>
	    <count>5</count>
	<item>
    </root>

Then I want to be able to modify the count with this code:

    XML document = XML (url="stock.xml")

    // Does the item exist?
    XMLFragment select = document//item/name/[text() == 'CD-RW'];
    if select:
	// Find the count element of the selection,
	// convert it to int and decrement it
	select/../count -= 1
	

    // Rename "stock.xml" to "stock.xml.bak"
    // and save the document as "stock.xml".
    document.saveWithBackup ()

-- 
==============================================
Sowatec AG,       CH-8330 Pfäffikon (ZH)
Witzbergstr. 7,   http://www.sowatec.com
Tel: +41-(0)1-952 55 55
Fax: +41-(0)1-952 55 66
----------------------------------------------
Aaron "Optimizer" Digulla, [email protected]
==============================================

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/W4wwlB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
pragmatic_lang-unsubscribe-hHKSG33TihhbjbujkaE4pw@public.gmane.org

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/