From 8b841148698ffcd7829876fc5c904f7337e453c4 Mon Sep 17 00:00:00 2001 From: Tuukka Turto Date: Sat, 25 Feb 2017 00:22:27 +0200 Subject: [PATCH] Document get in nested structure (#1236) --- docs/language/api.rst | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/language/api.rst b/docs/language/api.rst index eef48aa..a538f43 100644 --- a/docs/language/api.rst +++ b/docs/language/api.rst @@ -946,20 +946,25 @@ written without accidental variable name clashes. get --- -``get`` is used to access single elements in lists and dictionaries. ``get`` -takes two parameters: the *data structure* and the *index* or *key* of the -item. It will then return the corresponding value from the dictionary or the -list. Example usage: +``get`` is used to access single elements in collections. ``get`` takes at +least two parameters: the *data structure* and the *index* or *key* of the +item. It will then return the corresponding value from the collection. If +multiple *index* or *key* values are provided, they are used to access +successive elements in a nested structure. Example usage: .. code-block:: clj => (do ... (setv animals {"dog" "bark" "cat" "meow"} - ... numbers ["zero" "one" "two" "three"]) + ... numbers (, "zero" "one" "two" "three") + ... nested [0 1 ["a" "b" "c"] 3 4]) ... (print (get animals "dog")) - ... (print (get numbers 2))) + ... (print (get numbers 2)) + ... (print (get nested 2 1))) + bark two + b .. note:: ``get`` raises a KeyError if a dictionary is queried for a non-existing key.