lasso9 accessing a variable with a variable

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

Re: lasso9 accessing a variable with a variable

Jolle Carlestam-2
23 aug 2014 kl. 02:54 skrev French, Shelane <[hidden email]>:

> wrp(’multiples’) -> last only works if you know you have multiples. ->last won't come out well with a string.

That is a very valid point. You can use a conditional at the calling point to protect yourself. Or let’s take this as an inspiration to the following tidbit.

It is very easy to expand present functionality with your own additions. If you want string -> last to work all you need to do is add the following definition:

define string -> last => self

'My string' -> last
-> My string

Now, there can be objections raised here. string -> last already exists and it produces the last character of the string. We should not tamper with that.

But we can add a definition that will work for both arrays and strings.

define string -> lastitem => self
define array -> lastitem => self -> last
define staticarray -> lastitem => self -> last


'My string' -> lastitem
-> My string

(:'My first', 'My last') -> lastitem
-> My last

array('My first', 'My last') -> lastitem
-> My last

Sweet, short and efficient. The Lasso way.

HDB
Jolle
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Brad Lindsay
This has been an excellent discussion, and I thought I'd like to add in
another option. This one works more like [action_param] of yore. It
returns the first parameter it finds unless you specify that you want
them all and then returns a staticarray


define wrp(name::string, -all::boolean=false) => {
     local(wrp) = wrps->find(#name)

     #wrp->isEmpty? return void

     if(#all) => {
         return (with param in #wrp select #param->second)->asStaticArray
     }

     return #wrp->get(1)->second
}

With this [wrp('multiples')] would return the first item and
[wrp('multiples', -all)] the staticarray of all items. This means to get
the last item is simply [wrp('multiples', -all)->last]


HTH,
Brad



On 8/23/14, 5:14 AM, Jolle Carlestam wrote:

> 23 aug 2014 kl. 02:54 skrev French, Shelane<[hidden email]>:
>
>> wrp(’multiples’) ->  last only works if you know you have multiples. ->last won't come out well with a string.
>
> That is a very valid point. You can use a conditional at the calling point to protect yourself. Or let’s take this as an inspiration to the following tidbit.
>
> It is very easy to expand present functionality with your own additions. If you want string ->  last to work all you need to do is add the following definition:
>
> define string ->  last =>  self
>
> 'My string' ->  last
> ->  My string
>
> Now, there can be objections raised here. string ->  last already exists and it produces the last character of the string. We should not tamper with that.
>
> But we can add a definition that will work for both arrays and strings.
>
> define string ->  lastitem =>  self
> define array ->  lastitem =>  self ->  last
> define staticarray ->  lastitem =>  self ->  last
>
>
> 'My string' ->  lastitem
> ->  My string
>
> (:'My first', 'My last') ->  lastitem
> ->  My last
>
> array('My first', 'My last') ->  lastitem
> ->  My last
>
> Sweet, short and efficient. The Lasso way.
>
> HDB
> Jolle
> #############################################################
> Attend the Lasso Developer Conference 2014!
> October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
> http://www.lassosoft.com/LDC-newmarket-2014
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>    the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to:<[hidden email]>
> Send administrative queries to<[hidden email]>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

RE: lasso9 accessing a variable with a variable

French, Shelane
In reply to this post by Ke Carlton-3
A lasso 9 symantic question:

define settings => var(__settings)->isa(::map) ? $__settings | $__settings
:= map

Is this returning the full map settings if the tag "settings" is called?

If there are a few variables that you would not want to put into a single map (each will be a map). Should you write a tag for each one, or can you condense to a since defined tag?

It seems from this example one for each would be best.



Sent with Good (www.good.com)


-----Original Message-----
From: Ke Carlton [[hidden email]<mailto:[hidden email]>]
Sent: Wednesday, August 20, 2014 03:41 PM Pacific Standard Time
To: Lasso Talk
Subject: Re: lasso9 accessing a variable with a variable


Now that you know it's possible; it's probably a good time to suggest not
using them.

Dynamic variables inevitably cause problems in terms of logic,
pre-compilation validation and depending on how they're used can increase
security risks.

I believe they're most commonly mis-used for storing settings, session
values or worse action params. In this situation I'd recommend using a
single variable with a map container values.

Here's are useful approach which means you never have to address the
variable directly and also not need to worry about it being set or not:

define settings =>  var(__settings)->isa(::map) ? $__settings | $__settings
:= map
define setting(name::string) => settings->find(#name)
define setting=(value::any,name::string) = settings->insert(#name = #value)


Then in your code you will never have to address the variable directly and
you can do things like this:

setting('isadmin') = true

Or:

if(setting('isadmin')) => { /* do this */ }


I take a similar approach to things like user ids or other simple values
likely to be stored in a session. I'll never address the variable directly
because it may mean the code may break if it doesn't exist or is changed.

define user_id => var(__user_id) || 0
define user_id=(value::integer) => var(__user_id = #value)


Then within your code you can do:

if(user_id) ...

Or on login:


user_id = #row(::id)


Why else is this good? well because you're no longer addressing variables
you can add to or change the behaviour without having to change your entire
code base. For example if we wanted to ensure that user_id was stored in
the current session when set we could do something like this:

define user_id=(value::integer) => {
    var(__user_id = #value)
    session_addVar(current_session, '__user_id')
}

And we could make it even smarter like so:

define user_id=(value::integer) => {
    var(__user_id = #value)
    #value
    ? session_addVar(current_session, '__user_id')
    | session_removeVar(current_session, '__user_id')
}

Which would automatically remove the value from the session if set to 0.

So all of the above is probably a bit to much for the solution you're
trying to put in place today — but I'd highly recommend keeping this type
of thinking in mind for future projects as it can save you a world of hurt
and really improve productivity.

Ke

On 21 August 2014 09:24, Steven McIntosh <[hidden email]> wrote:

> Thanks Mark—I can’t believe I didn’t try it that way to begin with! I
> guess I always use that for assigning and not retrieving.
>
> Thanks again,
> Steve
>
>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

RE: lasso9 accessing a variable with a variable

French, Shelane
Also, I am a little confused on this:
define setting=(value::any,name::string) = settings->insert(#name = #value)

There is an equal sign before the parameters and another equal sign. What is going on here?

Thanks!!



Sent with Good (www.good.com)


-----Original Message-----
From: French, Shelane [[hidden email]<mailto:[hidden email]>]
Sent: Saturday, August 23, 2014 03:19 PM Pacific Standard Time
To: '[hidden email]'
Subject: RE: lasso9 accessing a variable with a variable


A lasso 9 symantic question:

define settings => var(__settings)->isa(::map) ? $__settings | $__settings
:= map

Is this returning the full map settings if the tag "settings" is called?

If there are a few variables that you would not want to put into a single map (each will be a map). Should you write a tag for each one, or can you condense to a since defined tag?

It seems from this example one for each would be best.



Sent with Good (www.good.com)


-----Original Message-----
From: Ke Carlton [[hidden email]<mailto:[hidden email]>]
Sent: Wednesday, August 20, 2014 03:41 PM Pacific Standard Time
To: Lasso Talk
Subject: Re: lasso9 accessing a variable with a variable


Now that you know it's possible; it's probably a good time to suggest not
using them.

Dynamic variables inevitably cause problems in terms of logic,
pre-compilation validation and depending on how they're used can increase
security risks.

I believe they're most commonly mis-used for storing settings, session
values or worse action params. In this situation I'd recommend using a
single variable with a map container values.

Here's are useful approach which means you never have to address the
variable directly and also not need to worry about it being set or not:

define settings =>  var(__settings)->isa(::map) ? $__settings | $__settings
:= map
define setting(name::string) => settings->find(#name)
define setting=(value::any,name::string) = settings->insert(#name = #value)


Then in your code you will never have to address the variable directly and
you can do things like this:

setting('isadmin') = true

Or:

if(setting('isadmin')) => { /* do this */ }


I take a similar approach to things like user ids or other simple values
likely to be stored in a session. I'll never address the variable directly
because it may mean the code may break if it doesn't exist or is changed.

define user_id => var(__user_id) || 0
define user_id=(value::integer) => var(__user_id = #value)


Then within your code you can do:

if(user_id) ...

Or on login:


user_id = #row(::id)


Why else is this good? well because you're no longer addressing variables
you can add to or change the behaviour without having to change your entire
code base. For example if we wanted to ensure that user_id was stored in
the current session when set we could do something like this:

define user_id=(value::integer) => {
    var(__user_id = #value)
    session_addVar(current_session, '__user_id')
}

And we could make it even smarter like so:

define user_id=(value::integer) => {
    var(__user_id = #value)
    #value
    ? session_addVar(current_session, '__user_id')
    | session_removeVar(current_session, '__user_id')
}

Which would automatically remove the value from the session if set to 0.

So all of the above is probably a bit to much for the solution you're
trying to put in place today — but I'd highly recommend keeping this type
of thinking in mind for future projects as it can save you a world of hurt
and really improve productivity.

Ke

On 21 August 2014 09:24, Steven McIntosh <[hidden email]> wrote:

> Thanks Mark—I can’t believe I didn’t try it that way to begin with! I
> guess I always use that for assigning and not retrieving.
>
> Thanks again,
> Steve
>
>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Jolle Carlestam-2
That looks like a typo to me.
define setting=(value::any,name::string) => settings->insert(#name = #value)


HDB
Jolle

Sent from a thin, flat, touchy device from an undetermined place in space.

> 24 aug 2014 kl. 00:37 skrev "French, Shelane" <[hidden email]>:
>
> Also, I am a little confused on this:
> define setting=(value::any,name::string) = settings->insert(#name = #value)
>
> There is an equal sign before the parameters and another equal sign. What is going on here?
>
> Thanks!!
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Jolle Carlestam-2
In reply to this post by French, Shelane

> 24 aug 2014 kl. 00:19 skrev "French, Shelane" <[hidden email]>:
>
> A lasso 9 symantic question:
>
> define settings => var(__settings)->isa(::map) ? $__settings | $__settings
> := map
>
> Is this returning the full map settings if the tag "settings" is called?
>
> If there are a few variables that you would not want to put into a single map (each will be a map). Should you write a tag for each one, or can you condense to a since defined tag?
>
> It seems from this example one for each would be best.

I would create one definition for each. The penalty in form of increased memory usage is minuscule and the methods/types does not do anything until called. And at that point it's better to call something that leaves as small footprint as possible. Thus rather 5-10-20 definitions with one map each than one definition with a very large map.


HDB
Jolle

Sent from a thin, flat, touchy device from an undetermined place in space
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

RE: lasso9 accessing a variable with a variable

French, Shelane
In reply to this post by Jolle Carlestam-2
So, what is the first equals before the params? I hadn't seen that anywhere before. And is not putting it in brackets only because it's one line of code?



Sent with Good (www.good.com)


-----Original Message-----
From: Jolle Carlestam [[hidden email]<mailto:[hidden email]>]
Sent: Saturday, August 23, 2014 04:02 PM Pacific Standard Time
To: [hidden email]
Subject: Re: lasso9 accessing a variable with a variable


That looks like a typo to me.
define setting=(value::any,name::string) => settings->insert(#name = #value)


HDB
Jolle

Sent from a thin, flat, touchy device from an undetermined place in space.

> 24 aug 2014 kl. 00:37 skrev "French, Shelane" <[hidden email]>:
>
> Also, I am a little confused on this:
> define setting=(value::any,name::string) = settings->insert(#name = #value)
>
> There is an equal sign before the parameters and another equal sign. What is going on here?
>
> Thanks!!
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Ke Carlton-3
It's the syntax to define a method that accepts an assigned value as a
parameter.

So, as a non-worldly example:

define hello = (rhs::string) => 'Hello ' + #rhs

hello = 'World'  // doesn't appear to do much

hello := 'World' // Returns Hello World


Effectively it allows you to create custom setters. So whenever you have a
method that sets a value somewhere it makes sense to take advantage of the
syntax as it's logical and clear what it's doing. For example:

setting('isadmin') = false


That's very explicit; the isadmin setting is being set to false. It's much
clearer than this:

setting('isadmin',false)


Is that setting isadmin to false or is false a switch of some kind? I
wouldn't know without looking at the source.

So this:

define setting=(rhs::any,name::string) => settings->insert(#name = #rhs)
 // rhs = right hand side


Allows for this:

setting('isadmin') = true


The params shift across one to the right, the right hand side assignment is
the first param (rhs) and the parameter ('isadmin') becomes the 'name'
parameter.

As covered in other threads I prefer to do this:

define user_id=(id::integer) => var(user_id) = #id

With:

user_id = 1234


Instead of this through out the code:

var(user_id) = 1234


It means if I need to change the variable name I only need to do so in once
place and it also means I ensure that the value will only ever be an
integer. Anything else will fail. It would also be pair with something like
this:

define user_id => var(user_id) || 0

It results in a more robust code base over all and less thinking required
on the developers front.

Ke





On 24 August 2014 16:50, French, Shelane <[hidden email]> wrote:

> So, what is the first equals before the params? I hadn't seen that
> anywhere before. And is not putting it in brackets only because it's one
> line of code?
>
>
>
> Sent with Good (www.good.com)
>
>
> -----Original Message-----
> From: Jolle Carlestam [[hidden email]<mailto:[hidden email]>]
> Sent: Saturday, August 23, 2014 04:02 PM Pacific Standard Time
> To: [hidden email]
> Subject: Re: lasso9 accessing a variable with a variable
>
>
> That looks like a typo to me.
> define setting=(value::any,name::string) => settings->insert(#name =
> #value)
>
>
> HDB
> Jolle
>
> Sent from a thin, flat, touchy device from an undetermined place in space.
>
> > 24 aug 2014 kl. 00:37 skrev "French, Shelane" <[hidden email]>:
> >
> > Also, I am a little confused on this:
> > define setting=(value::any,name::string) = settings->insert(#name =
> #value)
> >
> > There is an equal sign before the parameters and another equal sign.
> What is going on here?
> >
> > Thanks!!
> #############################################################
> Attend the Lasso Developer Conference 2014!
> October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
> http://www.lassosoft.com/LDC-newmarket-2014
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>   the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
> #############################################################
> Attend the Lasso Developer Conference 2014!
> October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
> http://www.lassosoft.com/LDC-newmarket-2014
>
> #############################################################
>
> This message is sent to you because you are subscribed to
>   the mailing list Lasso [hidden email]
> Official list archives available at http://www.lassotalk.com
> To unsubscribe, E-mail to: <[hidden email]>
> Send administrative queries to  <[hidden email]>
>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Jolle Carlestam-2
In reply to this post by Brad Lindsay
23 aug 2014 kl. 14:21 skrev Brad Lindsay <[hidden email]>:

> This has been an excellent discussion, and I thought I'd like to add in
> another option. This one works more like [action_param] of yore. It
> returns the first parameter it finds unless you specify that you want
> them all and then returns a staticarray
>
>
> define wrp(name::string, -all::boolean=false) => {
>     local(wrp) = wrps->find(#name)
>
>     #wrp->isEmpty? return void
>
>     if(#all) => {
>         return (with param in #wrp select #param->second)->asStaticArray
>     }
>
>     return #wrp->get(1)->second
> }
>
> With this [wrp('multiples')] would return the first item and
> [wrp('multiples', -all)] the staticarray of all items. This means to get
> the last item is simply [wrp('multiples', -all)->last]


That is even more excellent!

I do however have a slight variation here too.

I suggest moving the check for empty to after the check for #all. Would make calling the method with -all always return a staticarray, albeit empty if no params where found.

Doing wrp(’myparam’, -all) would in most cases be used for checkboxes in forms. And the issue we all fight with in regards to checkboxes is that if none was ticked then looking for it would return void. And calling it when only one was ticked would return a bytes object. If multiple items are ticked it would mean several bytes objects that we can join in an array.
With my alteration of wrp a checkbox param would constantly always be a staticarray. And with the way wrp is built items in the staticarray would always be strings.

Heres’s the tweaked code:

define wrp(name::string, -all::boolean=false) => {
    local(wrp) = wrps->find(#name)

    if(#all) => {
        return (with param in #wrp select #param->second)->asStaticArray
    }

    #wrp->isEmpty? return void

    return #wrp->get(1)->second
}

HDB
Jolle
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Brad Lindsay
On 8/24/14, 2:13 AM, Jolle Carlestam wrote:
> That is even more excellent!
>
> I do however have a slight variation here too.
>
> I suggest moving the check for empty to after the check for #all. Would make calling the method with -all always return a staticarray, albeit empty if no params where found.

Excellent. (That's actually what I'm doing in my wrapper code.) Thanks
for pointing that out.

Brad
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

RE: lasso9 accessing a variable with a variable

French, Shelane
In reply to this post by Jolle Carlestam-2
Excellent, excellent, excellent. I have now saved this into lasso 9 and have done one for lasso 8 with the same principals. It's just one of those "the thought had never occurred to me" things that I will feel like, "what did I ever do before this" as soon as it's fully into practice.

On a little side question: does lasso 9 automatically do -encodenone on defined methods. In lasso 8 you had to include the -encodenone tag if you wanted to return unaltered HTML. I don't see anything about it in the HTML.



Sent with Good (www.good.com)


-----Original Message-----
From: Jolle Carlestam [[hidden email]<mailto:[hidden email]>]
Sent: Saturday, August 23, 2014 11:13 PM Pacific Standard Time
To: [hidden email]
Subject: Re: lasso9 accessing a variable with a variable


23 aug 2014 kl. 14:21 skrev Brad Lindsay <[hidden email]>:

> This has been an excellent discussion, and I thought I'd like to add in
> another option. This one works more like [action_param] of yore. It
> returns the first parameter it finds unless you specify that you want
> them all and then returns a staticarray
>
>
> define wrp(name::string, -all::boolean=false) => {
>     local(wrp) = wrps->find(#name)
>
>     #wrp->isEmpty? return void
>
>     if(#all) => {
>         return (with param in #wrp select #param->second)->asStaticArray
>     }
>
>     return #wrp->get(1)->second
> }
>
> With this [wrp('multiples')] would return the first item and
> [wrp('multiples', -all)] the staticarray of all items. This means to get
> the last item is simply [wrp('multiples', -all)->last]


That is even more excellent!

I do however have a slight variation here too.

I suggest moving the check for empty to after the check for #all. Would make calling the method with -all always return a staticarray, albeit empty if no params where found.

Doing wrp(’myparam’, -all) would in most cases be used for checkboxes in forms. And the issue we all fight with in regards to checkboxes is that if none was ticked then looking for it would return void. And calling it when only one was ticked would return a bytes object. If multiple items are ticked it would mean several bytes objects that we can join in an array.
With my alteration of wrp a checkbox param would constantly always be a staticarray. And with the way wrp is built items in the staticarray would always be strings.

Heres’s the tweaked code:

define wrp(name::string, -all::boolean=false) => {
    local(wrp) = wrps->find(#name)

    if(#all) => {
        return (with param in #wrp select #param->second)->asStaticArray
    }

    #wrp->isEmpty? return void

    return #wrp->get(1)->second
}

HDB
Jolle
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Ke Carlton-3
Correct, Lasso 9 doesn't do any encoding unless told to — which makes a lot
of sense and keeps things simple.


On 25 August 2014 12:11, French, Shelane <[hidden email]> wrote:

>
> On a little side question: does lasso 9 automatically do -encodenone on
> defined methods. In lasso 8 you had to include the -encodenone tag if you
> wanted to return unaltered HTML. I don't see anything about it in the HTML.
>
>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

RE: lasso9 accessing a variable with a variable

French, Shelane
In that light, what if you do what to do encoding? It is necessary to prevent against XSS if you're displaying any user inputted data.



Sent with Good (www.good.com)


-----Original Message-----
From: Ke Carlton [[hidden email]<mailto:[hidden email]>]
Sent: Sunday, August 24, 2014 07:03 PM Pacific Standard Time
To: Lasso Talk
Subject: Re: lasso9 accessing a variable with a variable


Correct, Lasso 9 doesn't do any encoding unless told to — which makes a lot
of sense and keeps things simple.


On 25 August 2014 12:11, French, Shelane <[hidden email]> wrote:

>
> On a little side question: does lasso 9 automatically do -encodenone on
> defined methods. In lasso 8 you had to include the -encodenone tag if you
> wanted to return unaltered HTML. I don't see anything about it in the HTML.
>
>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Jolle Carlestam-2

> 25 aug 2014 kl. 16:18 skrev "French, Shelane" <[hidden email]>:
>
> In that light, what if you do what to do encoding? It is necessary to prevent against XSS if you're displaying any user inputted data.

String -> encodehtml
Or
Encode_html(string)

HDB
Jolle

Sent from a mobile device. Any anomalies is due to Autocorrect.

#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Ke Carlton-3
This; and if you're using a templating system of some kinda can do
automatically so in that.

On 26 August 2014 08:47, Jolle Carlestam <[hidden email]> wrote:

>
> String -> encodehtml
> Or
> Encode_html(string)
>
> HDB
> Jolle
>
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

French, Shelane
In reply to this post by Jolle Carlestam-2
Question:

I often have a param that has no value like ?search or ?logout

Then I do action_param('search', -count) do check its existence.

Will your tag have issues with these params? It is there a way to add a
count or true if present to your tag or another quick way of checking in
Lasso 9?

On 8/23/14, 11:13 PM, "Jolle Carlestam" <[hidden email]> wrote:

23 aug 2014 kl. 14:21 skrev Brad Lindsay <[hidden email]>:

> This has been an excellent discussion, and I thought I'd like to add in
> another option. This one works more like [action_param] of yore. It
> returns the first parameter it finds unless you specify that you want
> them all and then returns a staticarray
>
>
> define wrp(name::string, -all::boolean=false) => {
>     local(wrp) = wrps->find(#name)
>
>     #wrp->isEmpty? return void
>
>     if(#all) => {
>         return (with param in #wrp select #param->second)->asStaticArray
>     }
>
>     return #wrp->get(1)->second
> }
>
> With this [wrp('multiples')] would return the first item and
> [wrp('multiples', -all)] the staticarray of all items. This means to get
> the last item is simply [wrp('multiples', -all)->last]


That is even more excellent!

I do however have a slight variation here too.

I suggest moving the check for empty to after the check for #all. Would
make calling the method with -all always return a staticarray, albeit
empty if no params where found.

Doing wrp(’myparam’, -all) would in most cases be used for checkboxes in
forms. And the issue we all fight with in regards to checkboxes is that if
none was ticked then looking for it would return void. And calling it when
only one was ticked would return a bytes object. If multiple items are
ticked it would mean several bytes objects that we can join in an array.
With my alteration of wrp a checkbox param would constantly always be a
staticarray. And with the way wrp is built items in the staticarray would
always be strings.

Heres’s the tweaked code:

define wrp(name::string, -all::boolean=false) => {
    local(wrp) = wrps->find(#name)

    if(#all) => {
        return (with param in #wrp select #param->second)->asStaticArray
    }

    #wrp->isEmpty? return void

    return #wrp->get(1)->second
}

HDB
Jolle
#############################################################
Attend the Lasso Developer Conference 2014!
October 1-3, 2014 at Treefrog HQ, Newmarket, Ontario, Canada
http://www.lassosoft.com/LDC-newmarket-2014

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Jonathan Guthrie-3
The easiest way might be to access direct:

web_request->params-asStaticArray >> 'search'

Lasso 9 specific of course :)


On Oct 14, 2014, at 12:59 PM, French, Shelane <[hidden email]> wrote:

> Question:
>
> I often have a param that has no value like ?search or ?logout
>
> Then I do action_param('search', -count) do check its existence.
>
> Will your tag have issues with these params? It is there a way to add a
> count or true if present to your tag or another quick way of checking in
> Lasso 9?

Jono

----------------------------
Jonathan Guthrie
[hidden email]
@iamjono
LassoSoft Inc.
AIM Chatroom: lassochat


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Brad Lindsay
In reply to this post by French, Shelane
On 10/14/14, 12:59 PM, French, Shelane wrote:
> Question:
>
> I often have a param that has no value like ?search or ?logout
>
> Then I do action_param('search', -count) do check its existence.
>
> Will your tag have issues with these params? It is there a way to add a
> count or true if present to your tag or another quick way of checking in
> Lasso 9?


Not sure about Jolle's tag, but here's what I've found to be the best
way to check that in Lasso9:

web_request->param(`search`) != void

Parameters that are passed with no values will return null. When you
check for a parameter that hasn't been passed, it returns void. (FYI,
rope->param does the same thing by default.)


HTH,
Brad

#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

Jonathan Guthrie-3
In reply to this post by Jonathan Guthrie-3
On Oct 14, 2014, at 1:05 PM, Jonathan Guthrie <[hidden email]> wrote:

> web_request->params-asStaticArray >> 'search'

Damn. Syntax error, should be:
web_request->params->asStaticArray >> 'search'



Jono

----------------------------
Jonathan Guthrie
[hidden email]
@iamjono
LassoSoft Inc.
AIM Chatroom: lassochat


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: lasso9 accessing a variable with a variable

French, Shelane
OK. Since Jolle's tag is returning a static array, I can do this with his
tag:

wrps >> 'search'

Thanks. That works. Sometimes you can't see what is right in front of your
face.

On 10/14/14, 11:51 AM, "Jonathan Guthrie" <[hidden email]> wrote:

On Oct 14, 2014, at 1:05 PM, Jonathan Guthrie <[hidden email]> wrote:

> web_request->params-asStaticArray >> 'search'

Damn. Syntax error, should be:
web_request->params->asStaticArray >> 'search'



Jono

----------------------------
Jonathan Guthrie
[hidden email]
@iamjono
LassoSoft Inc.
AIM Chatroom: lassochat


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>


#############################################################

This message is sent to you because you are subscribed to
  the mailing list Lasso [hidden email]
Official list archives available at http://www.lassotalk.com
To unsubscribe, E-mail to: <[hidden email]>
Send administrative queries to  <[hidden email]>
12