chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Review my Caesar Cipher?


From: Alex Shinn
Subject: Re: [Chicken-users] Review my Caesar Cipher?
Date: Tue, 11 Mar 2014 20:41:12 +0900

On Tue, Mar 11, 2014 at 7:15 PM, Daniel Carrera <address@hidden> wrote:
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

Chibi has string-map in (chibi string).

But actually, if you're aiming for R7RS support then
string-map is in (scheme base).  Just replace the
cond-expand with:

(import (scheme base))

-- 
Alex


reply via email to

[Prev in Thread] Current Thread [Next in Thread]