• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Functional Programming Languages

Whoever named them "functional" is a retard or it's a sick joke - just search for my ranks in Technical, look for XSLT / XPATH keyrods :mad

Your whining about XSLT was based on your failure to understand how to use it as a declarative language (along with a failure to grasp that XML requires proper nesting of start and end tags).

JavaScript has been in active use as a functional language since 1996, and is one of the most widely-used languages in the world today, so it's a bit late to be talking about them as the next big thing.
 
JavaScript has been in active use as a functional language

I don't have problems with JavaScript - it is certainly NOT a functional language of the likes of Lisp/XSLT and thank God for that!

XSLT (and anything like it) was designed by people either high up in academia or high on drugs, most likely both - you can't fking use "variable" keyword to define a constant that can't change value, it's not a fking variable! :mad
 
XSLT (and anything like it) was designed by people either high up in academia or high on drugs, most likely both - you can't fking use "variable" keyword to define a constant that can't change value, it's not a fking variable! :mad

It's a variable in a mathematical sense. You can change the value of a variable (to be more precise, you can shadow a variable by creating a new binding over a value in the current scope). For example, the following stylesheet:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    
    <xsl:output method="text"/>
    
    <xsl:variable name="currentValue">No value</xsl:variable>
    
    <xsl:template match="values">
        <xsl:text>Global value of $currentValue is </xsl:text>
        <xsl:value-of select="$currentValue"/>
        <xsl:text>
        </xsl:text>
        <xsl:apply-templates select="value"/>
    </xsl:template>
    
    <xsl:template match="value">
        <xsl:variable name="currentValue" select="text()"/>
        <xsl:text>Current value of $currentValue is </xsl:text>
        <xsl:value-of select="$currentValue"/>
        <xsl:text>
        </xsl:text>
    </xsl:template>
    
</xsl:stylesheet>

given the following input:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<values>
    <value>Foo</value>
    <value>Bar</value>
    <value>AtW</value>
</values>

will produce the following output:

Code:
Global value of $currentValue is No value
Current value of $currentValue is Foo
Current value of $currentValue is Bar
Current value of $currentValue is AtW

As I always say to people who struggle because they attempt to apply imperative programming techniques to declarative languages: work with the grain, not against it. It's a different paradigm. Most of the things you know from the world of imperative languages are specific to that world, and won't help you.

Some people even think <xsl:for-each> is a looping construct, FFS :rolleyes:
 
Some people even think <xsl:for-each> is a looping construct, FFS :rolleyes:

And it isn't? :mad

All I wanted to do with this tulipy XSLT is to loop through some data and do some aggregations! :tantrum:

And don't give me that XPath tulip about doing sums in calls - that wasn't working in .NET - the whole thing is a load of tosh! :mad
 
It's a variable in a mathematical sense.

:suicide:

I don't a problem with some crackpot PhDs wasting their grants on developing some crackpot ideas - that's fine by me. It's also fine by me to have "programming" language of the kind they developed.

What's not ****ing fine is the words they've chosen to describe it, specifically "functional" - I could ****ing do simple tasks with it, just how ****ing functional is that?!?! :mad

Those "variables" also named in such a way that I feel the urge to lodge a complaints to Advertising Standards Authority as I feel been grossly mislead! :mad
 
But if you want your code to parallelize easily, your going to have to get with the crackpot PhD stuff. ;)
 
And it isn't? :mad

All I wanted to do with this tulipy XSLT is to loop through some data and do some aggregations! :tantrum:

And don't give me that XPath tulip about doing sums in calls - that wasn't working in .NET - the whole thing is a load of tosh! :mad

Of course not. Looping allows side effects, and side effects cause bugs.

Surely <xsl:value-of select="sum(element/@value)"/> isn't that hard? Look, like this stylesheet:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:output method="text"/>
    
    <xsl:template match="elements">
        <xsl:text>Sum of element values is </xsl:text>
        <xsl:value-of select="sum(element/@value)"/>
    </xsl:template>

</xsl:stylesheet>

applied to this input:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<elements>
    <element value="1"/>
    <element value="2"/>
    <element value="3"/>
    <element value="4"/>
    <element value="5"/>
    <element value="6"/>
</elements>

giving this output:

Code:
Sum of element values is 21

See, it's easy :)
 

Advertisers

Back
Top