Variable conundrum

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

Variable conundrum

Trevor Jacques
It's been a long day, so I can't figure this one out. I have to
construct the name of a variable using lasso, and then use Lasso to
call the variable with that name, something like:

$(string1 + (Lasso evaluation resulting in string2))

That's the gist of it, by my brain seems to be shutting down.
Shouldn't this be simple?

T.

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: Variable conundrum

Fletcher Sandbeck
On 2006-09-06 at 20:07 by [hidden email] (Trevor Jacques):

>It's been a long day, so I can't figure this one out. I have to
>construct the name of a variable using lasso, and then use Lasso to
>call the variable with that name, something like:
>
>$(string1 + (Lasso evaluation resulting in string2))
>
>That's the gist of it, by my brain seems to be shutting down.
>Shouldn't this be simple?

You should use the [Var] tag rather than the $ symbol.

[var: 'string' + (expression)]

Hope this helps,

[fletcher]
--
Fletcher Sandbeck                         [hidden email]
Director of Product Development       http://www.lassostudio.com
OmniPilot Software, Inc.                http://www.omnipilot.com

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: Variable conundrum

Doug Gentry
In reply to this post by Trevor Jacques
When I'm not sure I construct the variable first, so maybe something  
like this:

var: 'varname'= 'string1' + (lasso expression);

Then

var: $varname = etc....

....Doug

On Sep 6, 2006, at 8:07 PM, Trevor Jacques wrote:

> It's been a long day, so I can't figure this one out. I have to  
> construct the name of a variable using lasso, and then use Lasso to  
> call the variable with that name, something like:
>
> $(string1 + (Lasso evaluation resulting in string2))
>
> That's the gist of it, by my brain seems to be shutting down.  
> Shouldn't this be simple?
>
> T.
>
> ------------------------------
> Lasso Support: http://support.omnipilot.com/
> Search the list archives: http://www.listsearch.com/lassotalk.lasso
> Manage your list subscription:  http://www.listsearch.com/ 
> lassotalk.lasso?manage



---
Doug Gentry
Dynapolis & Southern Oregon University
p:  541-261-8501 / Toll Free: 888-490-0644
[hidden email]
www.dynapolis.com



------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: Variable conundrum

Trevor Jacques
In reply to this post by Fletcher Sandbeck
>  >$(string1 + (Lasso evaluation resulting in string2))
>[var: 'string' + (expression)]
>Hope this helps,

Thanks, Fletcher. That's exactly what I needed. I think I should go
watch TV for the rest of the evening.... ;-)

T.

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: Variable conundrum

Bil Corry-3
In reply to this post by Trevor Jacques
Unless you have an overriding reason for using dynamic variable names, I strongly recommend against it.  You'll find it's *much* easier to maintain and debug multiple values using an array (or map) rather than using dynamic variables.

- Bil

Trevor Jacques wrote:
> It's been a long day, so I can't figure this one out. I have to
> construct the name of a variable using lasso, and then use Lasso to call
> the variable with that name, something like:
>
> $(string1 + (Lasso evaluation resulting in string2))
>
> That's the gist of it, by my brain seems to be shutting down. Shouldn't
> this be simple?


------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: Variable conundrum

Greg Willits-2
In reply to this post by Trevor Jacques
On Sep 6, 2006, at 5:07 PM, Trevor Jacques wrote:

> It's been a long day, so I can't figure this one out. I have to  
> construct the name of a variable using lasso, and then use Lasso to  
> call the variable with that name, something like:
>
> $(string1 + (Lasso evaluation resulting in string2))
>
> That's the gist of it, by my brain seems to be shutting down.  
> Shouldn't this be simple?

Aside from the basics like fletcher said, you'll also find that you  
can invoke member tags and instance variables if you wrap the whole  
thing in () like

        (var:#formController)->validate;

Or in a dose of composition:

        (var:($compositeObject->find:'formController'))->validate;

That kind of dynamic assignment can be quite handy in keeping the  
lower code completely ignorant of the actual names of the  
implementation variables.

That example also shows one of the problems with doing OOP in Lasso:

        a map requires $var->find:'x'

        whereas a ctype is simply $var->'x'

So, if I start out using a map, then have to change it to a ctype in  
order to add some custom member tags, I have a whole bunch of code to  
through to remove that (most lamented) ->find tag.

It gets even worse if... ah, but I digress.

Anyway, I don't have Bil's disdain for dynamic vars. They're  
essential to many kinds of OOP and code automation. And having these  
tools http://ldml.org/library/fwpDebugUtils.lasso really helps too.

-- gw


------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: Variable conundrum

Trevor Jacques
In reply to this post by Bil Corry-3
>Unless you have an overriding reason for using dynamic variable names

I do and the debugging is simple in this case. Thanks for the
suggestion, though.  :-)

T.

------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage
Reply | Threaded
Open this post in threaded view
|

Re: Variable conundrum

Bil Corry-3
In reply to this post by Greg Willits-2
Greg Willits wrote:
> Anyway, I don't have Bil's disdain for dynamic vars. They're essential
> to many kinds of OOP and code automation.

There's no disdain, just advice that if an array or map can accomplish the task, then there isn't any reason to complicate the coding with dynamically named vars.


- Bil


------------------------------
Lasso Support: http://support.omnipilot.com/
Search the list archives: http://www.listsearch.com/lassotalk.lasso
Manage your list subscription:  
http://www.listsearch.com/lassotalk.lasso?manage