Associative array/Creation: Difference between revisions

Content added Content deleted
(added ol)
Line 1,914: Line 1,914:
(* see if key exists *)
(* see if key exists *)
print_endline (if List.mem_assoc "foo" dict then "key found" else "key missing")</lang>
print_endline (if List.mem_assoc "foo" dict then "key found" else "key missing")</lang>

=={{header|Ol}}==
In Otus Lisp associative arrays (aka "ff") fully conforms the functional paradigm. It means that there are no ability to change the existing associative array, only get new changed one.

Please be aware that you can use only values as keys (atomic numbers, constants) and, as exception, symbols (symbols are references, but unique). No strings, lists, vectors, tuples and other references can be used directly. In such cases use hashes or similar mechanisms.

<lang ol>
; empty associative array has two names
#empty
#()

; creating the new empty associative array
(define empty-map #empty)

; creating associative array with values
(define my-map (list->ff '(
(1 . 100)
(2 . 200)
(7 . 777))))

; add new key-value pair to the existing associative array
(define my-new-map (put my-map 'the-key 'the-value))

; print our arrays
(print empty-map)
; ==> #()
(print my-map)
; ==> #((1 . 100) (2 . 200) (7 . 777))
(print my-new-map)
; ==> #((1 . 100) (2 . 200) (7 . 777) (the-key . the-value))
</lang>


=={{header|ooRexx}}==
=={{header|ooRexx}}==
Line 1,957: Line 1,988:
end
end
</lang>
</lang>

=={{header|OxygenBasic}}==
=={{header|OxygenBasic}}==
Not very efficient but the 'find' method could be optimised very easily.
Not very efficient but the 'find' method could be optimised very easily.