On Tue, Mar 11, 2014 at 6:16 AM, Daniel Carrera <dcarr...@gmail.com> wrote:
> > On 10 March 2014 20:04, Daniel Carrera <dcarr...@gmail.com> wrote: > >> 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. >> > > After a tip from Erik, I have isolated the issue. The (import) only works > correctly if you first run (use posix). My REPL was loading posix because I > loaded readline. The following code compiles and runs correctly: > > (use posix) > > ; > ; 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. > (integer->char (cond ((<= A c Z) (+ A (modulo (+ key (- c A)) 26))) ((<= a c z) (+ a (modulo (+ key (- c A)) 26))) (else c))) > > (print (string-map caesar msg)) > > > > Cheers, > Daniel. > > > _______________________________________________ > Chicken-users mailing list > Chicken-users@nongnu.org > https://lists.nongnu.org/mailman/listinfo/chicken-users > >
_______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users