fork(1) download
  1. ; string data type
  2.  
  3. (define (take n xs)
  4. (let loop ((n n) (xs xs) (ys '()))
  5. (if (or (zero? n) (null? xs))
  6. (reverse ys)
  7. (loop (- n 1) (cdr xs)
  8. (cons (car xs) ys)))))
  9.  
  10. (define (drop n xs)
  11. (let loop ((n n) (xs xs))
  12. (if (or (zero? n) (null? xs)) xs
  13. (loop (- n 1) (cdr xs)))))
  14.  
  15. (define string->str string->list)
  16. (define str->string list->string)
  17. (define s (string->str "Programming Praxis"))
  18. (display s) (newline)
  19. (display (str->string s)) (newline)
  20.  
  21. (define str-length length)
  22. (define str-ref list-ref)
  23. (define str-substring (case-lambda
  24. ((s start) (str-substring s start (+ (str-length s))))
  25. ((s start past) (take (- past start) (drop start s)))))
  26. (display (str-length s)) (newline)
  27. (display (str-ref s 8)) (newline)
  28. (display (str-substring s 8)) (newline)
  29. (display (str-substring s 8 13)) (newline)
  30.  
  31. (define str-concat append)
  32. (display (str-concat
  33. (string->str "Programming")
  34. (string->str " ")
  35. (string->str "Praxis")))
Success #stdin #stdout 0s 50288KB
stdin
Standard input is empty
stdout
(P r o g r a m m i n g   P r a x i s)
Programming Praxis
18
i
(i n g   P r a x i s)
(i n g   P)
(P r o g r a m m i n g   P r a x i s)