XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
Re: [xml-dev] The beauty and power of declarative syntaxes and declarative programming languages

> This is a declaration of how an aircraft's altitude in feet relates to an altitude in meters.
>
> Observe that there are no moving parts. It just declares the relationship.
>
> At a glance you can determine whether the relationship is correct.
>
> This is declarative programming. You simply declare the relationships.


There is even more to it. Take for example the following:

 <xsl:function name="f:maxPrimeFactor" as="xs:integer">
   <xsl:param name="pNum" as="xs:integer"/>

   <xsl:sequence select=
    "if(f:isPrime($pNum))
       then $pNum
       else
         for $vEnd in xs:integer(floor(f:sqrt($pNum, 0.1E0))),
             $vDiv1 in (2 to $vEnd)[$pNum mod . = 0][1],
             $vDiv2 in $pNum idiv $vDiv1
           return
             max((f:maxPrimeFactor($vDiv1),f:maxPrimeFactor($vDiv2)))
    "/>
 </xsl:function>

The XPath expression specified in the <xsl:sequence> above is a
definition of "the maximum prime factor of a natural number".

Just enclose this definition in the <xsl:function> above and you get a
...  executable definition or executable specification.

The power of declarative programming is that you don't need to
calculate/build/execute  -- you already have done this by just
providing a definition.



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play




On Mon, Feb 2, 2009 at 5:26 AM, Costello, Roger L. <costello@mitre.org> wrote:
>
> Hi Folks,
>
> While reading a paper [1] by Dimitre Novatchev I gained a deeper insight and appreciation of the beauty and power of declarative syntaxes and declarative programming languages.
>
> Consider this XML:
>
>    <?xml version="1.0"?>
>    <aircraft>
>        <altitude units="feet">
>            12000
>        </altitude>
>    </aircraft>
>
> It is a declaration of an aircraft's altitude in feet.
>
> It is just a declaration. There are no moving parts, no "state" changes. It just declares what is.
>
> This is really nice. It's easy to understand and verify at a glance.
>
> XML is a declarative syntax.
>
>
> Imagine a parallel universe where altitudes are expressed in meters, not feet.
>
> We can declaratively express the relationship between the two universes:
>
>    $alt = the value of altitude in feet
>    <aircraft>
>        <altitude units="meters">
>            $alt * 0.3048
>        </altitude>
>    </aircraft>
>
> This is a declaration of how an aircraft's altitude in feet relates to an altitude in meters.
>
> Observe that there are no moving parts. It just declares the relationship.
>
> At a glance you can determine whether the relationship is correct.
>
> This is declarative programming. You simply declare the relationships.
>
> Contrast with non-declarative programming, where you write code to convert feet to meters. "Convert" implies moving parts and changes. Whenever there's movement, things become much more complex and difficult to understand and verify.
>
>
> XSLT is a declarative programming language.
>
> Rather than using my fictitious syntax, we can express the relationship using a standard XSLT syntax:
>
>    <xsl:variable name="alt" select="/aircraft/altitude" />
>    <aircraft>
>        <altitude units="meters">
>            <xsl:value-of select="$alt * 0.3048" />
>        </altitude>
>    </aircraft>
>
>
> Breaking away from the non-declarative style of programming is difficult, as that's the way we're taught in school. I can hear my professor: "A program is like a recipe, first do step 1, then step 2, and so forth." Declarative programming isn't like that at all. Declarative programming simply involves declaring relationships. This is beautiful and powerful!
>
> /Roger
>
> [1] Higher-Order Functional Programming with XSLT 2.0 and FXSL by Dimitre Novatchev
> http://www.idealliance.org/papers/extreme/proceedings/xslfo-pdf/2006/Novatchev01/EML2006Novatchev01.pdf
> _______________________________________________________________________
>
> XML-DEV is a publicly archived, unmoderated list hosted by OASIS
> to support XML implementation and development. To minimize
> spam in the archives, you must subscribe before posting.
>
> [Un]Subscribe/change address: http://www.oasis-open.org/mlmanage/
> Or unsubscribe: xml-dev-unsubscribe@lists.xml.org
> subscribe: xml-dev-subscribe@lists.xml.org
> List archive: http://lists.xml.org/archives/xml-dev/
> List Guidelines: http://www.oasis-open.org/maillists/guidelines.php
>
>


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS