PasteRack.org
Paste # 1894
2018-06-17 11:50:05

Fork as a new paste.

Paste viewed 136 times.


Embed:

broken heightmap

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