With the last suggestion from Alex, and a tip to use cond-expand from Kon,
I have settled on the following:

-----------------------------
;
; Works with Chicken Scheme and Gauche.
;
(cond-expand (chicken (use srfi-13))
             (gauche  (use srfi-13)))

(define msg "The quick brown fox jumps over the lazy dog.")
(define key 13)

(define (caesar char)
  (define A (char->integer #\A))
  (define Z (char->integer #\Z))
  (define a (char->integer #\a))
  (define z (char->integer #\z))
  (define c (char->integer char))
  (integer->char
    (cond ((<= A c Z) (+ A (modulo (+ key (- c A)) 26)))
          ((<= a c z) (+ a (modulo (+ key (- c a)) 26)))
          (else c)))) ; Return other characters verbatim.

(print (string-map caesar msg))
-----------------------------

I tried to include more Schemes, but Chibi doesn't seem to have SRFI-13,
Racket doesn't support SRFI-0 (cond-expand), and Stklos is
case-insensitive. There are other schemes that support both SRFI-0 and 13,
but AFAICT they are not active. Even Stklos seems to have gone into a
slumber 2.5 years ago. I have updated the Rosetta Code page. Since this
code includes a lot of advice from experienced Schemers, I have removed the
"novice" note.

http://rosettacode.org/wiki/Caesar_cipher#Scheme

Cheers,
Daniel.


On 11 March 2014 02:09, Alex Shinn <alexsh...@gmail.com> wrote:

>
> (integer->char
>  (cond ((<= A c Z) (+ A (modulo (+ key (- c A)) 26)))
>           ((<= a c z) (+ a (modulo (+ key (- c A)) 26)))
>           (else c)))
>
> --
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

Reply via email to