Re: identity tests and comparing two references
On Thu, 2005-03-31 at 23:46 -0800, Darren Duncan wrote: What I want to be able to do is compare two references to see if they point to the same thing, in this case an object, but in other cases perhaps some other type of thing. Let's be clear about the difference between P5 and P6 here. In P5, an object was actually a reference with special magic that indicated that it was also tied to a package. In P6, an object is a data-type. It's not a reference, and any member payload is attached directly to the variable. So, comparing references to objects isn't all that common in P6, though it could certainly happen. Now, back to the concept of identity comparison... I would expect that you could do this: $ref1 ~~ $ref2 The table in S4 doesn't have an entry for Any ~~ Reference, but my guess is that that's just an oversight, as it seems to fit into the flow nicely. More generally, I see no direct way to tell if two values have the same storage (the same PMC in Parrot), so you might have to do something P5ish: \$a ~~ \$b
Re: identity tests and comparing two references
On Thu, Mar 31, 2005 at 11:46:22PM -0800, Darren Duncan wrote: : So, what is the operator for reference comparison? The =:= operator is almost certainly what you want here. Larry
Re: identity tests and comparing two references
Sam Vilain writes: Darren Duncan wrote: Now I seem to remember reading somewhere that '===' will do what I want, but I'm now having trouble finding any mention of it. So, what is the operator for reference comparison? As someone who wrote a tool that uses refaddr() and 0+ in Perl 5 to achieve the same thing, I agree with the need for such an operator. I think that =:= compares *lexical* identity is fairly clearly spelled out in S03. However, we need a way to compare *value* /identity/ (not equality or equivalence), without being subject to overloading etc. I'm pretty sure that =:= does what you want. If you have two scalar references, you might have to spell it like this: $$x =:= $$y And binding can't be overloaded[1], so you don't have to worry about that. Luke [1] Or maybe it can, but like the prefix operator in C++, only people who really know what they're doing will overload it.
Re: identity tests and comparing two references
: On Thu, 2005-03-31 at 23:46 -0800, Darren Duncan wrote: On Fri, Apr 01, 2005 at 08:04:22AM -0500, Aaron Sherman wrote: : : What I want to be able to do is compare two references to see if they : point to the same thing, in this case an object, but in other cases : perhaps some other type of thing. : : Let's be clear about the difference between P5 and P6 here. In P5, an : object was actually a reference with special magic that indicated that : it was also tied to a package. : : In P6, an object is a data-type. It's not a reference, and any member : payload is attached directly to the variable. Well, it's still a reference, but we try to smudge the distinction in P6. : So, comparing references to objects isn't all that common in P6, though : it could certainly happen. : : Now, back to the concept of identity comparison... I would expect that : you could do this: : : $ref1 ~~ $ref2 No, ~~ will deref any explicit references and smart match against what is referenced. That's part of the intentional smudging. : The table in S4 doesn't have an entry for Any ~~ Reference, but my : guess is that that's just an oversight, as it seems to fit into the flow : nicely. That would be going back to the P5 way of thinking. The ~~ operator doesn't try to guess whether the user meant references to refer to themselves or their referent. It always assumes the referent. Note that when you say @foo ~~ @bar it's actually passing two array references to ~~, for instance, since they're in scalar context. : More generally, I see no direct way to tell if two values have the same : storage (the same PMC in Parrot), so you might have to do something : P5ish: : : \$a ~~ \$b Wouldn't work. Ends up doing the same as $a ~~ $b. Anyway, that's what =:= is there for. Larry
Re: identity tests and comparing two references
On Fri, Apr 01, 2005 at 08:39:52AM -0700, Luke Palmer wrote: : I'm pretty sure that =:= does what you want. If you have two scalar : references, you might have to spell it like this: : : $$x =:= $$y Unnecessary, I think. I want $x =:= @y to tell me whether the reference in $x is to the same array as @y. Larry
Re: Documentary annotations: $what docwhy
According to Abhijit Mahabal: sub f2c (Num $temp doc Temperature in degrees F) {...} Nce. -- Chip Salzenberg- a.k.a. -[EMAIL PROTECTED] Open Source is not an excuse to write fun code then leave the actual work to others.
Re: identity tests and comparing two references
On Fri, 2005-04-01 at 10:46, Larry Wall wrote: On Fri, Apr 01, 2005 at 08:04:22AM -0500, Aaron Sherman wrote: : In P6, an object is a data-type. It's not a reference, and any member : payload is attached directly to the variable. Well, it's still a reference, but we try to smudge the distinction in P6. Hrm... ok, I'm a bit confused, probably because I'm thinking in terms of Parrot. In Parrot, an object PMC is not a reference, it's of some object type and contains fields directly in the PMC for any member data. There's also a vtable which tells you everything you need to know about its methods. So you're saying that P6 will only manipulate Parrot-level object PMCs via references? If so, sorry, I just didn't realize that. -- Aaron Sherman [EMAIL PROTECTED] Senior Systems Engineer and Toolsmith It's the sound of a satellite saying, 'get me down!' -Shriekback
Re: identity tests and comparing two references
At 7:37 AM -0800 4/1/05, Larry Wall wrote: On Thu, Mar 31, 2005 at 11:46:22PM -0800, Darren Duncan wrote: : So, what is the operator for reference comparison? The =:= operator is almost certainly what you want here. Larry Thanks to everyone for their answers. Last night I started coding with =:= by default since it was the best self-documenting option I could see, then lacking a definitive answer. From what I've read of your responses, this seems to have been the right choice. So I will assume that =:= is the definitive answer until the official docs decide to unambiguously say otherwise. -- Darren Duncan
Re: identity tests and comparing two references
Larry Wall skribis 2005-04-01 7:47 (-0800): : $$x =:= $$y Unnecessary, I think. I want $x =:= @y to tell me whether the reference in $x is to the same array as @y. But my $foo; my $bar := $foo; my $baz = \$foo; $foo :=: $bar; # true $foo :=: $baz; # also true?! $bar = 1; # updates $foo $baz = 2; # does not update $foo IMO, :=: should not auto(de)reference. Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
Re: identity tests and comparing two references
Juerd skribis 2005-04-01 22:35 (+0200): $foo :=: $bar; # true $foo :=: $baz; # also true?! IMO, :=: should not auto(de)reference. s:g/:=:/=:=/ Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
PLEAC - Programming Language Examples Alike Cookbook
So far http://pleac.sourceforge.net/ has comparative Perl Cookbook example for these languages: - perl, 100.00% done (naturally, since they're from the book) - python, 63.43% done - ruby, 62.43% done - guile, 30.00% done - merd, 28.86% done - ada, 26.00% done - tcl, 25.00% done - ocaml, 24.71% done - haskell, 20.86% done - pike, 23.29% done - java, 14.29% done - pliant, 9.43% done - commonlisp, 6.29% done - c++, 3.43% done - forth, 2.00% done - erlang, 1.86% done - php, 1.71% done - R, 1.43% done - masd, 0.57% done - nasm, 0.29% done You can see from this graph http://pleac.sourceforge.net/pleac_evolving.png that both python and ruby are steadily gathering examples, and that ocaml and pike have shown a recent spurt of activity. The maintainer, Guillaume Cottenceau [EMAIL PROTECTED], is very happy to accept perl6 versions of Perl Cookbook examples. As soon as the first arrives he'll rename perl to perl5 and start a new perl6 language category and start tracking contributions. More useful golf practice for Pugs fans! There must be some Perl Cookbook examples it can already execute... Tim.
Re: identity tests and comparing two references
Thomas Sandlaß skribis 2005-04-01 23:37 (+0200): Juerd wrote (with substitution applied): IMO, =:= should not auto(de)reference. So you expect $bar to contain value 2 and detach from $foo? No. But if you said $baz instead of $bar, then yes. How would one then reach the value in $foo? With $$baz? Assuming you did mean $baz in the previous line, yes. And for longer chains of referene with a corresponding number of $ on the front? But IIRC that was obviated in Perl6. Exactly. Because an array in scalar context is automatically referenced, and an arrayref in array context is automatically dereferenced, that implicity can exist. But a reference IS a scalar, and having scalars reference or dereference in scalar context automatically is madness. And if we're saying that an array is a scalar as much as a string or a number is, then why are values mutable, do scalars not have three different sigils and do things automatically convert without the intervention of lists? If =:= tests variable sameness, then it should do that literally in order to both be useful and look like :=. For reference equality you can still use \FOO == \BAR (I assume). Juerd -- http://convolution.nl/maak_juerd_blij.html http://convolution.nl/make_juerd_happy.html http://convolution.nl/gajigu_juerd_n.html
Re: identity tests and comparing two references
HaloO Juerd, you wrote: Thomas Sandlaß skribis 2005-04-01 23:37 (+0200): So you expect $bar to contain value 2 and detach from $foo? No. But if you said $baz instead of $bar, then yes. Ohh sorry, I mis-read your mail as talking about chains of references: $baz to $bar to $foo to 2. The last step could also be direct storage. Then my question was if an assignment is forwarded along this chain or if a ref is somehow manipulating it's target directly. Consider: my $one = 1; my $two := $one; my $three = \$two; # same as := ? was actually your question, or not? my $four := three; my $five = 5; $four = 4; # $one == 4 now? $$four := $five; say $three; # prints 5? then why are values mutable, do scalars not have three different sigils and do things automatically convert without the intervention of lists? Values are immutable in the abstract. That means 3 is always 3. Only variables change (reference to) value, hence the name. An object that is not referenced and objects that just reference each other are garbage collected! For simple values the reference is optimised into direct storage if possible. These two things are the implementation of conceptually immutable values. By introducing a finite subtype Example of Array where { is shape(0..9) of Bool }; you have 1024 possible immutable values which could be pre-allocated and then referenced as needed. For less restricted types you get so many possible values that other implementation strategies are needed :) Calling a method through a variable conceptually produces a new value of the object type in question which in turn is implemented by changing the object in place for practical reasons. If =:= tests variable sameness, then it should do that literally in order to both be useful and look like :=. For reference equality you can still use \FOO == \BAR (I assume). In my view of the world =:= checks for identity of values. Equality could hold for non-identical objects. E.g. a complex number object with imaginary part 0 could be considered equal to a real number with the value of the real part of the complex number: my Complex $complex = (3.2, 0); my Num $real = 3.2; $complex =:= $real # false $complex == $real # true The above would of course be implemented by installing apropriate multis for infix:== from the Complex class. Overloading =:= OTOH will be hardly necessary nor usefull. -- TSa (Thomas Sandlaß)
Re: identity tests and comparing two references
Larry Wall wrote: On Fri, Apr 01, 2005 at 08:39:52AM -0700, Luke Palmer wrote: : I'm pretty sure that =:= does what you want. If you have two scalar : references, you might have to spell it like this: : : $$x =:= $$y Unnecessary, I think. I want $x =:= @y to tell me whether the reference in $x is to the same array as @y. $x = 42; $a = \$x but false; $b = \$y but blue; $a =:= $b ??? If it's true, then the =:= operator is pretty useless -- two things that are =:= to each-other can have very different semantics. If it's not, then there needs to be some other way to tell. $$a =:= $$b feels sane to me. So does $a == $b. I generally don't like it when things half-smudge important differences. Either there should be no difference between a reference and a referent, or there should be. We shouldn't try to hide important truths. (This is why I don't like CGI.pm's HTML generation, for example -- it makes you feel like you don't need to know HTML, when you do.) -=- James Mastros
Re: identity tests and comparing two references
James Mastros wrote: $x = 42; $a = \$x but false; $b = \$y but blue; Assuming you meant \$x in the last row we are dealing with three values: 42 but true 42 but false 42 but blue Which are not identical but equal. The first value is not necessarily implemented that way because the boolean value can be calculated on demand. And $a and $b none the less manage to change the value in $x when new values are assigned to them, and these can be retrieved via $x. If you meant true not blue in the last line than $b =:= $x. $a =:= $b ??? If it's true, then the =:= operator is pretty useless -- two things that are =:= to each-other can have very different semantics. If it's not, then there needs to be some other way to tell. $$a =:= $$b feels sane to me. So does $a == $b. I think =:= shall supersede the $ chains in front of refs by always dereferencing through to value level and accumulating traits while doing so. Usually you don't even know how many levels of indirection there are. I generally don't like it when things half-smudge important differences. Me neither. -- TSa (Thomas Sandlaß)
Re: Documentary annotations: $what docwhy
Luke Palmer wrote: Supposing I had a doc trait, could I say: sub f2c (Num $temp docTemperature in degrees F) docConvert degress F to degrees C {...} Or would I be forced to spell it doc('stuff') ? Well, first you need an `is` somewhere in there. And after that I think you'll need to do it in doc('stuff') form. If we did allow doc, then this: A word of warning... Perldoc[*] will eventually support this sort of thing, for sure. But it will lead to the unfortunate side effect that your code needs to at least compile without syntax errors, and without too many obscene mistakes - so that these traits are accessible by the dialect that interprets them into a Perldoc tree. That's if you care about seeing the information presented nicely when you use `perldoc Foo', of course. Sam. * - the project aiming to provide dialect-agnostic inline documentation for Perl 5 and Perl 6. The Perl 5 prototype is on CPAN... still in early stages.
Definitive and Complete Perl 6 Operator List
S03 does not seem to detail a complete list of all Perl 6 operators. For example, it explicitly mentions += but does not mention -= Googling around, I found the Perl 6 Periodic Table of Operators http://www.ozonehouse.com/mark/blog/code/PeriodicTable.html (which I assume does not form part of the official Perl 6 docs) and this November 1 2002 p6l post: http://groups-beta.google.com/group/perl.perl6.language/msg/cd1ca0a0c901d35f?hl=enlr=ie=UTF-8rnum=1 which is the closest I found to what I'm looking for. Is there a definitive, official, complete list of all Perl 6 operators, along with their precedence levels? For example, this Perl 6 program: my $i = 0; $i ~^= 2; Pugs currently rejects with: pugs: cannot cast into a handle: VInt 2 Since ~^ is string xor, I guessed that ~^= would be allowed. /-\ Find local movie times and trailers on Yahoo! Movies. http://au.movies.yahoo.com