home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / programs / programming / wimpworks / Editors / !Structure / !Help next >
Encoding:
Text File  |  1998-09-03  |  3.4 KB  |  98 lines

  1.  
  2.   Structure    Public Domain         UNSUPPORTED SOFTWARE
  3.   ~~~~~~~~~    by Andrew Flegg       mailto:andrew@jaffasoft.co.uk
  4.                v0.01 (20-Aug-1998)   http://www.jaffasoft.co.uk/
  5.  
  6.   This demonstration (and a possibly early version) of adding C-like
  7.   structures to WimpWorks.
  8.  
  9.   Copy it into !WimpWorks.Resources.Editors to install it and restart
  10.   WWv2.
  11.  
  12.   The actual structures themselves will be defined at design-time using
  13.   this editor, however in this simple version there is only one structure
  14.   available - Person.
  15.  
  16.   Structures are a way of packaging related variables together, eg.
  17.   the Person structure represents data on a person for use in a linked
  18.   list; their name, age and a pointer to the next item in the list.
  19.  
  20.   As BASIC isn't heavily typed a form of "cast" operator is used to tell
  21.   the parser that a given integer variable is actually a pointer to a
  22.   structure.
  23.  
  24.   Structures are created by using NEW( <structure name> ) and assigning
  25.   the result to an integer variable (ie. one ending in %), <structure
  26.   name> would be 'Person' - no quotes.
  27.  
  28.   To remove the structure after use and free the memory (there is no
  29.   garbage collector as in Java) use DESTROY( <pointer> ), where <pointer>
  30.   is the result of NEW.
  31.  
  32.   The important bit of structures is accessing the components though,
  33.   to do this append the structure name to the pointer and then the individual
  34.   component (seperated by a full stop '.'). These new forms of variable can
  35.   be assigned values, passed to subroutines etc.
  36.  
  37.   The pointer can also be passed about (eg. to subroutines).
  38.  
  39.   eg.
  40.  
  41.   me% = NEW(Person)
  42.  
  43.   me%Person.name$ = "Andrew"       : REM Assign the name (<256 chars)
  44.   me%Person.age%  = 42             : REM The age
  45.   me%Person.next% = -1             : REM No next item in the list
  46.  
  47.   IF FNage_last_year(me%) = you%Person.age% THEN
  48.       ' me% is a year older than you%
  49.   ENDIF
  50.  
  51.   DESTROY(me%)
  52.  
  53.  
  54.   Current Limitations
  55.   -------------------
  56.  
  57. 1 Arrays of structures can be created, however the pointer must be
  58. - assigned to a temporary integer variable, eg.
  59.  
  60.   DIM people%(20)
  61.  
  62.   FOR loop%=1 TO 20
  63.       people%(loop%) = NEW(Person)
  64.   
  65.       ' Can't do people%(loop%)Person.name$ so...
  66.       temp%             = people%(loop%)
  67.       temp%Person.name$ = "Fred"
  68.   NEXT
  69.  
  70.  
  71. 2 Arrays can't be put into a structure - a dynamic structure like
  72. - a linked list should be used instead.
  73.  
  74.  
  75. 3 The parser replacement has been designed to be not *that* hard to
  76. - generalise and produce a complete structure implementation: however,
  77.   unions, arrays etc. still need to be designed. The generalisation
  78.   shouldn't be too hard as it will most likely be a linked list of
  79.   structures with pointers to member items.
  80.  
  81.  
  82. 4 The ability to attach subroutines to these would also be extremely
  83. - useful and be one step on the road to complete object orientation.
  84.   Syntax could be of the form:
  85.  
  86.      FNme%Person.age_last_year or possibly me%Person.FNage_last_year
  87.  
  88.   Comments welcome. How this would impact the parser would need
  89.   further analysis.
  90.  
  91. --------------------------------------------------------------------------
  92. This software is public domain, it may be used freely in any product,
  93. modified, disected etc. No warranty is given or implied and this is NOT
  94. an official Jaffa Software product. Parts of this software may form part
  95. of future Jaffa Software products - in which case they will then be
  96. supported. Until then the only support will be via the WimpWorks mailing
  97. list (see http://www.jaffasoft.co.uk/maillist.html)
  98.