Lasso Coding Examples

classic Classic list List threaded Threaded
28 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Lasso Coding Examples

Viaduct Productions
Hi folks.  Since someone asked to have some examples whipped up, I  
have written a package for such perusal.

http://www.viaduct-productions.com/crudmaster/lep.zip

Any questions, please post here on the list.


Cheers

Rich in Toronto


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

detlef.hebbel
Thanks Rich.

> http://www.viaduct-productions.com/crudmaster/lep.zip

Immediately after browsing your examples I was able to add some  
improvements to my work.

Your examples shows me how and where to use certain kind of tags.

Detlef




On 8/02/2008, at 4:53 PM, Rich wrote:

> Hi folks.  Since someone asked to have some examples whipped up, I  
> have written a package for such perusal.
>
> http://www.viaduct-productions.com/crudmaster/lep.zip
>
> Any questions, please post here on the list.
>
>
> Cheers
>
> Rich in Toronto
>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Viaduct Productions
Glad it helped.

Unfortunately I won't be answering emails today, as I threw my back  
out shoveling snow.  Pain like I really don't need at the moment.

On Feb 7, 2008, at 11:08 PM, Detlef Hebbel wrote:

> Immediately after browsing your examples I was able to add some  
> improvements to my work.
>
> Your examples shows me how and where to use certain kind of tags.


Cheers

Rich in Toronto


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Jonathan Vanherpe (T & T NV)
In reply to this post by Viaduct Productions
Rich wrote:

> Hi folks.  Since someone asked to have some examples whipped up, I have
> written a package for such perusal.
>
> http://www.viaduct-productions.com/crudmaster/lep.zip
>
> Any questions, please post here on the list.
>
>
> Cheers
>
> Rich in Toronto

Thanks for the examples, Rich.

I've been looking over them to see if there was anything I could learn,
and I spotted a mistake in the contact form. It seems like your
validation code isn't really doing what you want it to do. It seems like
an e-mail will be sent if the e-mail address OR the comment text are
filled in, while both should normally be filled in.

I usually use an array with error messages for this, and only send out
the e-mail if the array is empty, something like this (there are
probably typo's and errors in this, I didn't test it, but you get the idea):

var('errormsg')=(:);
if(!valid_email(action_param('email')));
        $errormsg->insert('you didn\'t enter a valid address');
/if;

if(action_param('comment')=='');
        $errormsg->insert('you didn\'t give us a message');
/if;
if($errormsg->size==0);
        email_send(...);
else;
        $errormsg->join('<br />');
/if;

Jonathan

--
Jonathan Vanherpe - Tallieu & Tallieu NV - [hidden email]

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Viaduct Productions
Hi there.

It was an example to show how to interrupt incoming params before the  
meat of it is performed.  In these examples, none of the logic was  
focussed on.  I should add that to the docs.


On Feb 8, 2008, at 3:02 AM, Jonathan Vanherpe (T & T NV) wrote:

> Thanks for the examples, Rich.
>
> I've been looking over them to see if there was anything I could  
> learn, and I spotted a mistake in the contact form. It seems like  
> your validation code isn't really doing what you want it to do. It  
> seems like an e-mail will be sent if the e-mail address OR the  
> comment text are filled in, while both should normally be filled in.
>
> I usually use an array with error messages for this, and only send  
> out the e-mail if the array is empty, something like this (there  
> are probably typo's and errors in this, I didn't test it, but you  
> get the idea):


Cheers

Rich in Toronto


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Jonathan Vanherpe (T & T NV)
Rich wrote:
> Hi there.
>
> It was an example to show how to interrupt incoming params before the
> meat of it is performed.  In these examples, none of the logic was
> focussed on.  I should add that to the docs.
>
>

Hi Rich,

You said we are encouraged to discuss the examples, so that's what I'm
doing ;). I'm just curious how others handle the whole validation thing.
The examples you gave are pretty good, and I wished I had those when I
started out with Lasso.

Jonathan

