Results 1 to 8 of 8

Thread: Compact Classes in Oxygen

  1. #1

    Compact Classes in Oxygen

    Proposed New OxygenSyntax

    OOP is renowned for being clunky & long-winded. But this compact syntax will I hope make objects really easy to build:

    Note the single line type definitions and the constructor prototype. Simple methods can also be done on a single line.

    Oxygen source code
    type vector single x,y,z
    type color  single r,g,b,a
    
    class body
      vector position,size,orientation,velocity,spin
      color ambient,diffuse,specular
      single density
      method mass() as single {return density * size.x * size.y * size.z}
      method constructor ( single* x,y,z) { size=>x,y,z : density=1 }
      method destructor () {}
    end class
    
    
    new body rock 1,2,3
    
    'putfile "t.txt", recordof rock
    print "mass of rock is " rock.mass
    del rock
    
    Internally the structure is flattened out snd the compiler sees it like this:

    $$  383 383 383 383 383 384 384 384 $$
    
    	mass 0 4 9 9 A , single
    	constructor 4 4 9 9 A #single#single#single@a1a1a1 sys
    	destructor 8 4 9 9 A , sys
    /
    	position 0 12 1 9 A , vector
    	position.x 0 4 1 9 A , single
    	position.y 4 4 1 9 A , single
    	position.z 8 4 1 9 A , single
     	size 12 12 1 9 A , vector
    	size.x 12 4 1 9 A , single
    	size.y 16 4 1 9 A , single
    	size.z 20 4 1 9 A , single
     	orientation 24 12 1 9 A , vector
    	orientation.x 24 4 1 9 A , single
    	orientation.y 28 4 1 9 A , single
    	orientation.z 32 4 1 9 A , single
     	velocity 36 12 1 9 A , vector
    	velocity.x 36 4 1 9 A , single
    	velocity.y 40 4 1 9 A , single
    	velocity.z 44 4 1 9 A , single
     	spin 48 12 1 9 A , vector
    	spin.x 48 4 1 9 A , single
    	spin.y 52 4 1 9 A , single
    	spin.z 56 4 1 9 A , single
     
      	ambient 60 16 1 9 A , color
    	ambient.r 60 4 1 9 A , single
    	ambient.g 64 4 1 9 A , single
    	ambient.b 68 4 1 9 A , single
    	ambient.a 72 4 1 9 A , single
     	diffuse 76 16 1 9 A , color
    	diffuse.r 76 4 1 9 A , single
    	diffuse.g 80 4 1 9 A , single
    	diffuse.b 84 4 1 9 A , single
    	diffuse.a 88 4 1 9 A , single
     	specular 92 16 1 9 A , color
    	specular.r 92 4 1 9 A , single
    	specular.g 96 4 1 9 A , single
    	specular.b 100 4 1 9 A , single
    	specular.a 104 4 1 9 A , single
     
    	density 108 4 1 9 A , single
    
    Charles
    Last edited by Charles Pegge; 04-03-2011 at 08:17.

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    Hi Charles,

    it looks good (very close to C#, so Petr is happy). Will the method/end method form be possible as well, or is that what you refer to as "clunky & long winded"

    There is one thing which could be seen little confusing:
    size=>x,y,z
    
    The direction of the arrow would suggest you export members of size UDT to variables x,y,z. But I guess it does the opposite?


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    Yes Petr,

    All prior layouts for classes and methods still apply. This is really an enhancement of Oxygen's reading skills.

    I too am concerned about "=>". This symbol is also used in FreeBasic for making multiple assignments. But the symbols one would naturally like to use have other meanings:

    a<=b a less than or equal to b
    a<-b a less than minus b
    a<--b a less predecremented b

    Other possibilities:

    a<<=b,c,d
    a<<<b,c,d
    a<=:b,c,d


    a<=b ' the compiler contextually deduces this is an assignment operator , not an arithmetical comparator.

    a=b,c,d 'Even smarter deduction.

    Any more ideas

    Charles

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    Hi Charles,

    I would like this syntax:
    size = x, y, z
    
    I have seen it in Python, and it looked quite natural to me. But I guess it will be a bit harder for parser to "detect" this type of assignment.


    Petr
    Last edited by Petr Schreiber; 04-03-2011 at 12:14.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    Okay Petr, the parser must be prepared to look far ahead, since multi assign is set up at the start, this could be interesting

    size = x*s^2,y*s^2 etc

    Charles

  6. #6
    After studying the compiler flow, I think the above option imposes too great a burden, so I have opted for "<=" as the preferred multiassign operator. Only 3 tiny changes to the compiler were required.

    Anyway, I hope this makes more sense with the arrow pointing in the right direction!

    I aim to release this along with wide string support in a few days time.


    single a[100]
    a[2]<=10,20,30,40,50,60,70
    print a[3]
    
    type vector single x,y,z
    vector size
    size<=1,2,3
    print size.y
    
    Charles
    Last edited by Charles Pegge; 04-03-2011 at 16:12.

  7. #7
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,153
    Rep Power
    736
    Ok I am looking forward to try it.


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  8. #8
    This is another mode of expressing structure. It uses nesting/hierarchy instead of inheritance. I envisage this would be most useful in the early stages of object development because it gives a compact view of an object's structure in one piece.

    class body
      color
      {
        ambient { single r,g,b,a }
        diffuse { single r,g,b,a }
        specular{ single r,g,b,a }
        single shininess
      }
      phys
      {
        pos   { single x,y,z }
        siz   { single x,y,z }
        rot   { single x,y,z }
        vel   { single x,y,z }
        spin  { single x,y,z }
        single dens
      }
      method mass() as single {return phys.dens * phys.siz.x * phys.siz.y * phys.siz.z}
      method constructor (single x,single y, single z) { phys.siz<=x,y,z : phys.dens=1 }
      method destructor () {}
    end class
    
    
    new body rock 1,2,3
    
    'print recordof rock
    print "Mass of rock is " rock.mass
    
    del rock
    
    Charles

Similar Threads

  1. Module classes
    By ErosOlmi in forum thinBasic vaporware
    Replies: 19
    Last Post: 02-12-2011, 12:15

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •