[REBOL] rebol weak points (i think) Re:(3)
[EMAIL PROTECTED] wrote: >no. The Math/Pie you have created is an instance variable not a static >variable. It is associated with an instance of the class, not the class >itself. A static variable means that there is a single copy of this variable >associated with class itself. You do not need to instantiate a class to use >static variable. You have it backwards. REBOL doesn't have classes. OOP in REBOL is prototype/delegation based, like Self, NewtonScript or JavaScript - not class-based like C++, Smalltalk or Java. Objects in REBOL are all unique. Their behavior is defined within themselves using static variables, rather than through their class. They are created from prototypes, not classes. Constructors are just functions. You don't inherit the features of a class, you call them directly - this is known as delegation. All fields are static - any "instance" objects you create call the "class" objects directly. This style of object-oriented programming, used properly, can be more efficient than class-based programming. If you really need classes they're a simple design pattern away. >For example: > >make-circle: make func [ > radius > /local blah-blah-blah > /static num_circles ;let's say this is how you create static var. >] [ > num_circles: num_circles + 1 ;this may not be correct but you get the >idea... > return make object! [ > ;object code goes here > ] >] There are techniques for making persistent values in functions - most of them are arcane (but fun). Functions don't have static variables as such but you can embed structured data in the code of the function. Most of the time it's better to use objects. Try this: circle-class: make object! [ num-circles: 0 new: func [value [number!]] [ num-circles: num-circles + 1 make object! compose [ class: (self) radius: value num-circles: func [] [class/num-circles] ] ] ] (skipped a little...) >The main disadvantage of having static variables is that perhaps it is an >unnecessary complication. But I don't think so. Maybe because I come from >java/javascript background. I'm still wondering though if there is a way to >have static variables that I don't know. It's interesting that you mention Java and JavaScript in the same sentence here. Java is class-based like C++. JavaScript is more like REBOL - all variables are static, constructor functions, class factory objects instead of classes. The object model of JavaScript has been traditionally confusing for those who think OOP is only class-based... >Regardless, the main problem that I wonder about is if rebol is suited for >modular programming where people reuse other people's functions/code. Since >everything is either global or local, it seems as though it would be >unnatural to use rebol in this way. Java has packages and stuff... Coming from a background of Oberon, Delphi and such (among many others) I'd have to agree. Fortunately RT has listened :) Look at this: http://www.rebol.com/reps/rep002.html It's a little outdated - many changes have purportedly been made already but they haven't been codified yet. I gather security support will be much improved. Still, it's a taste of things to come. I'm looking forward to it :) >Perhaps I am not thinking straight and have too much java in my >blood (which I have been doing to much of lately and finally got >sick of all the abstractions that got in the way of doing simple >stuff!!) Tell me about it :( I'm having the opposite problem. I just got put on a project that is being done with ColdFusion, a web template language like ASP. I can't go 5 minutes without running into some limitation that would be trivial to overcome with REBOL. Maybe I can do the next round with REBOL/Serve when it comes out... Brian
[REBOL] rebol weak points (i think) Re:(3)
Hi, Rishi... Just a couple of points re REBOL objects that may be of some help: [EMAIL PROTECTED] wrote: > > no. The Math/Pie you have created is an instance variable not a > static variable. It is associated with an instance of the class, > not the class itself. A static variable means that there is a > single copy of this variable associated with class itself. You do > not need to instantiate a class to use static variable... > 1) The distinction to which you keep referring -- "class variable" vs. "instance variable" -- doesn't exist at all in REBOL because REBOL doesn't use the class-based object model of Java or Smalltalk. There are other ways to think of objects than simply as instances of "classes". In NewtonScript and Self, for example, objects exist completely as standalone entities without any enveloping class. Instead, in both of those langauges, objects can have "prototypes", other objects to which they refer for common (or default) attributes and methods. In those languages, the object-to-prototype relationship is maintained throughout the lifetime of an object, so that changes to an attribute/method of an object are visible within any other objects that refer to the first object as their prototype (and that have not overridden the attribute/method involved). In REBOL, an object is a standalone entity. It may be created directly, using make object! ... or may be created using another object as a model or specification. However, it is cloned at the time of creation, and no longer maintains a relation to its model object. For example: >> ob1: make object! [ [attr: 23 [meth: func [] [print attr: attr + 1] [] >> kenobi: make ob1 [] >> ob1/meth 24 >> ob1/meth 25 >> ob1/meth 26 >> kenobi/meth 24 >> kenobi/meth 25 >> kenobi/meth 26 >> ob1/attr: 2 == 2 >> ob1/meth 3 >> ob1/meth 4 >> kenobi/meth 27 >> kenobi/meth 28 >> Notice that kenobi has its own copy of attr and meth which are independent of those in ob1 even though no explicit overriding was done at the creation of kenobi . Therefore all objects are created equal, without any "class" vs. "instance" distinction. Therefore the term "static" as used in Java or c++ is meaningless in REBOL. > > The main advantage of having static variables would be to prevent > name collisions and to group variables/functions that act on a > class (not an object) together for use in a more natural way. > > The main disadvantage of having static variables is that perhaps > it is an unnecessary complication. But I don't think so. Maybe > because I come from java/javascript background. I'm still wondering > though if there is a way to have static variables that I don't know. > > Regardless, the main problem that I wonder about is if rebol is > suited for modular programming where people reuse other people's > functions/code. Since everything is either global or local, it seems > as though it would be unnatural to use rebol in this way... > 2) I frequently use objects in my own REBOL programming to get exactly the benefit you're looking for: to partition the namespace. Most of my REBOL source files define objects to encapsulate all of the variables, subordinate functions, parse pattern blocks, etc. that make up the details of the main idea of the script. A limited number (often only one!) of the functions within the object are actually intended for use by the clients of the object. It's a handy way to structure and modularize libraries of code (and DOES offer a alternative to global and local). I write code in this fashion when I want to reuse it myself across many independent projects. Hope this helps! -jn-
[REBOL] rebol weak points (i think) Re:(3)
> I'd also be curious to know why rebol can't be compiled. Try compiling this: do ask "Please enter some Rebol code: " Andrew Martin ICQ: 26227169 http://members.xoom.com/AndrewMartin/ -><-
[REBOL] rebol weak points (i think) Re:(3)
hi ho hi ho hi ho hi ... please note all.. as usual with functions, with objects to.. (i know you know, why else clone-object.. :) a: make object! [static: make object! [pie: 20]] and a/static/pie is static.. should one know again :) Volker [rebol [] ?do: func [todo] [prin ">> do " probe :todo prin "== " probe do todo] a: make object! [static: make object! [pie: 20]] b: make a [] c: make a [] ? a ? b print "--" ?do [b/static/pie: 10] ? a ? b ] > A is an object of value: make object! [ static: make object! [ pie: 20 ] ] B is an object of value: make object! [ static: make object! [ pie: 20 ] ] -- >> do [b/static/pie: 10] == 10 A is an object of value: make object! [ static: make object! [ pie: 10 ] ] B is an object of value: make object! [ static: make object! [ pie: 10 ] ] [EMAIL PROTECTED] wrote on 9-Sep-2000/19:12:06-7:00 > no. The Math/Pie you have created is an instance variable not a static > variable. It is associated with an instance of the class, not the class > itself. A static variable means that there is a single copy of this variable > associated with class itself. You do not need to instantiate a class to use > static variable. For example: > > make-circle: make func [ > radius > /local blah-blah-blah > /static num_circles ;let's say this is how you create static var. > ] [ > num_circles: num_circles + 1 ;this may not be correct but you get the > idea... > return make object! [ > ;object code goes here > ] > ] > > small-circle: make-math(2) > large-circle: make-math(100) > print make-circle/num-circles ;this should hypothetically print out 2 > print num-circles ;should print error > > Unfortunately, it would not make sense to add a static option the way I have > done it since not all functions return objects. > > Anyway, the fact that rebol does not have static variables and static > functions is no big deal. It was probably a concious decision not to include > it. > > The main advantage of having static variables would be to prevent name > collisions and to group variables/functions that act on a class (not an > object) together for use in a more natural way. > > The main disadvantage of having static variables is that perhaps it is an > unnecessary complication. But I don't think so. Maybe because I come from > java/javascript background. I'm still wondering though if there is a way to > have static variables that I don't know. > > Regardless, the main problem that I wonder about is if rebol is suited for > modular programming where people reuse other people's functions/code. Since > everything is either global or local, it seems as though it would be > unnatural to use rebol in this way. Java has packages and stuff...perhaps I > am not thinking straight and have too much java in my blood (which I have > been doing to much of lately and finally got sick of all the abstractions > that got in the way of doing simple stuff!!) > > Rishi > > > - Original Message - > From: <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Saturday, September 09, 2000 6:03 PM > Subject: [REBOL] rebol weak points (i think) Re: > > > > Rishi wrote: > > > Math.pi=20 > > > > >> Math: make object! [ > > [Pie: 20 > > [] > > >> Math/Pie > > == 20 > > >> Pie > > ** Script Error: Pie has no value. > > ** Where: Pie > > >> > > > > Andrew Martin > > ICQ: 26227169 > > http://members.xoom.com/AndrewMartin/ > > -><- > > > > > > >
[REBOL] rebol weak points (i think) Re:(3)
Hi Rishi, I think, that you are missing only complications here. What you are saying is, that Math below is an instance of Object! datatype. You are right. You are saying, that you would prefer it to be a class. But classes in a lot of languages (except for C++, Java, ..., AFAIK) are instances of object datatype too. There is only a little other language classes could do for you and Rebol objects can't, IMHO. (You can even create a Rebol class hierarchy using Rebol objects, as I demonstrated.) Regards Ladislav > no. The Math/Pie you have created is an instance variable not a static > variable. It is associated with an instance of the class, not the class > itself. A static variable means that there is a single copy of this variable > associated with class itself. You do not need to instantiate a class to use > static variable. For example: > > make-circle: make func [ > radius > /local blah-blah-blah > /static num_circles ;let's say this is how you create static var. > ] [ > num_circles: num_circles + 1 ;this may not be correct but you get the > idea... > return make object! [ > ;object code goes here > ] > ] > > small-circle: make-math(2) > large-circle: make-math(100) > print make-circle/num-circles ;this should hypothetically print out 2 > print num-circles ;should print error > > Unfortunately, it would not make sense to add a static option the way I have > done it since not all functions return objects. > > Anyway, the fact that rebol does not have static variables and static > functions is no big deal. It was probably a concious decision not to include > it. > > The main advantage of having static variables would be to prevent name > collisions and to group variables/functions that act on a class (not an > object) together for use in a more natural way. > > The main disadvantage of having static variables is that perhaps it is an > unnecessary complication. But I don't think so. Maybe because I come from > java/javascript background. I'm still wondering though if there is a way to > have static variables that I don't know. > > Regardless, the main problem that I wonder about is if rebol is suited for > modular programming where people reuse other people's functions/code. Since > everything is either global or local, it seems as though it would be > unnatural to use rebol in this way. Java has packages and stuff...perhaps I > am not thinking straight and have too much java in my blood (which I have > been doing to much of lately and finally got sick of all the abstractions > that got in the way of doing simple stuff!!) > > Rishi > > > - Original Message - > From: <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Saturday, September 09, 2000 6:03 PM > Subject: [REBOL] rebol weak points (i think) Re: > > > > Rishi wrote: > > > Math.pi=20 > > > > >> Math: make object! [ > > [Pie: 20 > > [] > > >> Math/Pie > > == 20 > > >> Pie > > ** Script Error: Pie has no value. > > ** Where: Pie > > >> > > > > Andrew Martin > > ICQ: 26227169 > > http://members.xoom.com/AndrewMartin/ > > -><- > > > > > >
[REBOL] rebol weak points (i think) Re:(3)
On Sat, 9 Sep 2000 [EMAIL PROTECTED] wrote: > make-circle: make func [ > radius > /local blah-blah-blah > /static num_circles ;let's say this is how you create static var. > ] [ > num_circles: num_circles + 1 ;this may not be correct but you get the > idea... > return make object! [ > ;object code goes here > ] > ] > You can use this: make-circle: func [radius /local num_circles] [ num_circles: [0] num_circles/1: num_circles/1 + 1 return make object! [ num: num_circles rad: radius ] ] >> probe make-circle 99 make object! [ num: [1] rad: 99 ] >> probe make-circle 88 make object! [ num: [2] rad: 88 ] or this: circle-maker: make object! [ num-circles: 0 set 'make-circle func [radius] [ num-circles: num-circles + 1 return make object! [ num: num-circles rad: radius ] ] ] >> circle-maker/num-circles == 0 >> probe make-circle 5 make object! [ num: 1 rad: 5 ] >> probe make-circle 3 make object! [ num: 2 rad: 3 ] >> circle-maker/num-circles == 2 CU, Frank
[REBOL] rebol weak points (i think) Re:(3)
Rebol Modules have been discussed by Carl Sassenrath. They should cover what you require, if an 'object! doesn't quite fit what you want. I'm getting a friend who has got a bigger collection of emails to post it to the list again or to find which message it was. Andrew Martin ICQ: 26227169 http://members.xoom.com/AndrewMartin/ -><-