Re: [perl #45935] [TODO][IMCC] syntax for assignment/creating objects
On 10/2/07, via RT Klaas-Jan Stol [EMAIL PROTECTED] wrote: # New Ticket Created by Klaas-Jan Stol # Please include the string: [perl #45935] # in the subject line of all future correspondence about this issue. # URL: http://rt.perl.org/rt3/Ticket/Display.html?id=45935 hi, a code snippet like this: the_value = new 'Type' the_value = 42 is in my eyes not clear. It seems as if the first line creates an object, and it seems to be discarded on the second line, as some value is assigned to the_value. some time ago (months, maybe 1 year?) there was a discussion about different assignment operators for setting/assigning. I remember := being mentioned. I don't recall whether it was about the issue, or that it was about the ops set and assign. I think this syntax could be improved, to make it more clear that the value 42 is assigned to the newly created object. kjs as a note-to-self, maybe this is an idea: .local pmc a,b,c a = new 'Integer' set a = 42 So, instead of a=42, you need to use the op. It reads kinda natural, set a to 42, but it's a bit longer to type. likewise, this could be done for assign as well assign b = c Also, the aforementioned := could be introduced, like so: a := new 'Integer' # assign a new object to a a = 42 # set some value to a a := b # assign value in b to a I'm not really sure if assigning another pmc and creating a new pmc can both be considered assignment, thus using the := assignment operator; in other words, would this be more consistent? Just some thoughts. kjs
Re: [perl #45935] [TODO][IMCC] syntax for assignment/creating objects
Klaas-Jan Stol (via RT) wrote: a code snippet like this: the_value = new 'Type' the_value = 42 is in my eyes not clear. It seems as if the first line creates an object, and it seems to be discarded on the second line, as some value is assigned to the_value. The key thing to keep in mind is that '=' is not an operator in PIR, it's just syntactic sugar for human convenience. Those two lines are actually: new the_value, 'Type' set the_value, 42 These apply two simple rules of An '=' followed by an opcode means the result argument is the first argument to the opcode and Any other '=' (that's not a sub or method call) is the 'set' opcode, and the result argument is the first argument to 'set'. The different behavior is a result of calling different opcodes. Each individual opcode decides whether it has assignment or binding behavior. Allison
[perl #45935] [TODO][IMCC] syntax for assignment/creating objects
# New Ticket Created by Klaas-Jan Stol # Please include the string: [perl #45935] # in the subject line of all future correspondence about this issue. # URL: http://rt.perl.org/rt3/Ticket/Display.html?id=45935 hi, a code snippet like this: the_value = new 'Type' the_value = 42 is in my eyes not clear. It seems as if the first line creates an object, and it seems to be discarded on the second line, as some value is assigned to the_value. some time ago (months, maybe 1 year?) there was a discussion about different assignment operators for setting/assigning. I remember := being mentioned. I don't recall whether it was about the issue, or that it was about the ops set and assign. I think this syntax could be improved, to make it more clear that the value 42 is assigned to the newly created object. kjs