s c h e m e w i k i . o r g

/ Sandbox.CodeFormatting

This Web


WebHome 
WebChanges 
WebTopicList 
WebStatistics 

All Webs


Chicken
Cookbook
Erlang
Know
Main
Plugins
Sandbox
Scm
TWiki  

Schematics


Schematics Home
TWiki Shorthand

Offsite Links


Schemers.org
Lambda the Ultimate
twiki.org

Scheme code formatting comparison

The following code is formatted using ScmToXexpr:

Syntax Highlighting: error: scm: undefined language


The following code is formatted using enscript:

; string->byte-strings : string -> list-of-strings
;  chop the string s into pieces of length 8
;  E.g. (string->byte-strings "0000000011111111") = (list "00000000" "11111111")
(define (string->byte-strings s)
  (string-chop s 8))

; string-chop : string non-negative-integer -> list-of-strings
;  chop the string s into pieces of length length-of-pieces
(define (string-chop s length-of-pieces)
  (let ([len (string-length s)])
    (do ([i  0   (+ i length-of-pieces)]
         [bs '() (cons (substring s i 
                                  (min (+ i length-of-pieces) len))
                       bs)])
      [(>= i len) (reverse bs)])))
                           
; binary-string->integer : string-of-zeros-and-ones -> integer
;  converts a string of binary digits into an integer
;  E.g. (binary-string->integer "101") = 5
(define (binary-string->integer b)
  (string->number b 2))


; decode : string -> string
;  converts a message written in binary to a normal string
(define (decode message)
  (apply string 
         (map (compose integer->char binary-string->integer)
              (string->byte-strings message))))

;; The following message appeared on a ThinkGeek tshirt
;; on the first of april 2004.

(define thinkgeek-tshirt-message
  (string-append "010010010010000001110011011010000110111"
                 "101110000011100000110010101100100001000" 
                 "000110000101110100001000000101010001101" 
                 "000011010010110111001101011010001110110" 
                 "010101100101011010110010000001101111011"
                 "011100010000001000001011100000111001001" 
                 "101001011011000010000001000110011011110" 
                 "110111101101100011100110010000001000100" 
                 "011000010111100100101100001000000110000" 
                 "101101110011001000010000001100001011011" 
                 "000110110000100000010010010010000001100" 
                 "111011011110111010000100000011101110110" 
                 "000101110011001000000111010001101000011" 
                 "010010111001100100000011011000110111101" 
                 "110101011100110111100100100000011100110" 
                 "110100001101001011100100111010000100001"))

(decode thinkgeek-tshirt-message)

 
 
© 2004 by the contributing authors. / You are Main.guest