Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,2 @@
|
|||
(define (lists->hash-table keys values . rest)
|
||||
(apply alist->hash-table (map cons keys values) rest))
|
||||
23
Task/Hash-from-two-arrays/Scheme/hash-from-two-arrays-2.ss
Normal file
23
Task/Hash-from-two-arrays/Scheme/hash-from-two-arrays-2.ss
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
;; Using SRFI-1, R6RS, or R7RS association lists.
|
||||
|
||||
;; Because the task calls for ‘arrays’, I start with actual arrays
|
||||
;; rather than lists.
|
||||
(define array1 (vector "a" "b" "c" "d"))
|
||||
(define array2 (vector 1 2 3 4))
|
||||
|
||||
;; Making the hash is just a simple list operation.
|
||||
(define dictionary (map cons (vector->list array1)
|
||||
(vector->list array2)))
|
||||
|
||||
;; Now you can look up associations with assoc.
|
||||
(write (assoc "b" dictionary)) (newline)
|
||||
(write (assoc "d" dictionary)) (newline)
|
||||
|
||||
;; USING CHICKEN 5 SCHEME, OUTPUT FROM EITHER
|
||||
;; ‘csc -R srfi-1 thisprog.scm && ./thisprog’
|
||||
;; OR ‘csc -R r7rs thisprog.scm && ./thisprog’,
|
||||
;; AND ALSO TESTED IN CHEZ SCHEME (R6RS):
|
||||
;;
|
||||
;; ("b" . 2)
|
||||
;; ("d" . 4)
|
||||
;;
|
||||
31
Task/Hash-from-two-arrays/Scheme/hash-from-two-arrays-3.ss
Normal file
31
Task/Hash-from-two-arrays/Scheme/hash-from-two-arrays-3.ss
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
(import (associative-arrays))
|
||||
|
||||
;; Because the task calls for ‘arrays’, I start with actual arrays
|
||||
;; rather than lists.
|
||||
(define array1 (vector "a" "b" "c" "d"))
|
||||
(define array2 (vector 1 2 3 4))
|
||||
|
||||
(define (silly-hashfunc s)
|
||||
(define h 1234)
|
||||
(do ((i 0 (+ i 1)))
|
||||
((= i (string-length s)))
|
||||
(set! h (+ h (char->integer (string-ref s i)))))
|
||||
(sqrt (/ (* h 101) 9.80665)))
|
||||
|
||||
;; Here is the making of the associative array:
|
||||
(define dictionary (assoc-array silly-hashfunc))
|
||||
(vector-for-each (lambda (key data)
|
||||
(set! dictionary
|
||||
(assoc-array-set dictionary key data)))
|
||||
array1 array2)
|
||||
|
||||
(display "Looking up \"b\" and \"d\": ")
|
||||
(write (assoc-array-ref dictionary "b"))
|
||||
(display " ")
|
||||
(write (assoc-array-ref dictionary "d"))
|
||||
(newline)
|
||||
|
||||
;; Output:
|
||||
;;
|
||||
;; Looking up "b" and "d": 2 4
|
||||
;;
|
||||
Loading…
Add table
Add a link
Reference in a new issue