Candle (programming language)

From Wikipedia, the free encyclopedia
Jump to: navigation, search
Candle
Paradigm(s) declarative, scripting, functional
Designed by Henry Luo
Developer Henry Luo
Appeared in 2005
Typing discipline dynamic, strong
Influenced by XQuery, XSLT, RELAX NG
OS Cross-platform
License Mozilla Public License v1.1
Website candlescript.org

Candle (Common ApplicatioN Development LanguagE) is a high-level general-purpose scripting language for both desktop and Internet applications. It unifies the core features of many XML related technologies like XQuery, XSLT, RELAX NG. Its first public beta release[1] was on 12 Oct 2005. And the planned formal release is in Mar 2012.[2]

Candle Markup[edit]

Candle Markup is a subset of the Candle language that is used as a document format for static data. The syntax of Candle Markup is designed based on XML. And it also supports an object notation similar to JavaFX object notation. Below is an example of an object in 3 notations:

Candle Element Notation Candle Object Notation Similar JavaFX Literal Object[3]
<Customer
  firstName = "John"
  lastName = "Doe"
  phoneNum = "9555-0101"
  address = <Address
    street = "1 Main Street"
    city = "Santa Clara"
    state = "CA"
    zip = "95050" />
    >
  "a text node"
</Customer>
Customer {
  firstName = "John"
  lastName = "Doe"
  phoneNum = "9555-0101"
  address = Address {
    street = "1 Main Street"
    city = "Santa Clara"
    state = "CA"
    zip = "95050"
  }
  "a text node"
}
Customer {
  firstName: "John";
  lastName: "Doe";
  phoneNum: "9555-0101";
  address: Address {
    street: "1 Main Street";
    city: "Santa Clara";
    state: "CA";
    zip: "95050";
  }
  /* text node not supported*/
}

The major advantages of Candle over XML are:

whitespace non-ambiguity
in XML, the whitespaces between the elements can be ambiguous as whether they are text nodes or just pure formatting whitespaces that can be ignored. Candle requires text nodes to be explicitly quoted, thus cleanly solves the problem.
cleaner namespace syntax
Candle supports a hierarchical namespace similar to Java. A fully expanded Qname in Candle looks like ns:domain:foo:bar.
strongly typed literal values
Candle uses unique syntax to denote the type of a literal value. Thus Candle is always strongly typed, whereas XML is only weakly typed without schema.
complex attribute content
attributes in Candle can accept complex content like an element.

Candle Script[edit]

Some of the distinctive features of Candle are:

  • Candle unifies XML markup data model with OOP object data model. In Candle, an attribute can have complex content like element. And an object can have child nodes like an element.
  • Candle unifies XQuery and XSLT as one coherent query language for hierarchical data processing.
  • Candle defines a pattern language which cleanly unifies several pattern-related DSLs (including RegEx, RELAX NG, EBNF, XQuery Sequence Type). It can easily match on sequence of items, nodes and characters.
  • Candle's action model is based on a mechanism called separation-of-side-effects, which is conceptually similar to command-query separation.[4] In Candle, routines are divided into functions and methods. Functions are routines without side-effects and methods are routines with side-effects. The rule of separation-of-side-effects is that methods can call functions, but not vice versa. In this way, pure functional islands are well-preserved in the sea of procedural program.

Sample code[edit]

Here's an example of Candle script generating the lyrics of the song '99 Bottles of Beer':

<?csp1.0?>
function nil:bottles($n as integer) {
   if ($n == 1) { "1 bottle" }
   else if ($n == 0) { "no more bottles" }
   else { {$n + " bottles"} }
}

template <song> {
   <html>
      <body>
         <h1>"Lyrics of the song " {@title?string}</h1>
         apply;
      </body>
   </html>
}

template <verse> {
   <p> apply; </p>
}

template <line> {
   apply; <br/>
}

function main() {
   apply to
   <song title="99 Bottles of Beer">
      for $b in reverse(0 to 99) {
         <verse>
            <line>{replace(nil:bottles($b), "n", "N")} " of beer on the wall, " nil:bottles($b); " of beer."</line> 
         if ($b != 0) {
            <line>"Take one down and pass it around, " nil:bottles($b - 1); " of beer on the wall."</line>
         } else {
            <line>"Go to the store and buy some more, 99 bottles of beer on the wall."</line>
         }
         </verse>
      }
   </song>;
}

Candle Runtime[edit]

Candle runtime currently runs on Windows and Linux (Ubuntu). The runtime is very lightweight, being only 2MB compressed.

The runtime can run in 3 modes: command line mode, desktop GUI mode or web server mode.

References[edit]

Further reading[edit]

External links[edit]