|
From: | Alex Shinn |
Subject: | Re: [Chicken-users] Review my Caesar Cipher? |
Date: | Tue, 11 Mar 2014 20:41:12 +0900 |
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
[Prev in Thread] | Current Thread | [Next in Thread] |