Lasso Soft Inc. > Home

  • Articles

Syntax Compatibility Between 8.5 and 9

Best practices to write Lasso 8.5 code that will work in Lasso 9

Goal of this page

Lassoscript syntax has evolved a lot in Lasso 9, but 8.5 syntax is still compatible, if you respect a few rules. The aim of this page is to list the best practices to use when writing Lasso 8.5 code so that it can be run without changes under the new lasso 9 server.

Here is a compilation of all beta testers on the L9 beta mailing list. It's not about deprecated tags, only syntax issues.

Use parens syntax rather than colons

Although Lasso 9 can understand the old colon syntax, in some cases it could get confused and output an error. De-colonize your code, now!

field('this')
// instead of
field:'this'

Always use + concatenation and not implicit concatenation

field('price')+'$'
// instead of
field('this')'$'

Do not use strings when a tag parameter expects an integer

Session_Start( -Name='cbs', -Expires='120'); //will fail
//instead use :
Session_Start( -Name='cbs', -Expires= 120 );

Avoid use of dynamic variable names in locals

Avoid using expressions to create local variables names like :

local('menu_'$lang)
//instead use a map like
var('map') = ('menu_en' = 'button', 'menu_fr' = 'bouton')

Please note that this limitation only applies to LOCAL( ) variables, you still can do this with VAR( ) variables.

In a protect/handle code, all handle blocks must be at the top of the protect block

protect;
handle();
/handle;
.... Then Rest of Code ....
/protect;

Referencing a var with @ does not work anymore

There is no solution here, the code has to be upgraded

Beware of the (:) shortcut

In Lasso 8.5 you could create an array using

var('test') = (:) ;
In Lasso 9 , this shortcut will create a staticarray type, which cannot grow dynamically

Testing a field or var against the empty string

This one can be tricky... If you are using the code below in 8.5 to check for either a field with an empty string or a field with a null value, it will only check for an empty string in 9:

if(field('someField') !='');

To get this to work in both 8.5 and 9, you should explicitly cast the field to a string prior to comparing it. This will leave an empty string as is and convert the null into an empty string. Better syntax :

if(string(field('someField')) != '');

nslookup difference

When a reverse lookup doesn't find anything, LP8 returns the IP address while L9 returns null.

Using array->join to make sum will not work

array(1,2,3)->join;

This kind of shortcut used to perform an addition integers in an array , in L9 it doesn't anymore. This will output 123 as expected from a concatenation method.

Looking for a param passed to a tag

define_tag('x');
return(params->find('-a')->size > 0);
/define_tag;

In LP8 you could search the built-in "params" map when inside a define_tag block by passing the name of the param with its hyphen. In L9, you'll have to remove the hyphen : params->find('-a') for this code to work

ForEach({...}) syntax will conflict with L9 brackets syntax

This one does not seem to have a workaround : { ... } is the main building block in L9, and this particular syntax in L8 will throw an error.

array(1,2,3)->foreach({
params->first *= 2;
return(true);
})&;
 

Article originally published on LassoTech.com

Author: Dominick Guiliano
Created: 12 Feb 2010
Last Modified: 16 Mar 2011

Comments

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