--
Jonathan Vanherpe - Tallieu & Tallieu NV - [hidden email]

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Viaduct Productions
Hey sure.  Not a problem.  There are many ways people can handle  
validation.  Some of the questions in the docs help to make  
developers think about how to integrate such a two part solution, and  
how it can help with validation and repositioning back at the  
original form.  I don't want to give too much away, as I'm hoping it  
will come out in the discussions.

If there are more items needed to be coded, then I'd love to hear  
about them.

On Feb 8, 2008, at 3:25 AM, Jonathan Vanherpe (T & T NV) wrote:

> Hi Rich,
>
> You said we are encouraged to discuss the examples, so that's what  
> I'm doing ;). I'm just curious how others handle the whole  
> validation thing. The examples you gave are pretty good, and I  
> wished I had those when I started out with Lasso.


Cheers

Rich in Toronto


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Adam Randall-2
In reply to this post by Jonathan Vanherpe (T & T NV)
On Fri, 08 Feb 2008 09:02:53 +0100, Jonathan Vanherpe (T & T NV) wrote:

> Rich wrote:
>> Hi folks.  Since someone asked to have some examples whipped up, I
>> have written a package for such perusal.
>>
>> http://www.viaduct-productions.com/crudmaster/lep.zip
>>
>> Any questions, please post here on the list.
>>
>>
>> Cheers
>>
>> Rich in Toronto
>
> Thanks for the examples, Rich.
>
> I've been looking over them to see if there was anything I could
> learn, and I spotted a mistake in the contact form. It seems like
> your validation code isn't really doing what you want it to do. It
> seems like an e-mail will be sent if the e-mail address OR the
> comment text are filled in, while both should normally be filled in.
>
> I usually use an array with error messages for this, and only send
> out the e-mail if the array is empty, something like this (there are
> probably typo's and errors in this, I didn't test it, but you get the
> idea):
>
> var('errormsg')=(:);
> if(!valid_email(action_param('email')));
> $errormsg->insert('you didn\'t enter a valid address');
> /if;
>
> if(action_param('comment')=='');
> $errormsg->insert('you didn\'t give us a message');
> /if;
> if($errormsg->size==0);
> email_send(...);
> else;
> $errormsg->join('<br />');
> /if;

One line If statements as you have here, as well as one line if/else (each) statements, should be written like so:

var('errormsg')=(:);
!valid_email(action_param('email')) ?
        $errormsg->insert('you didn\'t enter a valid address');

action_param('comment')=='' ?
        $errormsg->insert('you didn\'t give us a message');

$errormsg->size==0 ?
        email_send(...) |
        $errormsg->join('<br />');

The above will execute faster, though the speed difference is likely very negligible.

Adam.

--
-----------------------------------------------------------------------
Adam Randall                                       http://www.xaren.net
[hidden email]                                   AIM/iChat:  blitz574

"Macintosh users are a special case. They care passionately about the
Mac OS and would rewire their own bodies to run on Mac OS X if such a
thing were possible." -- Peter H. Lewis

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Viaduct Productions
I prefer one line if statements (what are they called again?), but I  
thought I would keep them simple, and keep that example for another  
day.  I find traditional statements so bulky.  I'd like to test the  
speed of the two with about 5 or 6 options.

On Feb 8, 2008, at 3:31 AM, Adam Randall wrote:

> One line If statements as you have here, as well as one line if/
> else (each) statements, should be written like so:


Cheers

Rich in Toronto


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Jonathan Vanherpe (T & T NV)
In reply to this post by Adam Randall-2
Adam Randall wrote:

>
> One line If statements as you have here, as well as one line if/else (each) statements, should be written like so:
>
> var('errormsg')=(:);
> !valid_email(action_param('email')) ?
> $errormsg->insert('you didn\'t enter a valid address');
>
> action_param('comment')=='' ?
> $errormsg->insert('you didn\'t give us a message');
>
> $errormsg->size==0 ?
> email_send(...) |
> $errormsg->join('<br />');
>
> The above will execute faster, though the speed difference is likely very negligible.
>
> Adam.

