HyperMath

Structures Using Tables

Structures Using Tables

Previous topic Next topic No expanding text in this topic  

Structures Using Tables

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  

Table can also be used as a structure data type similar to other programming languages.  There are two ways to do this:

> t = {name = "Jane Doe", grade = 4.0}

Or equivalently:

> t = {} // Create an empty table first

> t.name = "Jane Doe"

> t.grade = 4.0

Once created, the fields can be accessed using the table.fieldname format as below:

> print(t.name)

Jane Doe

You can assign a table to a field, too.  For example, if you want to store all grades as an array:

> t.grade = {4.0, 3.5} // field grade is a table array now

> print(t.grade[1], t.grade[2])

4.0                3.5

Or, even a vector data type:

> t.grade = [4.0, 3.5] // field grade is a Vector now

> print(t.grade(1), t.grade(2))

4.0                3.5

Variables can also be assigned to fields.

Tables support a set of other functionalities.  See Vector and Matrix Operations for more information.