TPU ChatChat on IRC
Internet Relay Chat?
Java Applet client
Who's on IRC?
for unknown_lamer or anyone who knows scheme
Posted by kfatima [send private reply] at November 25, 2002, 11:10:42 PM hi,
hope i am not bothering you too much. i am having trouble with one of the functions in scheme .
the structure is like: it is supposed to take a list containing 4 different hashfunctions and apply each one to the words that are within the list. so
hashfunctions are in the list like: (hash1 hash2 hash3)
and words are in the list like (hello day)
hash1, 2 & 3 are already defined. so the result should be
like (78 45 76 32 98 32) since hash1,2 & 3 apply to hello first and then day so altogether 6 numbers generated by the hashfunction.
i already have a function that generates a list containing numbers by apply hashfunctions to only one word:
(define applyall (lambda (functionlist value)
(if(null? functionlist) '()
(cons ((car functionlist) value) (applyall (cdr functionlist) value))))) // works fine!
but i dont know how to apply it to the whole list of words containing more than one word, i assme i can use he applyall
function but how?
this is how i started it:
(define bitvect (lambda (function w)
(cond(null? w) '()
(null? function) '()
(append ((applyall function w)) (bitvect (cdr function) (cdr w))))))//but it just gives the list of words back!
any kind of advice would be helpful
i would really appreciate it
thanks a lot
Posted by unknown_lamer [send private reply] at November 26, 2002, 10:19:16 AM In your cond, you are missing some parens. (cond (null ? w) ...) will test if null? is true, and it is, so w is returned.
(cond ((null? w) '()) ((null? function) '()) (else ...))
etc., just make sure the use the right number of parens.
Posted by kfatima [send private reply] at November 26, 2002, 12:03:39 PM hi,
thanks for the reply i fixed the parenthesis now, but i dont seem to get the right output, can you tell me how to get the list of numbers generated by the hash functions as i mentioned in my last post
Posted by unknown_lamer [send private reply] at November 27, 2002, 11:09:52 PM You should put the append into the else of the cond. Your recursion is non-tail so you may want to rewrite your code using named-let and also cons together your list backwards and then use reverse! from srfi-1 to reverse it for efficiency. But you probably don't care about that.
Register as a new user