present: adding M\ complex present.
parent
46fd0b5794
commit
1f2ecfde76
|
@ -1,8 +1,14 @@
|
|||
IN: present.tests
|
||||
USING: tools.test vocabs.hierarchy present math vocabs sequences kernel ;
|
||||
USING: kernel math present sequences tools.test vocabs
|
||||
vocabs.hierarchy ;
|
||||
|
||||
[ "3" ] [ 3 present ] unit-test
|
||||
[ "Hi" ] [ "Hi" present ] unit-test
|
||||
[ "+" ] [ \ + present ] unit-test
|
||||
[ "kernel" ] [ "kernel" lookup-vocab present ] unit-test
|
||||
[ ] [ all-vocabs-recursive filter-vocabs [ present ] map drop ] unit-test
|
||||
{ "3" } [ 3 present ] unit-test
|
||||
{ "Hi" } [ "Hi" present ] unit-test
|
||||
{ "+" } [ \ + present ] unit-test
|
||||
{ "kernel" } [ "kernel" lookup-vocab present ] unit-test
|
||||
{ } [ all-vocabs-recursive filter-vocabs [ present ] map drop ] unit-test
|
||||
|
||||
{ "1+1j" } [ C{ 1 1 } present ] unit-test
|
||||
{ "1-1j" } [ C{ 1 -1 } present ] unit-test
|
||||
{ "-1+1j" } [ C{ -1 1 } present ] unit-test
|
||||
{ "-1-1j" } [ C{ -1 -1 } present ] unit-test
|
||||
|
|
|
@ -1,13 +1,21 @@
|
|||
! Copyright (C) 2008, 2009 Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors effects io.pathnames kernel math math.parser
|
||||
strings vocabs words ;
|
||||
sequences strings vocabs words ;
|
||||
IN: present
|
||||
|
||||
GENERIC: present ( object -- string )
|
||||
|
||||
M: real present number>string ;
|
||||
|
||||
M: complex present ( c -- str )
|
||||
[ real>> number>string ]
|
||||
[
|
||||
imaginary>>
|
||||
[ number>string ]
|
||||
[ 0 >= [ "+" prepend ] when ] bi
|
||||
] bi "j" 3append ;
|
||||
|
||||
M: string present ;
|
||||
|
||||
M: word present name>> ;
|
||||
|
|
Loading…
Reference in New Issue