Scheme is not C. I fixed the upper function to look more Scheme-y:
(also use code tags, which are represented by the # symbol in the advanced editing mode here on 2+2)
Code:
(define flip
(lambda (s)
(if (null? s)
'()
(append (flip (cdr s)) ('(car s))))))
(define key
(lambda (w)
;;first check if the list (word) is null
(if (null? w)
0
;;this is the base case when there is only one letter left
(if (null? (cdr w))
(+ (* 33 5381) (ctv (car w)))
;;this is the recursive step
(+ (* 33 (key (cdr w))) (ctv (car w)))
Are you using an editor with parenthesis matching?
irt to the gen-hash-method, yes, it will bonkers out because of the last line. See the comments:
Code:
(define gen-hash-division-method
(lambda (size)
(lambda (w) (modulo key (flip(w)) size)))))
;;; Let's rewrite this:
(define gen-hash-division-method
(lambda (size)
;; do you understand what is happening here?
;; do you know what a closure is?
(lambda (w)
;;; if you want to call a function in Scheme, you have
;;; to wrap it in parens:
;; you do not wrap args in parens:
(modulo (key (flip w)) size))))
I think you're confused by how to call functions in Scheme. The syntax that you use in this case:
(+ 3 4)
or
(cdr my-list)
is the same exact syntax that you use to call a function that you have created:
(my-function-rocks my-list)
The idea of Scheme (or any Lisp) is to create a program that is syntactically consistent, where the functions you create are not apparent from the functions built in to the program.
If you don't mind me asking, where are you learning to write this language? The syntax is all bonkers and it looks like a fairly difficult assignment for your comfort level of this language.