diff --git a/basis/math/complex/complex-tests.factor b/basis/math/complex/complex-tests.factor index d7fe54b201..537163cb09 100644 --- a/basis/math/complex/complex-tests.factor +++ b/basis/math/complex/complex-tests.factor @@ -76,3 +76,6 @@ IN: math.complex.tests 10 number-base [ [ "C{ 1/2 2/3 }" ] [ C{ 1/2 2/3 } unparse ] unit-test ] with-variable + +[ "C{ 1 2 3 }" eval( -- obj ) ] +[ error>> T{ malformed-complex f V{ 1 2 3 } } = ] must-fail-with diff --git a/basis/math/complex/complex.factor b/basis/math/complex/complex.factor index c432089f4d..381f21d693 100644 --- a/basis/math/complex/complex.factor +++ b/basis/math/complex/complex.factor @@ -1,7 +1,8 @@ ! Copyright (C) 2006, 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors kernel kernel.private math math.private -math.functions arrays math.functions.private sequences parser ; +math.functions arrays math.functions.private sequences +sequences.private parser ; IN: math.complex.private M: real real-part ; inline @@ -30,10 +31,15 @@ M: complex sqrt >polar [ sqrt ] [ 2.0 / ] bi* polar> ; inline IN: syntax -SYNTAX: C{ \ } [ first2 rect> ] parse-literal ; +ERROR: malformed-complex obj ; + +: parse-complex ( seq -- complex ) + dup length 2 = [ first2-unsafe rect> ] [ malformed-complex ] if ; + +SYNTAX: C{ \ } [ parse-complex ] parse-literal ; USE: prettyprint.custom M: complex pprint* pprint-object ; M: complex pprint-delims drop \ C{ \ } ; -M: complex >pprint-sequence >rect 2array ; \ No newline at end of file +M: complex >pprint-sequence >rect 2array ;