
Data Structure

This illustrates a data structure, a means of storing data within a program.

You may see other such structures in the Data Structures category.


Task

Create a compound data type:

  Point(x,y) 



A compound data type is one that holds multiple independent values.



Related task

   Enumeration


See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


with javascript_semantics 
enum x,y
type point(object p)
    return sequence(p) and length(p)=y and atom(p[x]) and atom(p[y])
end type
 
point p = {175,3.375}
p[x] -= p[y]*20
puts(1,"point p is ")
?p
printf(1,"p[x]:%g, p[y]:%g\n",{p[x],p[y]})
p[x] = 0            -- fine
p[y] = "string"     -- run-time error (not pwa/p2js)
