math.complex: Check C{ } syntax -- can only have two elements in the complex array. Fixes #612.
							parent
							
								
									0178117d6c
								
							
						
					
					
						commit
						2b45ba9a4f
					
				|  | @ -76,3 +76,6 @@ IN: math.complex.tests | ||||||
| 10 number-base [ | 10 number-base [ | ||||||
|     [ "C{ 1/2 2/3 }" ] [ C{ 1/2 2/3 } unparse ] unit-test |     [ "C{ 1/2 2/3 }" ] [ C{ 1/2 2/3 } unparse ] unit-test | ||||||
| ] with-variable | ] with-variable | ||||||
|  | 
 | ||||||
|  | [ "C{ 1 2 3 }" eval( -- obj ) ] | ||||||
|  | [ error>> T{ malformed-complex f V{ 1 2 3 } } = ] must-fail-with | ||||||
|  |  | ||||||
|  | @ -1,7 +1,8 @@ | ||||||
| ! Copyright (C) 2006, 2009 Slava Pestov. | ! Copyright (C) 2006, 2009 Slava Pestov. | ||||||
| ! See http://factorcode.org/license.txt for BSD license. | ! See http://factorcode.org/license.txt for BSD license. | ||||||
| USING: accessors kernel kernel.private math math.private | 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 | IN: math.complex.private | ||||||
| 
 | 
 | ||||||
| M: real real-part ; inline | M: real real-part ; inline | ||||||
|  | @ -30,7 +31,12 @@ M: complex sqrt >polar [ sqrt ] [ 2.0 / ] bi* polar> ; inline | ||||||
| 
 | 
 | ||||||
| IN: syntax | 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 | USE: prettyprint.custom | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue