1. Re: Implementing structures

Irv replied to my proposals:

>These seem more OO than what we have been discussing.

OO looks a lot like structures, although it's not the same thing. Not =
being able to actually change the syntax puts a certain crimp on what =
you can do.

>Looking thru some old Pascal code, I find structures used
>extensively. Everywhere, actually. Quite useful, and makes
>for cleaner code.
>An example converted to Euphorish:
>structure listbox
>   coords location -- we're assuming type coords
>   coords size       -- is already defined as
>   sequence caption -- a structure with elements
>   atom maxlen        -- x and y, type checked to be
>   ....etc.               -- within valid range for screen coords.

I hadn't included that part in my examples, but here's the equivalent, =
using the proposed syntax:

   constant structure( "listbox" )     -- new type of structure
      element( "location", "coords" )  -- already defined
      element( "size", "coords" )      -- ditto
      element( "caption", "sequence" ) -- gets type checking
      element( "maxlen", "atom" )      -- ditto
      ... etc

Since we are passing the data type along with the element name, we know =
what test to perform during data checking.

The "structure in a structure" is where these calls get expensive.
     =20
>>
>>assignments would be done in the normal way:
>>with listbox
>>  location =3D {1,1}
>>  size =3D {100,100}
>>  caption =3D "My List"
>>  maxlen =3D 25
>>end listbox

My examples might look like:

   set( "listbox.location.x", 1 )
   set( "listbox.location.y", 1 )
   set( "listbox.size.x", 100 )  =20
   set( "listbox.size.y", 100 )
   set( "listbox.caption", "My List" )
   set( "listbox.maxlen", 25 )

If you wanted to implement a "with" procedure, it could look like:

   with( "listbox" )
      set( ".location.x", 1 )
      set( ".location.y", 1 )
      set( ".size.x", 100 )  =20
      set( ".size.y", 100 )
      set( ".caption", "My List" )
      set( ".maxlen", 25 )

The *is* possible to make the code do this:

   set( "listbox.location", {1,1} )
   set( "listbox.size", {100,100} )  =20
   set( "listbox.caption", "My List" )
   set( "listbox.maxlen", 25 )

or even:

   with( "listbox" )
      set( ".location", {1,1} )
      set( ".size", {100,100} )  =20
      set( ".caption", "My List" )
      set( ".maxlen", 25 )

But it makes some implict assumptions about the structure ( x =3D =
element 1, y =3D 2, etc.). If you ever changed the order of your =
structure, the code would break. So I'm not sure I'm a fan of that =
option.

>>You could use the same names (location...etc) for
>>other gadgets:
>>  messagebox:location =3D {12,16}

Yeah, you get that, too. Same reservations about the multiple =
assignment, though.

>>The difference would be you could refer to listbox as a unit
>>(like any sequence) but assignments would be type checked,
>>i.e. location could not be assigned 1, or "Here". and maxlen
>>couldn't be "Lou" or {2,1} (Oh,yeah: no more LOCATION  =3D 1,
>>SIZE=3D2, constant declarations needed, either)

You get that under my proposed system - if you can stomach the syntax. =
Since the names are maintained by the element() function, you don't need =
to worry about them at all.


>>I am not at all sure this could be implemented in any way
>>other than a change to Euphoria itself. Hope I am wrong.

If you want to use something other than functions and procedures, better =
start working on a pre-processor.

>Saturday -- ok, maybe Sunday. Depends upon all sorts of
>things, including the barometric pressure...

Great! I'm holding my breath.

-- David Cuny

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu