Calendar

««Mar 2010»»
SMTWTFS
  123456
7
8
910111213
14151617181920
21222324252627
28293031

Alert Email

Get a short email alert whenever a new entry is published.

Confidential, secure it's piece of cake to keep uptodate.

Implicit Array/Struct Creation and new Operators

Published: 2:01 PM GMT, Friday, 29 January 2010

Today sees the release of some much awaited support for both implicit array/struct creation and a whole host of operators. The cfscript and expression parsing engines have been rewritten, switching from the javacc based parsers to a cleaner and leaner ANTLR based one.

Implicit Array/Struct Creation

For those unfamiliar with the concept of implicit array/struct creation, here's some examples to whet your appetite as you wait for the latest OpenBD nightly build to download.

<!--- create an empty array --->
<cfset myarray = []>

<!--- create an array with 3 numeric elements --->
<cfset myarray = [1,2,3]>

<!--- create an array with mixed element types --->
<cfset myarray = [true,'andy',3]>

<!--- create an array of arrays --->
<cfset myArray = [[1,2],[3]]> 

<!--- create an empty struct --->
<cfset myStruct = {}>

<!--- create a struct with fields --->
<cfset myStruct = { name = "Andy", country = "Scotland" }>

<!--- create structs within a struct --->
<cfset myStruct={ a.c = 1, a.b.c = 3 }>

Those familiar with the JSON format will be pleased to see that we also support the following notation for creating structs:

<!--- create a struct with fields --->
<cfset myStruct = { name : "Andy", country : "Scotland" }>

Operators

You can now make use of all the following operators in your OpenBD apps.

  • Assignment: +=, -=, %=, /=, *=, &=
  • Unary Arithmetic: ++, --
  • Binary Arithmetic: %
  • Comparators (cfscript only): ==, !=, <, >,<=, >=
  • Logical: !, ||, &&

Here's an example of how you could make use of that:

<cfscript>
people = [ { name = 'Andy', country = 'Scotland' },
           { name = 'Matt', country = 'USA' },
           { name = 'Alan', country = 'Scotland' },
           { name = 'John', country = 'Australia' } ];

scottishCount = 0;
for ( i = 1; i < arraylen(people); i++ ){
  if ( people[i].country == 'Scotland' ){
    scottishCount++;
  }
}

</cfscript>

Try it out for yourself now in the nightly build of OpenBD.

Comments (2)

This really is a cool development. Can't wait for the final release!

left by Sameer . Wednesday, 3 February 2010 4:29 PM

Great stuff as always Matt. I especially like the JSON style support, configuration files are much leaner now. I am glad to see cfscript getting more attention, me being a big javascript fan.

left by Kevin Pepperman . Saturday, 30 January 2010 1:51 AM
Add Comment