Upgrading to Lasso 9 can be daunting for developers that have spent years developing in older versions of Lasso. Some have syntax habits that have carried through from Lasso 3.6 and earlier and will face challenges moving forward.
This article aims to provide some guidelines for identifying and updating code to modern Lasso 9 syntax.
However, it is important to note that while syntax methodology may be highlighted as undesirable in this article, the vast majority of your pre-Lasso 9 code will "just work" in Lasso 9. For a more detailed discription of the differences between Lasso 8 (and earlier) and Lasso 9 please see this afticle: Migration Guide: What has changed
Colon syntax has been replaced with bracket (a.k.a. parentheses) syntax and has been available since Lasso 8.5.
Generally speaking the brackets will visually group the syntax and will be easier to read once you are used to the change.
If you are running LassoLab, it's parser will report these colons as errors even though Lasso 9 might execute this code perfectly. This is an excellent method of spotting these colons and dealing with them accordingly. The LassoLab parser will also help ensure your bracket nesting is correct.
// Lasso 8 code: // ======================== var:'var1' = 100; loop:100; $var1 += 1; /loop; $var1; // Lasso 9 equivalent // ======================== var('var1' = 100) loop(100) $var1 += 1 /loop $var1
In all versions of Lasso prior to Lasso 9, semi-colons were required to separate statements within the same square bracket block or LassoScript block, regardless of line breaks.
In Lasso 9 the semi-colon is now effectively redundant as a statement delimiter. The only situation where a semi-colon would have benefit is where you wish to have statements in a single line with no line breaks.
// Lasso 8 code: // ======================== var('var1' = 100); loop(100); $var1 += 1; /loop; $var1; // Lasso 9 equivalent // - note the absence of semi-colons // ======================== var('var1' = 100) loop(100) $var1 += 1 /loop $var1
Containers in previous versions of Lasso were started with the name of the block and ended with the name preceeded by a slash.
For example, a [loop] container would look like this:
// Lasso 8 code: // ======================== loop(100); // some code here /loop;
Lasso 9 introduces the concept of "captures", and simplify the container concept. The above example can be written like so:
// Lasso 9 code: // ======================== loop(100) => { // some code here }
The great thing about {} captures is that most good code editors will be helpful by hiighlighting the beginning and end of the capture. Try it in LassoLab... in fact in LassoLab you can double-click one of the braces and it will select the whole block for you.
One really important thing to know about captures is that if you want to output something from within them, you have to use "auto-collect". The auto-collect caret "^" is placed inside the start and end of the capture which we wish to generate output from.
Lets see this in action: in the first loop block below, nothing will be output, however in the second we are including the carets "^" and the we get output.
// Lasso 9 code: // ======================== loop(10) => { // Without auto-collect, this will output nothing: loop_count + ', ' } loop(10) => {^ // With auto-collect, this will output as we expect: loop_count + ', ' ^} Output: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
Captures are a huge visual change to the way Lasso 9 code looks, however it's a change I strongly encourage you to embrace.
In Lasso 9 both locals and variables no longer need to be quoted while being declared. Have a look at the following syntax:
local('myLocal' = string) local(myLocal = string) var('myVar' = string) var(myVar = string)
Both of these are functionally equivalent, both of these are "correct". While it's not really of great benefit to omit quotes areound variable names, it is important to know that you don't need them as it quickly becomes a habit when you realize it's just another keystroke or two you don't need anymore!
Warning: In previous versions of Lasso variable names with spaces were tolerated, and while they're supported in Lasso 9 quotes are required. Support for spaces in variable names is actively discouraged and may be removed from future versions.
The following code is "valid", however the LassoLab parser will report the folloing code as a problem:
// valid Lasso 9 code by actively discouraged. local('my Local' = 'hello') local('my Local') outputs: "hello"
The use of semi-colons as statement delimiters in earlier versions allowed the practice of "implicit concatenation". This term means "if no semicolon was present then assume string concatenation".
Lets look at an example that would have output "There are 12 eggs in a dozen":
// Works in Lasso 8 local('x' = 'There are '(3*4)' eggs in a dozen'); // Correct code in Lasso 9 local(x = 'There are '+(3*4)+' eggs in a dozen')
Notice how the Lasso 8 code has omitted the + syntax out of convenience? In Lasso 9 this may cause problems. The irony is that this example will still work, but many other similar situations will not, and LassoLab will highlight this as a problem.
Any process with significant benefits usually comes with some amount of discomfort during the process. Think getting fit, weight loss, etc.
Spending the time time to learn the modern syntax options will increase the efficiency, readability and ability to maintain your code base moving forward. It doesn't take long to feel comfortable with the changes!
Author: Jonathan Guthrie
Created: 8 Jun 2012
Last Modified: 15 Jun 2012
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 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft