Pass params to tag with equals

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

Pass params to tag with equals

Mark Palmer
Hi List,

Lasso 8.5.6

Is it possible to pass a param to a tag with equals?

For example

$mytype->mytag = 'some value';

Rather than

$mytype->mytag('some value');

I'm using _UnknownTag to get and set values in a map within my type and it seem more readable to use "=".

Regards

Mark Palmer
E: [hidden email]
T: 01902 620500
W: www.pageworks.co.uk




#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Pass params to tag with equals

Tim Taplin
While I'm not a great user of _unKnownTag, the two examples do quite different things. It may be that you can use the equals notation if you write your type appropriately.
On Jul 12, 2011, at 7:14 AM, Mark Palmer wrote:

> Hi List,
>
> Lasso 8.5.6
>
> Is it possible to pass a param to a tag with equals?
>
> For example
>
> $mytype->mytag = 'some value';
This sets the  public property mytag of the var mytype to be the string 'some value';
The publice properties in 8.5.6 are declared as locals in the type definition and internally referenced as self->mytag or self->'mytag'

>
> Rather than
>
> $mytype->mytag('some value');

This passes the string parameter 'some value' to a public method named mytag on the var mytype where it may be used for further processing or may be used to set some internal property.

The public methods are declared with define_tag code blocks inside the type definition and may or may not have a return value. They can also be referenced internally with the self->mytag notation.

>
> I'm using _UnknownTag to get and set values in a map within my type and it seem more readable to use "=".
>

Probably I'm telling you things you already know, but sometimes just repeating the info in a different way triggers the lightbulb needed to get moving forward.

Tim Taplin

> Regards
>
> Mark Palmer
> E: [hidden email]
> T: 01902 620500
> W: www.pageworks.co.uk
>


#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Pass params to tag with equals

Kyle Jessup-2
In reply to this post by Mark Palmer

On Jul 12, 2011, at 9:14 AM, Mark Palmer wrote:

> Hi List,
>
> Lasso 8.5.6
>
> Is it possible to pass a param to a tag with equals?
>
> For example
>
> $mytype->mytag = 'some value';
>
> Rather than
>
> $mytype->mytag('some value');
>
> I'm using _UnknownTag to get and set values in a map within my type and it seem more readable to use "=".

It's not really possible in 8.
It is directly possible in 9, however. You would define a method named "mytag=".

define foo => type {
        public mytag=(n) => {
                // ... use #n
        }
}

foo->mytag = 'xyz' // (that calls the mytag= method)

You can handle that with _unknowntag as well by just checking to see if the method name that was called ends in '='.
-Kyle

> Regards
>
> Mark Palmer
> E: [hidden email]
> T: 01902 620500
> W: www.pageworks.co.uk

#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Pass params to tag with equals

Mark Palmer
In reply to this post by Mark Palmer
Tim, Kyle. Thanks for the replies. I suspected it wasn't possible.

It was just a nice to have to make some long sequence of calculations more readable.

For example:

Self->premium_net(#base_rate);
Self->premium_ipt(Self->premium_net * Self->ipt_rate / 100);
Self->premium_total(Self->premium_net + Self->premium_ipt);

Just seems wrong not seeing equals signs, and of course I keep typing new code with "=" and erroring.


On 12 Jul 2011, at 14:14, Mark Palmer wrote:

> Hi List,
>
> Lasso 8.5.6
>
> Is it possible to pass a param to a tag with equals?
>
> For example
>
> $mytype->mytag = 'some value';
>
> Rather than
>
> $mytype->mytag('some value');
>
> I'm using _UnknownTag to get and set values in a map within my type and it seem more readable to use "=".
>
> Regards
>
> Mark Palmer
> E: [hidden email]
> T: 01902 620500
> W: www.pageworks.co.uk
>
>
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list <[hidden email]>.
> To unsubscribe, E-mail to: <[hidden email]>
> To switch to the DIGEST mode, E-mail to <[hidden email]>
> To switch to the INDEX mode, E-mail to <[hidden email]>
> Send administrative queries to  <[hidden email]>
>



Regards

Mark Palmer
E: [hidden email]
T: 01902 620500
W: www.pageworks.co.uk




#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Pass params to tag with equals

Tim Taplin
hmm, so, without seeing whats behind the code, it seems that you could write your type so that it would allow more visually appealing version of this
On Jul 12, 2011, at 7:38 AM, Mark Palmer wrote:

> Tim, Kyle. Thanks for the replies. I suspected it wasn't possible.
>
> It was just a nice to have to make some long sequence of calculations more readable.
>
> For example:
>
> Self->premium_net(#base_rate);

If this is really just a variable, then define it as a local in the type definition so that you could then use
self->premium_net = #base_rate;

> Self->premium_ipt(Self->premium_net * Self->ipt_rate / 100);

here again, it its just a property, you could define as a local and then use
self->premium_ipt = (self->premium_net * self->ipt_rate/100);

or use it as a method
self->premium_ipt;
    and internally calculate (self->premium_net * self->ipt_rate/100)
        return the calculated value.
> Self->premium_total(Self->premium_net + Self->premium_ipt);

This could be a method which does not require parameters.

self->premium_total;
     would be internally defined to use the self->premium_net and self->premium_ipt to calculate and return a total.

>
> Just seems wrong not seeing equals signs, and of course I keep typing new code with "=" and erroring.
>

I usually try to use action based names to help visually determine differences between properties and methods. So, I might have a property named premium_ipt and a method named calc_premium_ipt which performs the calculation and sets the property value. Sometimes there may be optional parameters which then define the internal behavior of the tag/method.

>
> On 12 Jul 2011, at 14:14, Mark Palmer wrote:
>
>> Hi List,
>>
>> Lasso 8.5.6
>>
>> Is it possible to pass a param to a tag with equals?
>>
>> For example
>>
>> $mytype->mytag = 'some value';
>>
>> Rather than
>>
>> $mytype->mytag('some value');
>>
>> I'm using _UnknownTag to get and set values in a map within my type and it seem more readable to use "=".
>>
>> Regards
>>
>> Mark Palmer
>> E: [hidden email]
>> T: 01902 620500
>> W: www.pageworks.co.uk
>>
>>
>>
>>
>> #############################################################
>> This message is sent to you because you are subscribed to
>> the mailing list <[hidden email]>.
>> To unsubscribe, E-mail to: <[hidden email]>
>> To switch to the DIGEST mode, E-mail to <[hidden email]>
>> To switch to the INDEX mode, E-mail to <[hidden email]>
>> Send administrative queries to  <[hidden email]>
>>
>
>
>
> Regards
>
> Mark Palmer
> E: [hidden email]
> T: 01902 620500
> W: www.pageworks.co.uk
>
>
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list <[hidden email]>.
> To unsubscribe, E-mail to: <[hidden email]>
> To switch to the DIGEST mode, E-mail to <[hidden email]>
> To switch to the INDEX mode, 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 <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Pass params to tag with equals

Tim Taplin
In reply to this post by Mark Palmer
Just seeing a potential further refinement.

a method named self->set_premium_net(#base_rate) could set the property premium_net and then update the calculations for premium_ipt and premium_total by either using its own internal calculations or by calling the set or calc methods of those properties.

using calc methods for other properties:
define_tag('set_premium_net', -required='base_rate');
        self->premium_net = #base_rate;
        self->calc_premium_ipt;
        self->calc_premium_total;
/define_tag;

all internal (where premium_ipt and premium_total are properties of the type):
define_tag('set_premium_net', -required='base_rate');
        self->premium_net = #base_rate;
        self->premium_ipt = (Self->premium_net * Self->ipt_rate / 100);
        self->premium_total = (Self->premium_net + Self->premium_ipt);
/define_tag;

On Jul 12, 2011, at 7:38 AM, Mark Palmer wrote:

> Tim, Kyle. Thanks for the replies. I suspected it wasn't possible.
>
> It was just a nice to have to make some long sequence of calculations more readable.
>
> For example:
>
> Self->premium_net(#base_rate);
> Self->premium_ipt(Self->premium_net * Self->ipt_rate / 100);
> Self->premium_total(Self->premium_net + Self->premium_ipt);
>
> Just seems wrong not seeing equals signs, and of course I keep typing new code with "=" and erroring.
>
>
> On 12 Jul 2011, at 14:14, Mark Palmer wrote:
>
>> Hi List,
>>
>> Lasso 8.5.6
>>
>> Is it possible to pass a param to a tag with equals?
>>
>> For example
>>
>> $mytype->mytag = 'some value';
>>
>> Rather than
>>
>> $mytype->mytag('some value');
>>
>> I'm using _UnknownTag to get and set values in a map within my type and it seem more readable to use "=".
>>
>> Regards
>>
>> Mark Palmer
>> E: [hidden email]
>> T: 01902 620500
>> W: www.pageworks.co.uk
>>
>>
>>
>>
>> #############################################################
>> This message is sent to you because you are subscribed to
>> the mailing list <[hidden email]>.
>> To unsubscribe, E-mail to: <[hidden email]>
>> To switch to the DIGEST mode, E-mail to <[hidden email]>
>> To switch to the INDEX mode, E-mail to <[hidden email]>
>> Send administrative queries to  <[hidden email]>
>>
>
>
>
> Regards
>
> Mark Palmer
> E: [hidden email]
> T: 01902 620500
> W: www.pageworks.co.uk
>
>
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list <[hidden email]>.
> To unsubscribe, E-mail to: <[hidden email]>
> To switch to the DIGEST mode, E-mail to <[hidden email]>
> To switch to the INDEX mode, 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 <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Pass params to tag with equals

Mark Palmer
In reply to this post by Tim Taplin

On 12 Jul 2011, at 14:55, Tim Taplin wrote:

> If this is really just a variable, then define it as a local in the type definition so that you could then use
> self->premium_net = #base_rate;

I use the _Unknown_Tag to update a pair in an array called 'fields' within the type.

Self->blah doesn't actually exist so blah in my fields array get updated using something like Self->'fields'->Find(Tag_Name)->Get(1) =

I have all my fields in an array, actually an lp_array, so that I can iterate and check ->type, check the field exists in the Db, build SQL statements and various other activities.

>
> I usually try to use action based names to help visually determine differences between properties and methods. So, I might have a property named premium_ipt and a method named calc_premium_ipt which performs the calculation and sets the property value. Sometimes there may be optional parameters which then define the internal behavior of the tag/method.

I've worked that way before and found maintaining the code more difficult scrolling up and down a long type chasing down calculations in different tags. As it stands I have a calculate_premium tag which sets maybe 30-40 values, all going on in one place. The validation of the input is done elsewhere and the process aborts before calculation - so I have pretty clean data to calculate from (insurance premiums).


Regards

Mark Palmer
E: [hidden email]
T: 01902 620500
W: www.pageworks.co.uk




#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Pass params to tag with equals

Mark Palmer
In reply to this post by Tim Taplin
I see mileage in this, I could break calculations down in largish blocks of related stuff and I get an = assignment.

I twice today wonder why something wasn't behaving as expected because I'd use $instance->total = blah instead of $instance->total(blah)

On 12 Jul 2011, at 15:02, Tim Taplin wrote:

> Just seeing a potential further refinement.
>
> a method named self->set_premium_net(#base_rate) could set the property premium_net and then update the calculations for premium_ipt and premium_total by either using its own internal calculations or by calling the set or calc methods of those properties.
>
> using calc methods for other properties:
> define_tag('set_premium_net', -required='base_rate');
> self->premium_net = #base_rate;
> self->calc_premium_ipt;
> self->calc_premium_total;
> /define_tag;
>
> all internal (where premium_ipt and premium_total are properties of the type):
> define_tag('set_premium_net', -required='base_rate');
> self->premium_net = #base_rate;
> self->premium_ipt = (Self->premium_net * Self->ipt_rate / 100);
> self->premium_total = (Self->premium_net + Self->premium_ipt);
> /define_tag;



Regards

Mark Palmer
E: [hidden email]
T: 01902 620500
W: www.pageworks.co.uk




#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>