Comments and Questions
Click to Run Model
extensions [table] globals [t] to test1 clear-all ;; create the table set t table:make ;; table:put
;; associate withtable:put t 0 "test-value" table:put t "test-key" 1 ;; table:get in 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.
This model does not have any ancestors.
This model does not have any descendants.