Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/Enumerations/Ol/enumerations.ol
Normal file
27
Task/Enumerations/Ol/enumerations.ol
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
(define fruits '{
|
||||
apple 0
|
||||
banana 1
|
||||
cherry 2})
|
||||
; or
|
||||
(define fruits {
|
||||
'apple 0
|
||||
'banana 1
|
||||
'cherry 2})
|
||||
|
||||
; getting enumeration value:
|
||||
(print (get fruits 'apple -1)) ; ==> 0
|
||||
; or simply
|
||||
(print (fruits 'apple)) ; ==> 0
|
||||
; or simply with default (for non existent enumeration key) value
|
||||
(print (fruits 'carrot -1)) ; ==> -1
|
||||
|
||||
; simple function to create enumeration with autoassigning values
|
||||
(define (make-enumeration . args)
|
||||
(fold (lambda (ff arg i)
|
||||
(put ff arg i))
|
||||
#empty
|
||||
args
|
||||
(iota (length args))))
|
||||
|
||||
(print (make-enumeration 'apple 'banana 'cherry))
|
||||
; ==> '#ff((apple . 0) (banana . 1) (cherry . 2))
|
||||
Loading…
Add table
Add a link
Reference in a new issue