I am stumped. I am trying to convert a charlist back to a string but it keeps failing: Its stupid because when I paste the result from one function into another it works just fine, but if I do it inside the function it fails...
Example: this works
(delete" h ell o ") outputs: '(#\h #\e #\l #\l #\o) (convertToString '(#\h #\e #\l #\l #\o)) outputs: "hello"
but this doesnt work, if the conertToString is called in delete this happens
(delete" hell o") outputs:. . list->string: contract violation expected: (listof char?) given: '(#\l . "o")
(define deleteCh;driver
(lambda (s)
(delete(string->list s))))
(define delete
(lambda (input)
(cond
[(null? input) input]
[(equal? (car input) #\space) (delete(cdr input))]
[else (convertToString (cons (car input) (delete(cdr input))))];this works without convertToString
)
)
)
define convertToString
(lambda (charList)
(list->string charList)))
Aucun commentaire:
Enregistrer un commentaire