Re: AW: my int( 1..31 ) $var ?
Christian Renz wrote: Now, I might be stupid, but I keep asking myself what you would need a property for in this example. Yes. It's important to remember that the shiny new hammer of properties is not necessarily the appropriate tool to beat on *every* problem. :-) Damian
AW: my int( 1..31 ) $var ?
It's also far slower. Constructing a 31-element list, junctionizing it, This might well be done at compile-time. And/or, lazily. So the cost of these two steps is likely to be negligible. then testing against each element vs. 2 numeric comparisons. Yes. That's a significant cost in this case. My example was bad. I intended something with more behind it. print creditcard if $var == CreditCard( 'VISA' ); wich should do a mod10 on $var and then match a regex or something. I think one could say CreditCard( 'VISA' ) is then the property. And after reading further seeing it could be smart matched like: print creditcard if $var ~~ CreditCard( 'VISA' ); Brought to a point: Properties could be also smart matched. Murat
AW: my int( 1..31 ) $var ?
my $var = 0; # or my $var = 0; # or my int $var = 0; # or my num $var = 0; # all 4 cases should print is integer print is integer if int $var == $var; This should work as a more generic method to test Integer *value*, rather than type, which IMHO is more useful (and more commonly wanted). I agree. And i found an interesting thread about that in comp.object http://groups.google.de/groups?hl=delr=ie=UTF-8oe=UTF-8threadm=1990S ep28.181057.16740%40odi.comrnum=5prev=/groups%3Fq%3DVariable%2BTypes%2 BVs%2BValue%2BTypes%26hl%3Dde%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3 D1990Sep28.181057.16740%2540odi.com%26rnum%3D5 Murat
Re: AW: my int( 1..31 ) $var ?
On Sat, 4 Jan 2003, Murat Ünalan wrote: print creditcard if $var == CreditCard( 'VISA' ); wich should do a mod10 on $var and then match a regex or something. I think one could say CreditCard( 'VISA' ) is then the property. And after reading further seeing it could be smart matched like: print creditcard if $var ~~ CreditCard( 'VISA' ); Brought to a point: Properties could be also smart matched. Wouldn't it be easier to say: print creditcard if CreditCard( $var ) eq 'VISA'; ~ John Williams
Re: AW: my int( 1..31 ) $var ?
Murat Ünalan wrote: print creditcard if $var ~~ CreditCard( 'VISA' ); Brought to a point: Properties could be also smart matched. 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
AW: my int( 1..31 ) $var ?
Why should you care? Perl 6 isn't going to be that strictly typed, is it? Not even optional ? Murat
Re: AW: AW: my int( 1..31 ) $var ?
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
Re: AW: my int( 1..31 ) $var ?
Now, I might be stupid, but I keep asking myself what you would need a property for in this example. To me, it totally confuses the underlying structure. When was the last time you asked an integer to identify itself as a valid credit card number? It is _not_ a property of the integer that it is a valid cc number, rather it happens that it will be accepted as valid _by a certain authority_. So why not go and ask the authority? Compare the case to a phone number -- the phone number itself doesn't know if its valid. You could only check a certain format (if e.g. in the USA, in Germany, that would be very hard). To check the validity, query a directory server or ask a phone to dial the number. Don't check the number itself. To provide even stronger evidence against using properties, consider the fact that a credit card number will only be accepted with an expiration date and -- with good merchants -- the three or four-digit security code on the back of the card. Now you're up to doing something like # funky syntax ahead my $cc = [ num = 8765 4321, expdate = 0799, code = 123 ]; # do magic # ... print I'm rich! if $cc.prop{CreditCard(CAMELCARD)}; Ouch! I may be conservative, but again I think you should go and ask the authority (ie., a validation service). The authority in this case probably is already encapsulated in a CPAN module and could look like this: use CreditCard::Validation; deduct(10_000_000) if validate($number, $expdate, PERLIAN EXPRESS); or something like use CreditCard::Validation qw(ISA CAMELCARD MONKSCLUB); deduct(10_000_000) if validate($number, $expdate, $bankcode); depending on your tastes. Yep, it doesn't use funky perl 6 syntax, but it SWIMs (Says What I Mean, ie. it is readable). Greetings, Christian -- [EMAIL PROTECTED] - http://www.web42.com/crenz/ - http://www.web42.com/ If God were a Kantian, who would not have us till we came to Him from the purest and best motives, who could be saved? -- C.S. Lewis, The Problem of Pain