Skip to content

Commit 6f0666b

Browse files
committed
switched % operator to mod
1 parent 5eaa9a2 commit 6f0666b

11 files changed

Lines changed: 19 additions & 13 deletions

File tree

editor/rustscript.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ syntax match rscOp "<="
3131
syntax match rscOp "<"
3232
syntax match rscOp ">"
3333
syntax match rscOp ">="
34+
syntax match rscOp "mod"
3435
highlight link rscOp Operator
3536

3637
syntax match rscMatchArrow "->"

examples/caesar.rsc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ let (to_number, to_letter) = {
66
}
77

88
let encode = fn(text, shift) => {
9-
let shift = shift % 26
9+
let shift = shift mod 26
1010

1111
let loop = fn(char_ls, acc) => match char_ls
1212
| [] -> concat(reverse(acc))
@@ -16,7 +16,7 @@ let encode = fn(text, shift) => {
1616
|> to_number
1717
|> add(shift, _)
1818
|> fn(c) => if c < 0 then 26 + c else c
19-
|> fn(c) => to_letter(c % 26)
19+
|> fn(c) => to_letter(c mod 26)
2020
loop(xs, [new_letter | acc])
2121
}
2222

examples/euler1.rsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
let euler1 = sum([x for x in [1..1000] if x % 3 == 0 || x % 5 == 0])
1+
let euler1 = sum([x for x in [1..1000] if x mod 3 == 0 || x mod 5 == 0])
22
# inspect(euler1) # 233168

examples/euler1_no_listcomp.rsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
let predicate = fn(n) => (n % 3 == 0) || (n % 5 == 0)
1+
let predicate = fn(n) => (n mod 3 == 0) || (n mod 5 == 0)
22
# inspect(sum(filter_rev(predicate, range(1, 1000)))) #233168

examples/euler1_tup.rsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ let sum_tup = {
2424
fn (ls) => helper(ls, 0)
2525
}
2626

27-
let predicate = fn(n) => (n % 3 == 0) || (n % 5 == 0)
27+
let predicate = fn(n) => (n mod 3 == 0) || (n mod 5 == 0)

examples/euler3.rsc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ let gcd = fn(a, b) => match (a, b)
22
| (x, 0) | (0, x) -> x
33
| (a, b) when a > b -> gcd(b, a)
44
| (a, b) -> {
5-
let remainder = b % a
5+
let remainder = b mod a
66
if remainder != 0 then (gcd(a, remainder)) else a
77
}
88

99
let pollard = fn(n) => match n
1010
| 1 -> ()
11-
| n when n % 2 == 0 -> 2
11+
| n when n mod 2 == 0 -> 2
1212
| n -> {
13-
let g = fn(x, n) => (x * x + 1) % n
13+
let g = fn(x, n) => (x * x + 1) mod n
1414
let iter = fn(x, y, d) => match (x, y, d)
1515
| (x, y, 1) -> {
1616
let x = g(x, n)

examples/euler5.rsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
let gcd = fn(a, b) => match (a, b)
22
| (a, 0) -> a
3-
| (a, b) -> gcd(b, a % b)
3+
| (a, b) -> gcd(b, a mod b)
44

55
let lcm = fn(a, b) => (a * b) / gcd(a, b)
66

lib/eval.ml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,9 +650,12 @@ and eval_map_expr ?tc:(_tail_call=false) map_pairs tail_map ss loc state =
650650
let start_map = match tail_map with
651651
| Some (Dictionary m) -> m
652652
| None -> Map.empty (module Int)
653-
| _ ->
654-
printf "Expected a map\n";
655-
assert false
653+
| Some m ->
654+
printf "Expected a map for the tail in map expr at %s, got %s\n"
655+
(location_to_string loc)
656+
(string_of_val ss m);
657+
print_traceback ss;
658+
Caml.exit 0
656659
in
657660
let (val_map, state) =
658661
List.fold_left ~init:(start_map, state) ~f:fold_fn map_pairs

lib/parser.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ let prefix_op_bp = 13
1919

2020
let rec complete_expr: expr t -> (token t) list -> int -> (expr t * (token t) list) =
2121
fun lhs ls min_bp -> match (skip_newlines ls) with
22-
| {data = Percent; location}::xs -> complete_expr lhs (({data = Operator Mod; location})::xs) min_bp
2322
| ({data = Operator op; location})::xs ->
2423
let (l_bp, r_bp) = binary_op_bp op in
2524
if l_bp < min_bp then
@@ -348,6 +347,7 @@ and parse_args toks =
348347
CaptureExprArg nx, rest
349348
in
350349
let acc = nx::acc in
350+
let rest = skip_newlines rest in
351351
match rest with
352352
| {data = Comma; _}::rest -> aux rest acc
353353
| {data = RParen; _}::rest -> acc, rest

lib/run.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ let run_line ss state line =
3333
let run_string in_string filename (ss, state) =
3434
let locate = Located.locate {line_num = 0; filename = filename} in
3535
let tokens = in_string |> Scanner.scan ~filename:filename |> skip_newlines in
36+
(* print_toks (List.map ~f:Located.extract tokens); *)
3637
let expr_ls =
3738
let rec aux remaining acc = match (skip_newlines remaining) with
3839
| [] -> acc

0 commit comments

Comments
 (0)