Skip to content

Instantly share code, notes, and snippets.

@dyoo
Created November 14, 2012 20:31
Show Gist options
  • Save dyoo/4074580 to your computer and use it in GitHub Desktop.
Save dyoo/4074580 to your computer and use it in GitHub Desktop.
iterating reverse string
#lang racket
(define (in-string/rev s)
(define stop 'stop)
(define n (string-length s))
(define i (sub1 n))
(define (next!)
(cond
[(< i 0)
stop]
[else
(let ([result (string-ref s i)])
(set! i (sub1 i))
result)]))
(in-producer next! stop))
(for ([ch (in-string/rev "hello world")])
(displayln ch))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment