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: Daniel Carrera
Subject: Re: [Chicken-users] Review my Caesar Cipher?
Date: Mon, 10 Mar 2014 20:04:57 +0100

On 10 March 2014 17:10, John Cowan <address@hidden> wrote:
This isn't i18n-safe, because char-alphabetic? can return #t on
non-Latin letters.  Convert to an integer first and make sure it's in
the safe range.  Then add a comment to the effect that this assumes a
Scheme in which char->integer and integer->char preserve the ASCII range.
(Almost all Schemes do so, but it's not required by R5RS.)

...

2) `Use` is Chicken-specific.  There is no fully standard way to
load/import a module prior to R6RS/R7RS, but at least `require-extension`
(which is also implemented in Chicken) is the subject of SRFI 55.

I am trying to write an R7RS-compliant version. R7RS would give me "import", as well as char->integer and integer->char. The problem I'm having is that my code does not work when I compile it, or when I use "csi -s", but it works perfectly well when I paste it directly into the csi REPL. Here is what I have:

;
; Unicode-safe. Requires an R7RS-compliant Scheme.
;
(import (srfi 13)) ; String library.

(define msg "The quick brown fox jumps over the lazy fox.")
(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))
  (cond ((and (>= c A) (<= c Z)) (integer->char (+ A (modulo (+ key (- c A)) 26))))
        ((and (>= c a) (<= c z)) (integer->char (+ a (modulo (+ key (- c a)) 26))))
        (else char))) ; Return other characters verbatim.

(print (string-map caesar msg))



When I compile this and run it, I get an error saying that string-map is not defined. Same thing happens with "csi -s". So clearly it is not loading SRFI-13... Any ideas?

Cheers,
Daniel.
--
When an engineer says that something can't be done, it's a code phrase that means it's not fun to do.

reply via email to

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