Lasso Soft Inc. > Home

  • Articles

Parentheses Syntax

The tip of the week for December 7, 2007 discusses Parentheses syntax in Lasso. Parentheses syntax was introduced in Lasso 8 as an alternative to Lasso's traditional Colon syntax. The tip includes an overview of parentheses syntax, some justifications for introducing this new syntax method, and a discussion of parentheses syntax examples in the documentation.


Lasso 8.5 includes support for two separate syntax styles which can be mixed and matched in your Lasso files. If you have been using Lasso for many years then it is important to know about these alternatives so that you won't be surprised by code written in different syntax styles. If you are new to Lasso then you might want to consider adopting parentheses syntax as your default for code moving forward.

This tip includes several examples of parentheses syntax, a short discussion of why parentheses syntax is important, and some notes about how parentheses syntax will be used in Lasso's documentation.

A previous tip of the week (published three years ago) introduced parentheses syntax and also includes a good discussion of colon syntax.

Parentheses Syntax

In parentheses syntax the parameters of each tag are written within parentheses following the tag name. If you program in JavaScript then this format will look familiar. The use of delimiters or square brackets is the same no matter what syntax style is being used. Similarly, math and string expressions and parameter styles are the same regardless of syntax style.



Here are some examples of how various tag calls look in parentheses syntax.

    If($type == 'text');

 [String(34) + String(56)]
  [Inline(-Search, -Database='reference', -Table='tags')]
      [Field('tag_name')] - [Field('tag_category')]<br />


One important thing to note about parentheses syntax is that it can be mixed and matched with colon syntax, even within the same tag call. The following call uses colon syntax for the main tag, but parentheses syntax within the array member tag call.

  Fail_If: $myarray->Get(1) == '', -1, 'Unknown Error';


If you want to transition to parentheses syntax you can do so in new projects without worrying about recoding old projects. Also, you don't need to worry about occasionally using colon syntax or copying and pasting old code since either syntax will work fine.


Parentheses syntax was introduced for three important reasons.

Consistency - Parentheses syntax allow a consistent syntax to be used whenever a tag is called. Colon syntax requires parentheses in certain circumstances, but not in others. An example will show how colon syntax can be confusing.

What is the result of the following tag call?

 Math_Add: 1, 2, Math_Sub: 3, 4;


One might imagine that this call would return the value of the expression (1 + 2 + (3 - 4)) = 2, but it actually returns (1 + 2 + 3 + 4) = 10. The [Math_Add] tag can be described as "greedy". It claims all of the parameters that are available to it and leaves only one parameter, 3, for [Math_Sub]. Adding parentheses makes it clear how Lasso assigns the parameters to the tags.

  Math_Add: 1, 2, (Math_Sub: 3), 4;


Or, we can move the parentheses to make the tag call correspond to the expression we want to calculate. Now the result is 2 as we originally guessed.

  Math_Add: 1, 2, (Math_Sub: 3, 4);


How does the same expression look in parentheses syntax?

  Math_Add(1, 2, Math_Sub(3, 4));


Here there is no chance of our misunderstanding how the parameters are going to be assigned to the tags. The parentheses are required and make the grouping absolutely clear.

This consistency helps you write better code since the possibility of misunderstanding Lasso's parser has been removed. If you adopt this syntax then you are guaranteed that the parentheses are always in the right place. This can help prevent subtle syntax errors which are very difficult to debug.

Industry Standard - C is one of the most popular programming languages and has been influential on most languages which have come since. Languages like Java, JavaScript, Perl, Python, and others all use a variation of parentheses syntax for their function (tag) calls. Lasso's colon syntax can present a stumbling block to programmers who are already familiar with other languages.

Parentheses syntax was one of the most frequently requested features in Lasso because it allows programmers to move among the different languages that they need to support more easily. Other elements of Lasso also present challenges to a new user who is already familiar with other languages. But, it seems the use of parentheses is much more part of the muscle memory of programmers than the names of functions, parameters, etc. which always differ from project to project. Of course, this goes both ways since Lasso users have programmed colon syntax into their muscle memory.

Parser - Lasso reads in your Lasso pages, finds the LassoScript within them, compiles the LassoScript to byte code, and then executes the byte code. The parser is responsible for translating LassoScript into byte code and is one of the most important components of Lasso.

LassoSoft is currently working on future versions of Lasso which will have a significantly streamlined parser. This will allow Lasso to see a significant speed improvement on every page it processes. Parentheses syntax is one of the keys to this speed improvement since its consistency is not only easier for programmers, but much easier for the parser to understand.

Colon syntax will be supported in future versions of Lasso for backward compatibility, but parentheses syntax will likely provide better performance.

Documentation Notes

LassoSoft is going to adopt parentheses syntax for most documentation projects from here on out including future tips of the week. Most of the existing documentation uses colon syntax so we want to introduce more examples which use parentheses syntax in order to familiarize Lasso users with the alternatives.

LassoSoft is also working on methods of modifying the online Lasso Reference so that it can be seen in either colon syntax or parentheses syntax.

There is no plan to do a wholesale edit of the PDF documentation since doing so would be guaranteed to introduce a number of errors into the code. Errors in the documentation can be particularly vexing to new users who aren't sure whether they are encountering errors in their uses of the code or if the error is in the example itself.

More Information

More information about all of the tags used in this tip of the week can be found in the Lasso 8.5 Language Guide or in the online Lasso Reference


Author: Fletcher Sandbeck
Created: 17 Dec 2007
Last Modified: 16 Mar 2011


No comments found
You must be logged in to comment.

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home



©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft