Enumerations: Difference between revisions

m
(Added Arturo implementation)
Line 1,188:
 
; 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
 
</lang>
<lang scheme>
; simple function to create enumeration with autoassigning values
(define (make-enumeration . args)
Line 1,203 ⟶ 1,202:
(iota (length args))))
 
(print (make-enumeration 'apple 'banana 'cherry))
; ==> '#ff((apple . 0) (banana . 1) (cherry . 2))
</lang>