PasteRack.org
Paste # 77237
2019-02-24 03:13:04

Fork as a new paste.

Paste viewed 326 times.


Embed:

verifying input in TR

  1. ; I needed to import state from a file and make it available for my event loop.
  2. ; Since read and load return Any, I needed to let the compiler know about the structure of the data
  3. ; by first filtering out nonlists, then filtering out list entries that don't match the input format.
  4. (: import-cell-state (-> Void))
  5. (define (import-cell-state)
  6.   (let ([import-path (get-file "Import cell state"
  7.                                frame
  8.                                (find-system-path 'desk-dir)
  9.                                #f
  10.                                "gol"
  11.                                (list 'common)
  12.                                (list (list "Game of Life state" "*.gol")))])
  13.     (cond [(path? import-path)
  14.            (set! import-cells
  15.                  (quadtree-fold null
  16.                                 (filter-map
  17.                                  (λ (c) (let ([x (if (pair? c) (car c) null)]
  18.                                               [y (if (pair? c) (cdr c) null)])
  19.                                           (if (and (exact-integer? x)
  20.                                                    (exact-integer? y))
  21.                                               (coordinate x y) #f)))
  22.                                  (get-cells-from-file import-path))))]
  23.           [else (void)])))
  24.  
  25. (: get-cells-from-file (-> Path-String (Listof Any)))
  26. (define (get-cells-from-file path)
  27.   (let* ([fh (open-input-file path)]
  28.          [cells (read fh)])
  29.     (close-input-port fh)
  30.     (if (list? cells)
  31.         cells
  32.         null)))

=>

load-handler: expected a `module' declaration for `pasterack' in "paste 77237", but found something else

Check that paste includes #lang?