Associative array/Iteration: Difference between revisions

racket IS scheme
m (minimal changes to fixed code so it works.)
(racket IS scheme)
Line 980:
1 2 3
 
=={{header|Racket}}==
 
Using the dictionary interface, different data structures can be treated as an associative array in Racket.
 
<lang Racket>#lang racket
 
(define dict1 #hash((apple . 5) (orange . 10))) ; hash table
(define dict2 '((apple . 5) (orange . 10))) ; a-list
(define dict3 (vector "a" "b" "c")) ; vector (integer keys)
 
(dict-keys dict1) ; => '(orange apple)
(dict-values dict2) ; => '(5 10)
(for/list ([(k v) (in-dict dict3)]) ; => '("0 -> a" "1 -> b" "2 -> c")
(format "~a -> ~a" k v))
</lang>
 
=={{header|RLaB}}==
Line 1,056 ⟶ 1,041:
println("\nKey->Value:")
for((k,v)<-m) println(k+"->"+v)</lang>
=={{header|RacketScheme}}==
{{works with|Racket}} (moved from Racket)
Using the dictionary interface, different data structures can be treated as an associative array in Racket.
 
<lang Racketscheme>#lang racket
 
(define dict1 #hash((apple . 5) (orange . 10))) ; hash table
(define dict2 '((apple . 5) (orange . 10))) ; a-list
(define dict3 (vector "a" "b" "c")) ; vector (integer keys)
 
(dict-keys dict1) ; => '(orange apple)
(dict-values dict2) ; => '(5 10)
(for/list ([(k v) (in-dict dict3)]) ; => '("0 -> a" "1 -> b" "2 -> c")
(format "~a -> ~a" k v))
</lang>
 
=={{header|Seed7}}==
Anonymous user