I sometimes use ternary if's for short in-line things, but I prefer
using the if/else thing in the bigger code chunks because it's easier to
read. Code readability is important for me.

jonathan
--
Jonathan Vanherpe - Tallieu & Tallieu NV - [hidden email]

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Viaduct Productions
In reply to this post by Adam Randall-2
On Feb 8, 2008, at 3:31 AM, Adam Randall wrote:

> One line If statements as you have here, as well as one line if/
> else (each) statements, should be written like so:

Tested:

var('group' = array);
loop(500);
        $group->insert(math_random(-lower = 1, -upper = 6));
/loop;


var('myClock' = date_msec);
iterate($group, var('i'));
        $i == 1 ? var('alpha' = 'bravo');
        $i == 2 ? var('alpha' = 'bravo');
        $i == 3 ? var('alpha' = 'bravo');
        $i == 4 ? var('alpha' = 'bravo');
        $i == 5 ? var('alpha' = 'bravo');
        $i == 6 ? var('alpha' = 'bravo');
/iterate;
'Ternary: ' integer(date_msec - $myClock) ' ms<br/>';


$myClock = date_msec;
iterate($group, var('i'));
        if($i == 1);
                var('alpha' = 'bravo');
        else($i == 2);
                var('alpha' = 'bravo');
        else($i == 3);
                var('alpha' = 'bravo');
        else($i == 4);
                var('alpha' = 'bravo');
        else($i == 5);
                var('alpha' = 'bravo');
        else($i == 6);
                var('alpha' = 'bravo');
        /if;
/iterate;
'Expanded Conditional: ' integer(date_msec - $myClock) ' ms<br/>';



$myClock = date_msec;
iterate($group, var('i'));
        select(math_random(-lower = 1, -upper = 6));
                case(1);
                        var('alpha' = 'bravo');
                case(2);
                        var('alpha' = 'bravo');
                case(3);
                        var('alpha' = 'bravo');
                case(4);
                        var('alpha' = 'bravo');
                case(5);
                        var('alpha' = 'bravo');
                case(6);
                        var('alpha' = 'bravo');
        /select;
/iterate;
'Select Case: ' integer(date_msec - $myClock) ' ms<br/>';

// G5 1.8 LP 8.5.5 9 ms / 5 ms / 42 ms


Cheers

Rich in Toronto


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Wade Maxfield
Rich wrote:
> On Feb 8, 2008, at 3:31 AM, Adam Randall wrote:
>
>> One line If statements as you have here, as well as one line if/else
>> (each) statements, should be written like so:
>

[snip]

>
> $myClock = date_msec;
> iterate($group, var('i'));
>     select(math_random(-lower = 1, -upper = 6));
>         case(1);
>             var('alpha' = 'bravo');
>         case(2);
>             var('alpha' = 'bravo');
>         case(3);
>             var('alpha' = 'bravo');
>         case(4);
>             var('alpha' = 'bravo');
>         case(5);
>             var('alpha' = 'bravo');
>         case(6);
>             var('alpha' = 'bravo');
>     /select;
> /iterate;
> 'Select Case: ' integer(date_msec - $myClock) ' ms<br/>';
>
> // G5 1.8 LP 8.5.5 9 ms / 5 ms / 42 ms
>

The Select should be

iterate($group, var('i'));
     select($i);
         case(1);
             var('alpha' = 'bravo');

[snip]

Currently you're doing another 500 * math_random (leading to the extra
33-37ms compared to the other styles)

  - Wade

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Viaduct Productions

On Feb 8, 2008, at 4:09 AM, Wade Maxfield wrote:

>     select($i);

Noted.  Leftover code from a previous version.

var('group' = array);
loop(500);
        $group->insert(math_random(-lower = 1, -upper = 6));
/loop;


var('myClock' = date_msec);
iterate($group, var('i'));
        $i == 1 ? var('alpha' = 'bravo');
        $i == 2 ? var('alpha' = 'bravo');
        $i == 3 ? var('alpha' = 'bravo');
        $i == 4 ? var('alpha' = 'bravo');
        $i == 5 ? var('alpha' = 'bravo');
        $i == 6 ? var('alpha' = 'bravo');
