#lang racket (provide clear-bookmarks bookmarks-empty? bookmarks-push bookmarks-pop) ;; ---------------------------------------------------------------------------- ;; Bookmarks ;; Bookmarks are a list (stack) of positions (define bookmarks null) (define (clear-bookmarks) (set! bookmarks null)) (define (bookmarks-empty?) (null? bookmarks)) ;; bookmarks-push : position -> void (define (bookmarks-push bm) (if (null? bookmarks) (set! bookmarks (cons bm bookmarks)) (when (not (= bm (car bookmarks))) ; only push if top bookmark != bm (set! bookmarks (cons bm bookmarks))))) ;; bookmarks-pop : position -> position or #f ;; pops bookmarks until one that is not = current-pot is found and returns it ;; returns #f if no such bookmark exists (define (bookmarks-pop current-pos) (let loop ([bms bookmarks]) (if (null? bms) #f (if (and current-pos (= current-pos (car bms))) (loop (cdr bms)) (begin0 (car bms) (set! bookmarks (cdr bms)))))))