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] RE: Declarative programming requires a different mindset

To me (and please explain why I'm wrong)
Saying that Declarative Programming languages dont "tell the computer what to do" is misleading, or outright false.
Even in languages like XQuery and XSLT ... There's few constructs that dont have some sense of operational instructions.
The literal element constructor in XQuery may come close where you simply enter what you want the output to be

But everything else, such as variable declarations, FLOWR expresions, recursion etc have some mannor of 'telling the computer what to do'.
Just not in as direct way as procedural/imperative programming.

Your example is a good one.  Your giving a "recipe" or "instructions" on 'how to do'  the substring-before-last ... operation.
Is this "purely declarative' ?   I dont know.
Does it matter ?

IMHO ... actual declarative languages like XQuery and XSLT (those are the ones I'm most familiar with) you still have to give the computer
directions on 'what to do' and quite a bit of 'how to do it'.   Just not quite so much on the 'how' part as imperative languages.
But I dont see it as quite black & white.   To me it seems somewhat fuzzy.

I'm not sure how one might express, purely declarative , a new operation built out of existing atoms without some kind of direction on how to get there from here.   Even purely 'rule based' languages still have the assumption that rules will be "evaluated" ...
Maybe there is some strict dividing line ... I'm not sure what it is.

For anything complex, In languages I know, you have to somehow give enough direction to the system to tell it how to do it.
How else ?  How would you write substring-before-last without giving directions on how to accomplish it or what it meant ?
Purely by example ? Inductive programming? But that may be really really difficult to make sure the examples you gave were good enough to express what you really mean.

Am I totally missing the boat here ?

David A. Lee

On 3/25/2010 7:32 AM, Costello, Roger L. wrote:
82B6502D-2598-489F-BA47-FB33D572D800@mimectl" type="cite">

Hi Folks,


Yesterday’s responses were outstanding and illuminating. Thank you.


I learned that a declarative program describes the relationship of the output to the input.


This raises new questions. Let’s take an example. Suppose that this is the input:




I want the output to contain the URL and the filename separated:







This XSLT code describes the relationship of the output to the input:


<xsl:template match="XML-file">

    <xsl:variable name="url"

                  select="f:substring-before-last(., '/')" />



            <xsl:value-of select="$url" />



            <xsl:value-of select="substring-after(., $url)" />





I believe this code is declarative. Do you agree?


Note my use of the function, f:substring-before-last(). There is no such built-in function, I created it. Below is how I implemented it. The implementation doesn’t seem descriptive. It seems quite recipe-like:


   Get the substring before $delimiter and output it,

   then output $delimiter, and then recurse.


It seems quite imperative. Do you agree?


If I stuff a bunch of imperative code into functions, and the “main” code is declarative, do I still have a declarative program?


Here’s my implementation of f:substring-before-last():


<xsl:function name="f:substring-before-last" as="xs:string?">

    <xsl:param name="string" as="xs:string" />

    <xsl:param name="delimiter" as="xs:string" />


    <xsl:if test="contains( $string, $delimiter )">

        <xsl:variable name="url">


               select="substring-before( $string, $delimiter )"/>

            <xsl:value-of select="$delimiter"/>



                        ( $string, $delimiter ), $delimiter)" />


        <xsl:value-of select="$url" />





[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