0 Replies - 1224 Views - Last Post: 27 July 2010 - 04:27 AM

#1 Crunch   User is offline

  • D.I.C Lover
  • member icon

Reputation: 139
  • View blog
  • Posts: 1,222
  • Joined: 28-July 09

[Scheme] Toggle Case of Char's in a String

Posted 27 July 2010 - 04:27 AM

Description:
(define (loop x x-max step str)
  (if (< x x-max)
    
     (begin 
      
      (cond
      ( (and (>= (char->integer (string-ref str x)) 97 ) (<= (char->integer (string-ref str x)) 122 ) )  (display  (integer->char (- (char->integer (string-ref str x) ) 32 )  ) ))
     
      ( (and (>= (char->integer (string-ref str x)) 65 ) (<= (char->integer (string-ref str x)) 90 ) )  (display  (integer->char (+  (char->integer (string-ref str x) ) 32 )  ) ))
          
      (else (display  (string-ref str x) ))
      )
          
      (loop (+ x step) x-max step str))))




(define toggle(lambda (x)
                
                (loop 0 (string-length x) 1 x )
                
))
                
                


Is This A Good Question/Topic? 0
  • +

Page 1 of 1