;; A teachpack with some string <--> number helper functions, ;; for Comp280 04.spring hw09. ;; ;; Your program will use the "Add teachpack..." menu item of drscheme, ;; to gain access to these functions. ;; If you copy this file to your own machine, ;; note that the file name must match the module name ("hw09lib", in this case). ;; For further info on writing your own teachpacks, see: ;; http://www.owlnet.rice.edu/~comp210/02fall/Handouts/teachpack-demo.shtml ;; (module hw09lib (lib "plt-pretty-big-text.ss" "lang") (provide ; Convert bewteen a string and a list of ascii character codes: string->integers ;:string -> (list-of int) integers->string ;:(list-of int) -> string ) ; Note that the next four functions are already built-in: ; ; Convert between a character and its ascii character code: ; char->integer ;:char -> int ; integer->char ;:int -> char ; Convert between a string and a list of characters: ; list->string ;:(list-of char) -> string ; string->list ;:string -> (list-of char) ;; string->integers :string -> (list-of int) ;; integers->string :(list-of int) -> string ;; Convert bewteen a string an a list of ascii character codes. ;; (define (string->integers str) (map char->integer (string->list str))) (define (integers->string nums) (list->string (map integer->char nums))) ) ;; Test cases ; (string->integers "ABBA") = (list 65 66 66 65) ; (integers->string (list 66 65 66 65)) = "BABA" ;; Scheme notes ;; ;; In scheme, the character 'w' is represented as #\w. ;; (E.g., (make-string 5 #\o) = "ooooo"). ;; Some special characters include #\space, #\tab, and #\newline. ;; ;; The difference between the built-in functions "remainder" and "modulo" ;; is how they handle negative numbers: ;; (remainder -7 5) = -2 ;; (modulo -7 5) = 3. ;; ;; ;; Some scheme functions you shouldn't need to use, but are related: ;; char-whitespace? ;; char-upper-case? char-lower-case? char-locale-upper-case? .. ;; char-upcase char-downcase char-locale-upcase .. ;; As always, see helpdesk for further info.