/iterate;
'Ternary: ' integer(date_msec - $myClock) ' ms<br/>';


$myClock = date_msec;
iterate($group, var('i'));
        if($i == 1);
                var('alpha' = 'bravo');
        else($i == 2);
                var('alpha' = 'bravo');
        else($i == 3);
                var('alpha' = 'bravo');
        else($i == 4);
                var('alpha' = 'bravo');
        else($i == 5);
                var('alpha' = 'bravo');
        else($i == 6);
                var('alpha' = 'bravo');
        /if;
/iterate;
'Expanded Conditional: ' integer(date_msec - $myClock) ' ms<br/>';



$myClock = date_msec;
iterate($group, var('i'));
        select($i);
                case(1);
                        var('alpha' = 'bravo');
                case(2);
                        var('alpha' = 'bravo');
                case(3);
                        var('alpha' = 'bravo');
                case(4);
                        var('alpha' = 'bravo');
                case(5);
                        var('alpha' = 'bravo');
                case(6);
                        var('alpha' = 'bravo');
        /select;
/iterate;
'Select Case: ' integer(date_msec - $myClock) ' ms<br/>';

// G5 1.8 LP 8.5.5 10 ms / 5 ms / 6 ms

Cheers

Rich in Toronto


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Bil Corry-3
Rich wrote on 2/8/2008 3:14 AM:
> iterate($group, var('i'));
>     $i == 1 ? var('alpha' = 'bravo');
>     $i == 2 ? var('alpha' = 'bravo');
>     $i == 3 ? var('alpha' = 'bravo');
>     $i == 4 ? var('alpha' = 'bravo');
>     $i == 5 ? var('alpha' = 'bravo');
>     $i == 6 ? var('alpha' = 'bravo');
> /iterate;

This will run a smidge faster if coded like this:

iterate($group, var('i'));
    $i == 1 ? var('alpha' = 'bravo') |
    $i == 2 ? var('alpha' = 'bravo') |
    $i == 3 ? var('alpha' = 'bravo') |
    $i == 4 ? var('alpha' = 'bravo') |
    $i == 5 ? var('alpha' = 'bravo') |
    $i == 6 ? var('alpha' = 'bravo');
/iterate;


- Bil


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Viaduct Productions
OK, can you explain how that works?  I thought Ternary was restricted  
to test ? true | false;  I would love to expand on ternary.


On Feb 8, 2008, at 4:40 AM, Bil Corry wrote:

> iterate($group, var('i'));
>    $i == 1 ? var('alpha' = 'bravo') |
>    $i == 2 ? var('alpha' = 'bravo') |
>    $i == 3 ? var('alpha' = 'bravo') |
>    $i == 4 ? var('alpha' = 'bravo') |
>    $i == 5 ? var('alpha' = 'bravo') |
>    $i == 6 ? var('alpha' = 'bravo');
> /iterate;


Cheers

Rich in Toronto


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Johan Solve
See it as a chain of elses. Every | is an else.

On Feb 8, 2008 10:45 AM, Rich <[hidden email]> wrote:

> OK, can you explain how that works?  I thought Ternary was restricted
> to test ? true | false;  I would love to expand on ternary.
>
>
> On Feb 8, 2008, at 4:40 AM, Bil Corry wrote:
>
> > iterate($group, var('i'));
> >    $i == 1 ? var('alpha' = 'bravo') |
> >    $i == 2 ? var('alpha' = 'bravo') |
> >    $i == 3 ? var('alpha' = 'bravo') |
> >    $i == 4 ? var('alpha' = 'bravo') |
> >    $i == 5 ? var('alpha' = 'bravo') |
> >    $i == 6 ? var('alpha' = 'bravo');
> > /iterate;
>
>
> Cheers
>
> Rich in Toronto
>
>
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>
>



--
Mvh
Johan Sölve
____________________________________
Montania System AB
Halmstad   Stockholm   Malmö
http://www.montania.se

