diff --git a/ocaml/reader.ml b/ocaml/reader.ml index 7456cf8e1c..fa009e255a 100644 --- a/ocaml/reader.ml +++ b/ocaml/reader.ml @@ -38,6 +38,11 @@ let read_atom token = | _ -> match token.[0] with | '0'..'9' -> T.Int (int_of_string token) + | '-' -> (match String.length token with + | 1 -> Types.symbol token + | _ -> (match token.[1] with + | '0'..'9' -> T.Int (int_of_string token) + | _ -> Types.symbol token)) | '"' -> T.String (gsub (Str.regexp "\\\\.") (function | "\\n" -> "\n" diff --git a/tests/step1_read_print.mal b/tests/step1_read_print.mal index 06e05ed4d2..5a3bcef684 100644 --- a/tests/step1_read_print.mal +++ b/tests/step1_read_print.mal @@ -14,6 +14,8 @@ false ;=>7 7 ;=>7 +-123 +;=>-123 ;; Testing read of symbols @@ -57,6 +59,8 @@ abc-def ;=>(* 1 2) (** 1 2) ;=>(** 1 2) +(* -3 6) +;=>(* -3 6) ;; Test commas as whitespace (1 2, 3,,,,),, diff --git a/tests/step2_eval.mal b/tests/step2_eval.mal index e97591020e..572d976ac9 100644 --- a/tests/step2_eval.mal +++ b/tests/step2_eval.mal @@ -14,6 +14,9 @@ (/ (- (+ 515 (* 222 311)) 302) 27) ;=>2565 +(* -3 6) +;=>-18 + (abc 1 2 3) ; .*\'abc\' not found.*