Wednesday, November 18, 2009

Learning Curl: {value expr} and Curl as an expression-based language

One thing that I have noticed in C# and Java programmers learning Curl is that if they rely on one of the available books (and even to some extent if they use the on-line Curl resources) there is a puzzle about {value some-expression} code blocks.

Here is an example from a book on Curl:
{value 2fortnights + 1day}
This an example of a Curl expression in which quantities are added (note the optional use of the plural for the user-defined quantity.)

{curl 7.0 applet}
{let public constant fortnight:Type = {type-of 14days}}
time in seconds is {value 2fortnights + 1day}
 
In keeping with the Gentle Slope approach to reduce the steepness of the Curl learning-curve, the text
time in seconds is
appears in the browser as text.
We say that this bit of text is at the top-level.
What follows, however, is an expression within curly braces and what we want to display is the result of that addition of the two Time quantities. We could have written this expression using optional parentheses as
{value (2fortnights + 1day) }
The {value } macro has been used to return a value: that is all.
To show that this is so, consider this alternative:
{String (2fortnights + 1day) }
The default constructor for the String class also returns a value (an instance of a String.)
Here is another alternative using assignment to a variable named tos:

{let tos:Time = 2fortnights + 1day}
The Time value held in the variable is {String tos}

And finally a complete alternative applet:

{curl 7.0 applet}
{let public constant fortnight:Type = {type-of 14days}}
{let tos:Time = 2fortnights + 1day}

The time in seconds equals {value 2fortnights + 1day}

Time quantity in the variable is {String tos}

Number of days: {format "%.0f", (tos / 1day)}

which displays in the browser as follows:

The time in seconds equals 2.5056e+006s

Time quantity in the variable is 2.5056e+006s

Number of days: 29

A more compact version of the applet using explicit {br} line formatting rather than relying on Curl to display the extra new lines might have been:

{curl 7.0 applet}
{let public constant fortnight:Type = {type-of 14days}}
{let tos:Time = 2fortnights + 1day}
The time in seconds equals {value 2fortnights + 1day} {br}
Time quantity in the variable is {String tos} {br}
Number of days: {format "%.0f", (tos / 1day)}

And so we proceed to wend our way up the 'Gentle Slope' of Curl.

Wednesday, November 4, 2009

What's new in what was once Borland Turbo Prolog?

PDC Visual Prolog has a page on what's new in 7.2

What stood out for me was anonymous predicates or "nameless clauses" as the Prolog response to "anonymous functions".

If you are interested in Tokyo Cabinet, you might want to glance back at PDC over the years and their features offering internal and external databases.  While I have been more excited about XSB and Logtalk in recent years, I have always enjoyed working in PDC.

There is something of an equivalent PROLOG in the Mercury project: both are distinctive in having a type system and in how they track determinism.  Both PDC and Mercury would like to appeal to programmers with a hankering for a functional style.

There are many active Prolog projects: the SWI-Prolog project is likely the most active in opensource and offers RDF parsing - somewhat different from that offered by XSB.

It is odd that with all the interest in Joe Armstrong and Erlang that there seems to be no up-tick in interest in Prolog and Constraint Logic Programming: the acquisition of ILog by IBM and the move of Drools into JBoss seem not to float any other boats.

Like Prologia (Prolog IV) in France, PDC now focuses on their software application offerings and not the language - but you wonder what would have happened if Apple or Microsoft had offered a Prolog to compete with Borland back in the late 80's ... but you could say the same of Smalltalk (in fairness, Apple's Objective-C is like Smalltalk and for some time Apple was home to some Smalltalk researchers.)  At least PROLOG never suffered the fate of Self and Strongtalk at the hands of SUN.

PDC was an early advocate of DSL's (Domain Specific Languages) but I do not know if these feature prominently in their own commercial packages.

Meanwhile, over at Strawberry Prolog a Windows prolog has been in a Beta for version 3.0 for almost a year: it was to contain a major innovation in the design of Prolog compilers, but I am still back at 2.9.2

If you like Eclipse, you might like AMZI Prolog 8 which comes as an Eclipse environment.  Amzi! is a pleasure to use and has great documentation if you have been away from logic programming for awhile.  But there are other options for Prologs which interface with Java and many "small" prolog interpreters about. 

One way to glimpse which Prolog implementations are active is to see which are supported by Logtalk - but that would exclude some of those which come with their own OOP frameworks .. such as PDC.

For other recent changes in PROLOG, see xsb.com and XSB at sourceforge.

If you are tracking any other PROLOG innovations, please add a comment and a link.  I have a note on Distributed Oz 1.4.0 elsewhere ...