PasteRack.org
Paste # 7261
2018-06-17 20:23:11

Forked from paste # 1894.

Fork as a new paste.

Paste viewed 117 times.


Embed:

broken heightmap fix

  1. #lang racket
  2.  
  3. ;; fixed by following advice from #racket
  4.  
  5. (require math/array)
  6.  
  7. (define (world dimensions)
  8.   (array->mutable-array
  9.    (make-array dimensions 7)))
  10.  
  11. (define (tiles elevation)
  12.   (cond
  13.     [(< elevation 8)
  14.      #\~]
  15.     [(< elevation 10)
  16.      #\:]
  17.     [(< elevation 12)
  18.      #\space]
  19.     [(< elevation 14)
  20.      #\n]
  21.     [else
  22.      #\A]))
  23.  
  24. (define (view-world map south east height width)
  25.   (define (view-row south east width)
  26.     (if (= width 1)
  27.         (list (tiles (array-ref map (vector south east))))
  28.         (append
  29.          (list (tiles (array-ref map (vector south east))))
  30.          (view-row south (+ east 1) (- width 1)))))
  31.   (if (= height 1)
  32.       (list->string (view-row south east width))
  33.       (string-append
  34.        (list->string (view-row south east width))
  35.        "\n"
  36.        (view-world map (+ south 1) east (- height 1) width))))
  37.  
  38. (define the-world (world (vector 8 8)))
  39.  
  40. (define out
  41.   (open-output-file "myData" #:exists 'truncate))
  42. (write (array->list* the-world) out)
  43. (close-output-port out)
  44.  
  45. (define in
  46.   (open-input-file "myData"))
  47. (display (view-world (list*->array (read in) number?) 1 1 5 5))
  48. (close-input-port in)

=>

open-output-file: `write' access denied for myData

out: undefined;

 cannot reference an identifier before its definition

  in module: 'm

out: undefined;

 cannot reference an identifier before its definition

  in module: 'm

open-input-file: cannot open input file

  path: /home/pasterack/racket68/share/pkgs/web-server-lib/w

eb-server/default-web-root/htdocs/myData

  system error: No such file or directory; errno=2

in: undefined;

 cannot reference an identifier before its definition

  in module: 'm

in: undefined;

 cannot reference an identifier before its definition

  in module: 'm