Re: AW: AW: "my int( 1..31 ) $var" ?

2003-01-04 Thread John Williams
On Sun, 5 Jan 2003, Murat Ünalan wrote:
> > Properties *can* be smart-matched:
> >
> > print "creditcard" if $var.prop().{CreditCard} ~~ 'VISA';
> > or:
> > print "creditcard" if $var.prop{CreditCard} ~~ 'VISA';
> > or:
> > print "creditcard" if $var.CreditCard ~~ 'VISA';
> >
> I think this is similar to "John Williams" suggestion:
>
>  print "creditcard" if CreditCard( $var ) eq 'VISA';

Well, no.  In my suggestion, CreditCard is a sub which checks whether $var
is a valid credit card, returning the card type.

In Damian's example, he is assuming $var already has a property assigned
to it called CreditCard possibly containing the value 'VISA'.  So his has
less processing they either of ours.

The problem I see with:

>   print "creditcard" if $var ~~ CreditCard( 'VISA' );

is that CreditCard does not know what $var is.  Even if you overload the
smartmatch operator on $var's class, it is still comparing $var with the
value returned from CreditCard.

>  sub CreditCard
>  {
>   #connect to a "specific" database (VISA, MASTERCARD, ..)
>   #compare with "non-blocked or valid" cards
>  }
...
> Excerpt: My concept is to have a twofold view about "properties". One
> thing that is attributing a type during decleration, and something that
> could verified against in other context. All my thinking on that
> orginates from Damians Attribute::Type.
>
> Hopefully i do not confuse you too much.

A sub is not a property.  It might be a method, which could sometimes look
like a property (as in Damian's third example), but you have strayed so
far away from properties that you are talking about something else now.

~ John Williams




AW: AW: "my int( 1..31 ) $var" ?

2003-01-04 Thread Murat Ünalan
> Properties *can* be smart-matched:
> 
>   print "creditcard" if $var.prop().{CreditCard} ~~ 'VISA';
> or:
>   print "creditcard" if $var.prop{CreditCard} ~~ 'VISA';
> or:
>   print "creditcard" if $var.CreditCard ~~ 'VISA';
> 
> Damian
> 

I think this is similar to "John Williams" suggestion:

 print "creditcard" if CreditCard( $var ) eq 'VISA';

It is something different to scan a database of card types and return a
list of possible matches, instead
of just testing one requested card type. What if CreditCard is such a
routine

 sub CreditCard
 {
#connect to a "specific" database (VISA, MASTERCARD, ..)
#compare with "non-blocked or valid" cards 
 } 

or 

 sub CreditCard
 {
#cycle through all 800 CreditCard types and return matches
 } 

Then Damians suggetion

>   print "creditcard" if $var.CreditCard ~~ 'VISA';

could mean heavy processing, but

print "creditcard" if $var ~~ CreditCard( 'VISA' );

would be short work.

Excerpt: My concept is to have a twofold view about "properties". One
thing that is attributing a type during decleration, and something that
could verified against in other context. All my thinking on that
orginates from Damians Attribute::Type.

Hopefully i do not confuse you too much.

Murat