Re: how do I instantiate? -- was: Objects!
Michal Wallace [EMAIL PROTECTED] wrote: I'm not even trying to get objects working yet. I just need something that'll let me run setprop on it You can attach properties to all PMCs. And WRT object instantiation: t/pmc/object*.t but only integer attributes are done. leo
Re: how do I instantiate? -- was: Objects!
On Thu, 8 Jan 2004, Leopold Toetsch wrote: Michal Wallace [EMAIL PROTECTED] wrote: I'm not even trying to get objects working yet. I just need something that'll let me run setprop on it You can attach properties to all PMCs. And WRT object instantiation: t/pmc/object*.t but only integer attributes are done. Thanks. I looked at those last night but I didn't get what I was looking at. Guess I should have been more careful. What exactly is the difference between an attribute and a property? Sincerely, Michal J Wallace Sabren Enterprises, Inc. - contact: [EMAIL PROTECTED] hosting: http://www.cornerhost.com/ my site: http://www.withoutane.com/ --
Re: how do I instantiate? -- was: Objects!
Michal Wallace [EMAIL PROTECTED] wrote: What exactly is the difference between an attribute and a property? $ perldoc docs/pdds/pdd15_objects.pod /TRANSLATION AND GLOSSARY Michal J Wallace leo
Re: how do I instantiate? -- was: Objects!
On Thu, 8 Jan 2004, Leopold Toetsch wrote: Michal Wallace [EMAIL PROTECTED] wrote: What exactly is the difference between an attribute and a property? $ perldoc docs/pdds/pdd15_objects.pod /TRANSLATION AND GLOSSARY Thanks. Don't mind me. I'm going to go make a card that says RTFM on my monitor here... :) So let me see if I have this right. Attributes are slots in a class, that get created on each instance. Properties don't have predefined slots, you can just attach whatever you want to any PMC. So: a language like java would probably use attributes, because the shape of the class is defined before hand, whereas python would tend to use properties... Right? But when I actually go to fill in the slots, I still use getprop/setprop for both types, right? So if I setprop on an attribute-based-class it would fill in the attribute first, and then if the attribute slot isn't there, do something else (like throw an exception or just make a property?) I guess what I'm asking is: is getprop/setprop a universal interface, or will we need some kind of logic to know whether a particular object uses attributes instead? Sincerely, Michal J Wallace Sabren Enterprises, Inc. - contact: [EMAIL PROTECTED] hosting: http://www.cornerhost.com/ my site: http://www.withoutane.com/ --
Re: how do I instantiate? -- was: Objects!
Michal Wallace [EMAIL PROTECTED] wrote: On Thu, 8 Jan 2004, Leopold Toetsch wrote: $ perldoc docs/pdds/pdd15_objects.pod /TRANSLATION AND GLOSSARY So let me see if I have this right. Attributes are slots in a class, that get created on each instance. Properties don't have predefined slots, you can just attach whatever you want to any PMC. Yep. The whatever you want is another PMC though. So: a language like java would probably use attributes, because the shape of the class is defined before hand, whereas python would tend to use properties... Right? Yes. Yes. But when I actually go to fill in the slots, I still use getprop/setprop for both types, right? So if I setprop on an attribute-based-class it would fill in the attribute first, and then if the attribute slot isn't there, do something else (like throw an exception or just make a property?) No: Attributes aren't filled with setprop, that just sets a property. And: what's happening if a non-existing property is set depends on the HLL. Python's throwing AFAIK a NameError or such exception. Attributes and properties are 2 different things to achieve similar effects. Perl6 will have both. Python would very likely use properties only. I guess what I'm asking is: is getprop/setprop a universal interface, or will we need some kind of logic to know whether a particular object uses attributes instead? We will have to know, if an object originated from Python or Perl6, if we want to mix library code. But don't nail me down on that. This all depends on namespaces too, the order how we lookup attributes (or properties) but its primary up to the HLL code to do the right thing. (All AFAIK, which isn't much when objects are concerned) Michal J Wallace leo
how do I instantiate? -- was: Objects!
On Tue, 2 Dec 2003, Dan Sugalski wrote: *) Creating new objects involves calling the -init vtable entry *on the class*. Because of this each class gets a custom vtable where the init method has been swapped out for one (from objects.c) that creates a new object instead. Well, cool! How do I this from parrot? I've been trying things along the lines of: .sub _main .local object Cat .local object felix newclass Cat, Cat P2 = Cat S0 = init callmeth felix = P0 #... end .end ... But haven't figured out the magic formula yet That code above gives: Method 'init' not found in file '(unknown file)' near line -1 (If anyone can post a working example of the code above I'd really appreciate it!) Sincerely, Michal J Wallace Sabren Enterprises, Inc. - contact: [EMAIL PROTECTED] hosting: http://www.cornerhost.com/ my site: http://www.withoutane.com/ --
Re: how do I instantiate? -- was: Objects!
Michal Wallace writes: On Tue, 2 Dec 2003, Dan Sugalski wrote: *) Creating new objects involves calling the -init vtable entry *on the class*. Because of this each class gets a custom vtable where the init method has been swapped out for one (from objects.c) that creates a new object instead. Well, cool! How do I this from parrot? I've been trying things along the lines of: .sub _main .local object Cat .local object felix newclass Cat, Cat P2 = Cat S0 = init callmeth felix = P0 #... end .end Should go something like this: .sub _main .local object Cat .local object felix newclass Cat, Cat find_type $I0, Cat felix = new $I0 # ... .end But note that objects are unfinished. I ran into a certain problem when I assumed that attributes could be any type of data; not so -- they can only be integers (at the moment). I needed object support right away, so I simulated using a hash. The hash has a CLASS key which holds the class to which it belongs. I then use this to get the methods. Luke ... But haven't figured out the magic formula yet That code above gives: Method 'init' not found in file '(unknown file)' near line -1 (If anyone can post a working example of the code above I'd really appreciate it!) Sincerely, Michal J Wallace Sabren Enterprises, Inc. - contact: [EMAIL PROTECTED] hosting: http://www.cornerhost.com/ my site: http://www.withoutane.com/ --
Re: how do I instantiate? -- was: Objects!
On Wed, 7 Jan 2004, Luke Palmer wrote: Should go something like this: .sub _main .local object Cat .local object felix newclass Cat, Cat find_type $I0, Cat felix = new $I0 # ... .end Thanks, but that doesn't work either. :/ The new op expects an identifier. It won't take a VAR, IREG, or REG. But note that objects are unfinished. I ran into a certain problem when I assumed that attributes could be any type of data; not so -- they can only be integers (at the moment). I needed object support right away, so I simulated using a hash. The hash has a CLASS key which holds the class to which it belongs. I then use this to get the methods. I'm not even trying to get objects working yet. I just need something that'll let me run setprop on it so my generators can make iterator things with a .next() attached to them... I was using ParrotObjects and ParrotClasss for a while but now you can't make a new ParrotObject directly either. :/ Incidentally, anyone know why not? In python or javascript it's easy to just create an object of no particular class just to have a place to stick things. foo = object() foo.x = 1 It was working fine in parrot too, but then it went away. :/ Sincerely, Michal J Wallace Sabren Enterprises, Inc. - contact: [EMAIL PROTECTED] hosting: http://www.cornerhost.com/ my site: http://www.withoutane.com/ --
Re: how do I instantiate? -- was: Objects!
Michal Wallace writes: On Wed, 7 Jan 2004, Luke Palmer wrote: Should go something like this: .sub _main .local object Cat .local object felix newclass Cat, Cat find_type $I0, Cat felix = new $I0 # ... .end Thanks, but that doesn't work either. :/ The new op expects an identifier. It won't take a VAR, IREG, or REG. Er, sorry, that's IMCC's fault. This works: new felix, $I0 But note that objects are unfinished. I ran into a certain problem when I assumed that attributes could be any type of data; not so -- they can only be integers (at the moment). I needed object support right away, so I simulated using a hash. The hash has a CLASS key which holds the class to which it belongs. I then use this to get the methods. I'm not even trying to get objects working yet. I just need something that'll let me run setprop on it so my generators can make iterator things with a .next() attached to them... I was using ParrotObjects and ParrotClasss for a while but now you can't make a new ParrotObject directly either. :/ I know PerlArray accepts and stores properties: my compiler uses them. PerlHash probably does too. And thanks again for all the work you're doing on Python :-) Luke Incidentally, anyone know why not? In python or javascript it's easy to just create an object of no particular class just to have a place to stick things. foo = object() foo.x = 1 It was working fine in parrot too, but then it went away. :/ Sincerely, Michal J Wallace Sabren Enterprises, Inc. - contact: [EMAIL PROTECTED] hosting: http://www.cornerhost.com/ my site: http://www.withoutane.com/ --