[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
- [Chicken-users] Review my Caesar Cipher?, Daniel Carrera, 2014/03/10
- Re: [Chicken-users] Review my Caesar Cipher?, Phil Bewig, 2014/03/10
- Re: [Chicken-users] Review my Caesar Cipher?, Peter Bex, 2014/03/10
- Re: [Chicken-users] Review my Caesar Cipher?, Phil Bewig, 2014/03/10
- Re: [Chicken-users] Review my Caesar Cipher?, Daniel Carrera, 2014/03/10
- Re: [Chicken-users] Review my Caesar Cipher?,
John Cowan <=
- Re: [Chicken-users] Review my Caesar Cipher?, Daniel Carrera, 2014/03/10
- Re: [Chicken-users] Review my Caesar Cipher?, Daniel Carrera, 2014/03/10
- Re: [Chicken-users] Review my Caesar Cipher?, Alex Shinn, 2014/03/10
- Re: [Chicken-users] Review my Caesar Cipher?, Daniel Carrera, 2014/03/11
- Re: [Chicken-users] Review my Caesar Cipher?, Alex Shinn, 2014/03/11
- Re: [Chicken-users] Review my Caesar Cipher?, Daniel Carrera, 2014/03/11
- Re: [Chicken-users] Review my Caesar Cipher?, Shiro Kawai, 2014/03/11
- Re: [Chicken-users] Review my Caesar Cipher?, John Cowan, 2014/03/11
- Re: [Chicken-users] Review my Caesar Cipher?, Alex Shinn, 2014/03/12
- Re: [Chicken-users] Review my Caesar Cipher?, Daniel Carrera, 2014/03/13