Advertisement
Guest User

Untitled

a guest
Jul 29th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.26 KB | None | 0 0
  1. ;;;
  2. ;;; Destructively  replaces character  '#' with  ';'. At  the  time of
  3. ;;; writing semicolons were used only in #-commented sections.
  4. ;;;
  5. ;;; FIXME: unfortunately there is at  least one use of the #-character
  6. ;;; in  atomic class  symbol ---  C#.   See atom  types 897  & 898  in
  7. ;;; oplsaa.prm and smoothaa.prm. It happens  that this C# atom type is
  8. ;;; the only  place where the  char # is  not preceeded by a  space or
  9. ;;; another # (cf.  grep "[^ #]#" *.prm).
  10. ;;;
  11. (define (rewrite! str)
  12.   (string-map! (lambda (c)
  13.                  (case c
  14.                    ((#\#) #\;)          ; # -> ;
  15.                    (else c)))           ; leave the rest alone
  16.                str))
  17.  
  18. (define (rewrite!! str)
  19.   (let ((n (string-length str)))
  20.     (let loop ((i 0)                    ; pointer into the string
  21.                (f #t)) ; should we interprete evential # as a comment sign?
  22.       (if (< i n)
  23.           (let ((c (string-ref str i))
  24.                 (i++ (+ 1 i)))
  25.             (if (and f (equal? c #\#))
  26.                 (begin
  27.                   (string-set! str i #\;)
  28.                   (loop i++ #t))
  29.                 (loop i++ (char-whitespace? c))))))))
  30.  
  31. (define a (string-copy "c# #xyz# ## c# # ## ### comm#nts"))
  32. (rewrite!! a)
  33. (pretty-print a)
  34. (exit 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement