Execute SNUSP/OCaml: Difference between revisions
m
Fixed syntax highlighting.
(added ocaml) |
m (Fixed syntax highlighting.) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1:
{{implementation|SNUSP}}{{collection|RCSNUSP}}
This is an implementation of '''Modular SNUSP'''.
<lang ocaml>let input_line ic =▼
Usage: ocaml rcsnusp.ml srccode.snusp
try Some(input_line ic)
with End_of_file -> None
Line 27 ⟶ 31:
let ruld (x,y) = (y,x)
let lurd (x,y) = (-y,-x)
let next_pos ~pos:(x,y) ~dir:(dx,dy) =▼
let incr (l,v,r) = (l,v+1,r)
Line 47:
let zero = function (_,0,_) -> true | _ -> false
▲let next_pos ~pos:(x,y) ~dir:(dx,dy) = (x+dx, y+dy)
let max_x = Array.fold_left (fun v line -> max v (String.length line)) 0 code
let max_y = Array.length code
let get_char code (x,y) =
if x < 0 || y < 0 || x > max_x || y > max_y then raise Exit;
try code.(y).[x]
with _ -> '\000'
let () =
▲ let code = read Sys.argv.(1) in
let rec loop pos dir cells stk =
match (get_char code pos) with
Line 73 ⟶ 79:
| _ -> loop (next_pos pos dir) dir cells stk
in
loop (dolar_pos code) (1,0) ([],0,[]) []</
|