RosettaCodeData/Task/Associative-array-Creation/Ol/associative-array-creation.ol

32 lines
641 B
Text
Raw Permalink Normal View History

2019-09-12 10:33:56 -07:00
;;; empty associative array
2017-09-23 10:01:46 +02:00
#empty
2019-09-12 10:33:56 -07:00
; or short form
#e
2017-09-23 10:01:46 +02:00
2019-09-12 10:33:56 -07:00
;;; creating the new empty associative array
2017-09-23 10:01:46 +02:00
(define empty-map #empty)
2019-09-12 10:33:56 -07:00
;;; creating associative array with values
2020-02-17 23:21:07 -08:00
(define my-map (pairs->ff '(
2017-09-23 10:01:46 +02:00
(1 . 100)
(2 . 200)
(7 . 777))))
2019-09-12 10:33:56 -07:00
;;; or in short form (available from Ol version 2.1)
2020-02-17 23:21:07 -08:00
(define my-map {
1 100
2 200
7 777})
2017-09-23 10:01:46 +02:00
2019-09-12 10:33:56 -07:00
;;; add new key-value pair to the existing associative array
2017-09-23 10:01:46 +02:00
(define my-new-map (put my-map 'the-key 'the-value))
2019-09-12 10:33:56 -07:00
;;; print our arrays
2017-09-23 10:01:46 +02:00
(print empty-map)
; ==> #()
2019-09-12 10:33:56 -07:00
2017-09-23 10:01:46 +02:00
(print my-map)
; ==> #((1 . 100) (2 . 200) (7 . 777))
2019-09-12 10:33:56 -07:00
2017-09-23 10:01:46 +02:00
(print my-new-map)
; ==> #((1 . 100) (2 . 200) (7 . 777) (the-key . the-value))