Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: rebol weak points (i think) Re:(2)

From: g:santilli:tiscalinet:it at: 10-Sep-2000 18:12

Hello [rishi--picostar--com]! On 10-Set-00, you wrote: r> make-circle: make func [ r> radius r> /local blah-blah-blah r> /static num_circles ;let's say this is how you create r> static var. ] [ r> num_circles: num_circles + 1 ;this may not be correct but r> you get the idea... r> return make object! [ r> ;object code goes here r> ] r> ]
>> make-circle: func [radius /local num-circles] [
[ num-circles: [0] [ num-circles/1: num-circles/1 + 1 [ ]
>> make-circle 10
== [1]
>> make-circle 10
== [2]
>> make-circle 10
== [3]
>> make-circle 10
== [4]
>> make-circle 5
== [5] Notice that:
>> source make-circle
make-circle: func [radius /local num-circles][ num-circles: [5] num-circles/1: num-circles/1 + 1 ] We achieved static "variables" with self-modifying code. More elegantly:
>> circle-context: make object! [
[ num-circles: 0 [ set 'make-circle func [radius] [num-circles: num-circles + 1] [ ]
>> make-circle 1
== 1
>> make-circle 1
== 2
>> make-circle 1
== 3
>> make-circle 1
== 4 r> small-circle: make-math(2) large-circle: make-math(100) print r> make-circle/num-circles ;this should hypothetically print out r> 2 print num-circles ;should print error Indeed,
>> print num-circles
** Script Error: num-circles has no value. ** Where: print num-circles r> Anyway, the fact that rebol does not have static variables and r> static functions is no big deal. It was probably a concious r> decision not to include it. The fact is, is has no VARIABLES at all. :-) r> The main advantage of having static variables would be to r> prevent name collisions and to group variables/functions that r> act on a class (not an object) together for use in a more r> natural way. OOP mainly means complexity, this is what we learned from history. If you change your point of view, you'll discover that you can do MORE in REBOL than in most OO languages. REBOL surely has weak points, but IMHO not being OO is its major strong point. And I was an OOP fan before learning REBOL. Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/