Reputation: 1048
I am new to the Scheme language and am currently using the Simply Scheme textbook. I was experimenting with some procedures, and I noticed that when I do these functions (below), it prints words in a "spoken" fashion:
(define (display-all sep . vs)
(for-each display (insert-between sep vs)))
(define (insert-between v xs)
(cond ((null? xs) xs)
((null? (cdr xs)) xs)
(else (cons (car xs)
(cons v (insert-between v (cdr xs)))))))
(Code used from How to 'display' multiple parameters in R5RS Scheme)
Then commanding:
(display-all "" 'w 'o 'w " " 't 'h 'i 's " " 'i 's " " 'c 'o 'o 'l)
The letters are printed one by one as if someone was typing them. I was wondering if there was any way to make it easier for me to input these words to be spoken, instead of inputting letter by letter. I was planning to have something like this:
(define (speak . wds)
(...))
where wds
would be a string. In the above example, I would like for it to be like this: (speak "wow this is cool")
and return "wow this is cool"
but each letter displayed one by one.
Thank you in advance for your help!
Upvotes: 1
Views: 111
Reputation: 236112
How about passing a string as input? there's no need to use variable arguments in this case, please try this:
(define (display-all sep vs)
(for-each display (insert-between sep (string->list vs))))
(display-all "" "wow this is cool")
Upvotes: 1