Re: Structs

new topic     » goto parent     » topic index » view thread      » older message » newer message

data-types

A data-type "limits the values permitted for an object."

Everything is an object; an object is the unlimited data-type.

Two fundamental objects: atom, sequence

Variations on the two fundamentals:

     
atom --> integer 
sequence --> string , struct 
     
type --> user defined data-type 

Question? Interfacing with 'c'; can special data-types be invented to make interfacing with an .so easier?


A struct is "a sequence; each item has a data-type; each item has a named index; default values may be assigned to an item."

struct zoo 
    string name = "" 
    integer legs = 0 
    atom  height = 0 
    atom speed = 0 
end struct 

This syntax creates a zoo struct identifier, a zoo() function for testing, and a zoo_new() function for initialization, and local enums (name,legs,height,speed) that can be used with dot-notation.

  • The struct name zoo is used to declare an new instance of the zoo struct-sequence.
zoo critter 
  • The zoo_new() function assigns default values
critter = zoo_new() 
? critter 
--> { "", 0, 0, 0 } 
 
 
zoo fauna = zoo_new( name := "osterich" ) 
? fauna 
--> { "osterich", 0, 0, 0 } 
  • The zoo() function tests if an object belongs to a struct.
? zoo( critter ) 
--> true 
 
? zoo( 3.14 ) 
--> false 
  • You can subscript struct items
critter[1] = "emu: 
critter[2] = 2 
critter[3] = 1.9 
critter[4] = 50 
  • you can use dot-notation with struct items
critter.name = "emu" 
critter.legs = 2 
critter.height = 1.9 
critter.speed = 50 
 
 
? critter 
--> { "emu", 2, 1.9, 50 } 

_tom

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu