home *** CD-ROM | disk | FTP | other *** search
-
- Structure Public Domain UNSUPPORTED SOFTWARE
- ~~~~~~~~~ by Andrew Flegg mailto:andrew@jaffasoft.co.uk
- v0.01 (20-Aug-1998) http://www.jaffasoft.co.uk/
-
- This demonstration (and a possibly early version) of adding C-like
- structures to WimpWorks.
-
- Copy it into !WimpWorks.Resources.Editors to install it and restart
- WWv2.
-
- The actual structures themselves will be defined at design-time using
- this editor, however in this simple version there is only one structure
- available - Person.
-
- Structures are a way of packaging related variables together, eg.
- the Person structure represents data on a person for use in a linked
- list; their name, age and a pointer to the next item in the list.
-
- As BASIC isn't heavily typed a form of "cast" operator is used to tell
- the parser that a given integer variable is actually a pointer to a
- structure.
-
- Structures are created by using NEW( <structure name> ) and assigning
- the result to an integer variable (ie. one ending in %), <structure
- name> would be 'Person' - no quotes.
-
- To remove the structure after use and free the memory (there is no
- garbage collector as in Java) use DESTROY( <pointer> ), where <pointer>
- is the result of NEW.
-
- The important bit of structures is accessing the components though,
- to do this append the structure name to the pointer and then the individual
- component (seperated by a full stop '.'). These new forms of variable can
- be assigned values, passed to subroutines etc.
-
- The pointer can also be passed about (eg. to subroutines).
-
- eg.
-
- me% = NEW(Person)
-
- me%Person.name$ = "Andrew" : REM Assign the name (<256 chars)
- me%Person.age% = 42 : REM The age
- me%Person.next% = -1 : REM No next item in the list
-
- IF FNage_last_year(me%) = you%Person.age% THEN
- ' me% is a year older than you%
- ENDIF
-
- DESTROY(me%)
-
-
- Current Limitations
- -------------------
-
- 1 Arrays of structures can be created, however the pointer must be
- - assigned to a temporary integer variable, eg.
-
- DIM people%(20)
-
- FOR loop%=1 TO 20
- people%(loop%) = NEW(Person)
-
- ' Can't do people%(loop%)Person.name$ so...
- temp% = people%(loop%)
- temp%Person.name$ = "Fred"
- NEXT
-
-
- 2 Arrays can't be put into a structure - a dynamic structure like
- - a linked list should be used instead.
-
-
- 3 The parser replacement has been designed to be not *that* hard to
- - generalise and produce a complete structure implementation: however,
- unions, arrays etc. still need to be designed. The generalisation
- shouldn't be too hard as it will most likely be a linked list of
- structures with pointers to member items.
-
-
- 4 The ability to attach subroutines to these would also be extremely
- - useful and be one step on the road to complete object orientation.
- Syntax could be of the form:
-
- FNme%Person.age_last_year or possibly me%Person.FNage_last_year
-
- Comments welcome. How this would impact the parser would need
- further analysis.
-
- --------------------------------------------------------------------------
- This software is public domain, it may be used freely in any product,
- modified, disected etc. No warranty is given or implied and this is NOT
- an official Jaffa Software product. Parts of this software may form part
- of future Jaffa Software products - in which case they will then be
- supported. Until then the only support will be via the WimpWorks mailing
- list (see http://www.jaffasoft.co.uk/maillist.html)
-