Johan Sölve
Mobil +46 709-51 55 70
[hidden email]

Kristinebergsvägen 17, S-302 41 Halmstad, Sweden
Telefon +46 35-136800 |  Fax +46 35-136801

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Jonathan Vanherpe (T & T NV)
In reply to this post by Viaduct Productions
Rich wrote:

> On Feb 8, 2008, at 4:40 AM, Bil Corry wrote:
>
>> iterate($group, var('i'));
>>    $i == 1 ? var('alpha' = 'bravo') |
>>    $i == 2 ? var('alpha' = 'bravo') |
>>    $i == 3 ? var('alpha' = 'bravo') |
>>    $i == 4 ? var('alpha' = 'bravo') |
>>    $i == 5 ? var('alpha' = 'bravo') |
>>    $i == 6 ? var('alpha' = 'bravo');
>> /iterate;
>
> OK, can you explain how that works?  I thought Ternary was restricted to
> test ? true | false;  I would love to expand on ternary.
>

Well, that's what it does:
if($i==1);
        var('alpha'='bravo');
else;
        if($i==2);
                var('alpha'='bravo');
        else;
        [..]
        /if;
/if;

He's just nesting them all. (I'd personally use SELECT; /SELECT; for
doing this, but that works too).

Using the ternary like this *is* more readable than nesting if's, though
;) .

Jonathan
--
Jonathan Vanherpe - Tallieu & Tallieu NV - [hidden email]

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Adam Randall-2
In reply to this post by Viaduct Productions
On Fri, 8 Feb 2008 03:59:53 -0500, Rich wrote:

> On Feb 8, 2008, at 3:31 AM, Adam Randall wrote:
>
>> One line If statements as you have here, as well as one line if/else
>> (each) statements, should be written like so:
>
> Tested:
>
> var('group' = array);
> loop(500);
> $group->insert(math_random(-lower = 1, -upper = 6));
> /loop;
>
>
> var('myClock' = date_msec);
> iterate($group, var('i'));
> $i == 1 ? var('alpha' = 'bravo');
> $i == 2 ? var('alpha' = 'bravo');
> $i == 3 ? var('alpha' = 'bravo');
> $i == 4 ? var('alpha' = 'bravo');
> $i == 5 ? var('alpha' = 'bravo');
> $i == 6 ? var('alpha' = 'bravo');
> /iterate;
> 'Ternary: ' integer(date_msec - $myClock) ' ms<br/>';
>
>
> $myClock = date_msec;
> iterate($group, var('i'));
> if($i == 1);
> var('alpha' = 'bravo');
> else($i == 2);
> var('alpha' = 'bravo');
> else($i == 3);
> var('alpha' = 'bravo');
> else($i == 4);
> var('alpha' = 'bravo');
> else($i == 5);
> var('alpha' = 'bravo');
> else($i == 6);
> var('alpha' = 'bravo');
> /if;
> /iterate;
> 'Expanded Conditional: ' integer(date_msec - $myClock) ' ms<br/>';
>
>
>
> $myClock = date_msec;
> iterate($group, var('i'));
> select(math_random(-lower = 1, -upper = 6));
> case(1);
> var('alpha' = 'bravo');
> case(2);
> var('alpha' = 'bravo');
> case(3);
> var('alpha' = 'bravo');
> case(4);
> var('alpha' = 'bravo');
> case(5);
> var('alpha' = 'bravo');
> case(6);
> var('alpha' = 'bravo');
> /select;
> /iterate;
> 'Select Case: ' integer(date_msec - $myClock) ' ms<br/>';
>
> // G5 1.8 LP 8.5.5 9 ms / 5 ms / 42 ms
>

As Wade said, the third example was doing more work than necessary, and was fixed by using $i instead of the second random. However, your ternary test was unfair. I've amended the code so all three are as equal as possible:

var(
        'group'   = array,
        'i'       = null,
        'myclock' = null );

loop(50000);
        $group->insert(math_random(-lower = 1, -upper = 6));
/loop;


