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: John Cowan
Subject: Re: [Chicken-users] Review my Caesar Cipher?
Date: Mon, 10 Mar 2014 12:10:48 -0400
User-agent: Mutt/1.5.20 (2009-06-14)

Daniel Carrera scripsit:

> (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))

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.)

General comments not relevant to this code:

1) Rolling your own string-map is tricky, because of the R7RS requirement
that a call/cc from the mapping function work correctly:

    If multiple returns occur from `string-map`, the values returned
    by earlier returns are not mutated.

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.

-- 
MEET US AT POINT ORANGE AT MIDNIGHT BRING YOUR DUCK OR PREPARE TO FACE WUGGUMS
John Cowan      address@hidden      http://www.ccil.org/~cowan



reply via email to

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