Thanks. I think it's fair to use SRF-13. Now that I learned some character functions from Phil, I think the following is nice and compact:
(define (caesar char) (if (not (char-alphabetic? char)) char ; Return other chars verbatim. (let ((i (- (char->integer (char-upcase char)) 65))) (integer->char (+ 65 (modulo (+ i key) 26)))))) (print (string-map caesar msg)) Cheers, Daniel. On 10 March 2014 16:31, Peter Bex <peter....@xs4all.nl> wrote: > On Mon, Mar 10, 2014 at 10:26:56AM -0500, Phil Bewig wrote: > > I would use an auxiliary function char-plus to add or subtract an offset > to > > a character: > > > > (define (caesar str n) > > (define (char-plus c) > > (let ((alpha "ABCDEFGHIJKLMNOPQRSTUVWXYZ")) > > (if (not (char-alphabetic? c)) c > > (let ((i (- (char->integer (char-upcase c)) 65))) > > (string-ref alpha (modulo (+ i n) 26)))))) > > (list->string (map char-plus (string->list str)))) > > If you're using srfi-13, you might as well change the final line to use > string-map: (string-map char-plus str) > > Cheers, > Peter > -- > http://www.more-magic.net > -- When an engineer says that something can't be done, it's a code phrase that means it's not fun to do.
_______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users