$myClock = _date_msec;
iterate($group, $i);
        $i == 1 ? var('alpha' = 'bravo') | (
                $i == 2 ? var('alpha' = 'bravo') | (
                        $i == 3 ? var('alpha' = 'bravo') | (
                                $i == 4 ? var('alpha' = 'bravo') | (
                                        $i == 5 ? var('alpha' = 'bravo') | (
                                                $i == 6 ? var('alpha' = 'bravo') ) ) ) ) );
/iterate;
'Ternary: ' ( _date_msec - $myClock ) ' ms<br/>';


$myClock = _date_msec;
iterate($group, $i);
        if($i == 1);
                var('alpha' = 'bravo');
        else($i == 2);
                var('alpha' = 'bravo');
        else($i == 3);
                var('alpha' = 'bravo');
        else($i == 4);
                var('alpha' = 'bravo');
        else($i == 5);
                var('alpha' = 'bravo');
        else($i == 6);
                var('alpha' = 'bravo');
        /if;
/iterate;
'Expanded Conditional: ' ( _date_msec - $myClock ) ' ms<br/>';



$myClock = _date_msec;
iterate($group, $i);
        select($i);
                case(1);
                        var('alpha' = 'bravo');
                case(2);
                        var('alpha' = 'bravo');
                case(3);
                        var('alpha' = 'bravo');
                case(4);
                        var('alpha' = 'bravo');
                case(5);
                        var('alpha' = 'bravo');
                case(6);
                        var('alpha' = 'bravo');
        /select;
/iterate;
'Select Case: ' ( _date_msec - $myClock ) ' ms<br/>';

Ternary: 450 ms
Expanded Conditional: 452 ms
Select Case: 481 ms

What I've found is that the multi-ternary and the if/else are pretty much equal speed. One test will be a few milliseconds longer, then shorter the next time. I had to ramp up the number of tests to see a larger time coverage. In all cases, the select was always slower than the rest.

All tests were done on a Xserve G5 2.3GHz with 4GB of RAM. Lasso 8.1.0.

Adam.

--
-----------------------------------------------------------------------
Adam Randall                                       http://www.xaren.net
[hidden email]                                   AIM/iChat:  blitz574

"Macintosh users are a special case. They care passionately about the
Mac OS and would rewire their own bodies to run on Mac OS X if such a
thing were possible." -- Peter H. Lewis

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Adam Randall-2
In reply to this post by Viaduct Productions
On Fri, 8 Feb 2008 04:45:11 -0500, Rich wrote:

> OK, can you explain how that works?  I thought Ternary was restricted
> to test ? true | false;  I would love to expand on ternary.
>
>
> On Feb 8, 2008, at 4:40 AM, Bil Corry wrote:
>
>> iterate($group, var('i'));
>>    $i == 1 ? var('alpha' = 'bravo') |
>>    $i == 2 ? var('alpha' = 'bravo') |
>>    $i == 3 ? var('alpha' = 'bravo') |
>>    $i == 4 ? var('alpha' = 'bravo') |
>>    $i == 5 ? var('alpha' = 'bravo') |
>>    $i == 6 ? var('alpha' = 'bravo');
>> /iterate;
>
>
> Cheers
>
> Rich in Toronto

This is the same thing I did in my version. Yes, a ternary can only have a true or false result, but that doesn't mean that the true or the false action can't be another ternary :)

true ? ( true ? 'a' | 'b' ) | ( true ? 'c' | 'd' );

Adam.

--
-----------------------------------------------------------------------
Adam Randall                                       http://www.xaren.net
[hidden email]                                   AIM/iChat:  blitz574

"Macintosh users are a special case. They care passionately about the
Mac OS and would rewire their own bodies to run on Mac OS X if such a
thing were possible." -- Peter H. Lewis

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: Lasso Coding Examples

Viaduct Productions
In reply to this post by Johan Solve
OK, that is very good to know.

On Feb 8, 2008, at 4:50 AM, Johan Solve wrote:

> See it as a chain of elses. Every | is an else.


Cheers

Rich in Toronto


--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

12