math.complex: Check C{ } syntax -- can only have two elements in the complex array. Fixes #612.

db4
Doug Coleman 2012-08-10 15:57:29 -07:00
parent 0178117d6c
commit 2b45ba9a4f
2 changed files with 12 additions and 3 deletions

View File

@ -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

View File

@ -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,7 +31,12 @@ 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