Table Example
Model was written in NetLogo 5.0.4
•
Viewed 811 times
•
Downloaded 57 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
extensions [table] globals [t] to test1 clear-all ;; create the table set t table:make ;; table:put
;; associate with table:put t 0 "test-value" table:put t "test-key" 1 ;; table:getin the table
;; reports the value in the table associated with ;; if there is no value set for the key, returns 0 if table:get t 0 != "test-value" [ user-message "should be \"test-value\"" ] if table:get t "test-key" != 1 [ user-message "should be 1" ] ;; table:keys ;; reports all keys in the table as a list output-print table:keys t ;; table:length
;; reports the number of key->value pairs in the table output-print table:length t ;; table:has-key?
;; reports true if there is a value associated with the key in the table if ( not table:has-key? t 0 ) [ user-message "should contain 0" ] if ( not table:has-key? t "test-key" ) [ user-message "should contain test-key" ] if ( table:has-key? t "arbitrary" ) [user-message "should not have the arbitrary key" ] ;; you can print a table output-print t ;; table:clear ;; clears all key->value associations in the table table:clear t if table:length t != 0 [ user-message "should have no entries" ] end ; Public Domain: ; To the extent possible under law, Uri Wilensky has waived all ; copyright and related or neighboring rights to this model.
There are 3 versions of this model.
Attached files
File Type Description Last updated Table Example.png preview Preview for 'Table Example' over 11 years ago, by Uri Wilensky Download This model does not have any ancestors.
This model does not have any descendants.