Template for a table editor [▣=▣ ].
04-13-2019, 12:26 PM (This post was last modified: 04-19-2019 02:20 PM by compsystems.)
Post: #1
 compsystems Senior Member Posts: 1,184 Joined: Dec 2013
Template for a table editor [▣=▣ ].
Hello

There is a very useful data type TABLE, it works in a similar way to the Python DICTIONARY, unlike a matrix that addresses each position by means of a "coordinate" (rows, columns), a table is addressed by a label that can be a number, a string of characters or a coordinate.

The TABLE editor is similar to the matrix editor. Simply for each position there would be two entries one for the label and one for the content.

The template for the table editor will be included in an icon next to the rest of the templates (key C / templates)

Examples

PHP Code:
tbl1:= table( (0,0)=9, p1=[9,8,7], 3=-10,"b"=20,"c"=30,"d"=40,"a"=10) [enter] returnstable(  3 = -10,  p1 = [9,8,7],  (0,0) = 9,  "a" = 10,  "b" = 20,  "c" = 30,  "d" = 40)

PHP Code:
tbl1["a"] [enter]  returns 10tbl1[3] [enter]  returns -10tbl1[(0,0)] [enter]  returns  9tbl1[p1] [enter]  returns  [9,8,7]

LO SUFICIENTEMENTE BUENO ES ENEMIGO DE LA EXCELENCIA.
04-17-2019, 03:10 PM
Post: #2
 toml_12953 Senior Member Posts: 1,215 Joined: Dec 2013
RE: Template for a table editor [▣=▣ ].
(04-13-2019 12:26 PM)compsystems Wrote:  Hello

There is a very useful data type TABLE, it works in a similar way to the Python DICTIONARY, unlike a matrix that addresses each position by means of a "coordinate" (rows, columns), a table is addressed by a label that can be a number, a string of characters or a coordinate.

The TABLE editor is similar to the matrix editor. Simply for each position there would be two entries one for the label and one for the content.

The template for the table editor will be included in an icon next to the rest of the templates (key C / templates)

Examples

tbl1:= table( (0,0)=[9,8,7], 3=-10,"b"=20,"c"=30,"d"=40,"a"=10) [enter] returns

table(
(0,0)=[9,8,7],
3 = -10,
"a" = 10,
"b" = 20,
"c" = 30,
"d" = 40
)

tbl1["a"] [enter] returns 10
tbl1[3] [enter] returns -10
tbl1[(0,0)] [enter] returns [9,8,7]

Supposedly the TABLE command is buggy and will be deprecated at some point in the future. I can't find the thread right now but when I saw the TABLE command I got all excited until I read that it will be going away.

Tom L
I think therefore I am-Descartes
I think therefore you are-Gorgias
You're not here to think-Army Sergeant
04-17-2019, 05:58 PM
Post: #3
 compsystems Senior Member Posts: 1,184 Joined: Dec 2013
RE: Template for a table editor [▣=▣ ].
the TABLE command works perfectly in Xcas, the problem is that in the hpprime it converts the position from (0,0) to (1,1) and then interprets it as a complex number. 1 + 1*i

LO SUFICIENTEMENTE BUENO ES ENEMIGO DE LA EXCELENCIA.
04-17-2019, 10:52 PM
Post: #4
 ijabbott Senior Member Posts: 720 Joined: Jul 2015
RE: Template for a table editor [▣=▣ ].
(04-17-2019 05:58 PM)compsystems Wrote:  the TABLE command works perfectly in Xcas, the problem is that in the hpprime it converts the position from (0,0) to (1,1) and then interprets it as a complex number. 1 + 1*i

Not that perfect. There is no way to delete (purge) table entries, for example (as far as I can tell).

— Ian Abbott
04-19-2019, 02:18 PM
Post: #5
 compsystems Senior Member Posts: 1,184 Joined: Dec 2013
RE: Template for a table editor [▣=▣ ].
Note: a coordinate as position cannot contain an array or list, to delete an element you use PURGE function

PHP Code:
tbl1:= table( (0,0)=9, p1=[9,8,7], 3=-10,"b"=20,"c"=30,"d"=40,"a"=10) [enter] returnstable(  3 = -10,  p1 = [9,8,7],  (0,0) = 9,  "a" = 10,  "b" = 20,  "c" = 30,  "d" = 40)

PHP Code:
purge( tbl1["a"] ) [enter] 1(Done)tbl1 [enter] returnstable(  3 = -10,  p1 = [9,8,7],  (0,0) = 9,  "b" = 20,  "c" = 30,  "d" = 40)

LO SUFICIENTEMENTE BUENO ES ENEMIGO DE LA EXCELENCIA.
04-27-2019, 02:36 AM (This post was last modified: 05-20-2019 11:52 PM by compsystems.)
Post: #6
 compsystems Senior Member Posts: 1,184 Joined: Dec 2013
RE: Template for a table editor [▣=▣ ].
Another example of how to use the data in the table.

PHP Code:
phonebook := table("John":0, "Jack":0, "Jill":0 )
[enter]
PHP Code:
table("Jack" = 0,"Jill" = 0,"John" = 0)

PHP Code:
phonebook["John"],phonebook["Jack"],phonebook["Jill"]
[enter]
PHP Code:
0,0,0

PHP Code:
phonebook["John"] := 938477566phonebook["Jack"] := 938377264phonebook["Jill"] := 947662781
[enter]
"Done","Done","Done"

PHP Code:
phonebook
[enter]
PHP Code:
table("Jack" = 938377264,"Jill" = 947662781,"John" = 938477566)

PHP Code:
phonebook["John"],phonebook["Jack"],phonebook["Jill"]
[enter]
PHP Code:
938477566, 938377264, 947662781

Alternatively, a table can be initialized with the same values in the following notation:

PHP Code:
phonebook := table("John" : 938477566,"Jack" : 938377264,"Jill" : 947662781)
[enter]
PHP Code:
table("Jack" = 938377264,"Jill" = 947662781,"John" = 938477566)

phonebook["jaime"] := 3187935015

Iterating over tables

Tables can be iterated over, just like a list. However, a table, unlike a list, does not keep the order of the values stored in it. To iterate over key value pairs, use the following syntax:

PHP Code:
for name in phonebook:    print( "Phone number of " + name + " is " + phonebook[name])
[enter]

PHP Code:
Phone number of Jack is 938377264Phone number of Jill is 947662781Phone number of John is 938477566

Removing a value
To remove a specified index, use either one of the following notations:

PHP Code:
del phonebook["John"]
[enter]

phonebook [enter]
PHP Code:
table("Jack" = 938377264,"Jill" = 947662781)

or
PHP Code:
phonebook.pop("Jill")
[enter]

phonebook [enter]
PHP Code:
table("Jack" = 938377264)

LO SUFICIENTEMENTE BUENO ES ENEMIGO DE LA EXCELENCIA.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)