math.vectors: Don't use macro with locals and cond in vif. Stack-checker/locals/macros/smart-combinators all need some work (a rewrite?), but meanwhile don't let it get in the way. Add tests.

db4
Doug Coleman 2013-01-03 09:45:57 -08:00
parent 2ab5607670
commit fb60673840
2 changed files with 17 additions and 4 deletions

View File

@ -34,3 +34,16 @@ SPECIALIZED-ARRAY: int
[ -1 ] [ { C{ 0 1 } } dup v. ] unit-test [ -1 ] [ { C{ 0 1 } } dup v. ] unit-test
[ 1 ] [ { C{ 0 1 } } dup h. ] unit-test [ 1 ] [ { C{ 0 1 } } dup h. ] unit-test
{ { 1 2 3 } } [
{ t t t } [ { 1 2 3 } ] [ { 4 5 6 } ] vif
] unit-test
{ { 4 5 6 } } [
{ f f f } [ { 1 2 3 } ] [ { 4 5 6 } ] vif
] unit-test
{ { 1 5 3 } } [
{ t f t } [ { 1 2 3 } ] [ { 4 5 6 } ] vif
] unit-test

View File

@ -202,11 +202,11 @@ GENERIC: v? ( mask true false -- result )
M: object v? M: object v?
[ vand ] [ vandn ] bi-curry* bi vor ; inline [ vand ] [ vandn ] bi-curry* bi vor ; inline
:: vif ( mask true-quot: ( -- vector ) false-quot: ( -- vector ) -- result ) : vif ( mask true-quot: ( -- vector ) false-quot: ( -- vector ) -- result )
{ {
{ [ mask vall? ] [ true-quot call ] } { [ pick vall? ] [ drop nip call ] }
{ [ mask vnone? ] [ false-quot call ] } { [ pick vnone? ] [ 2nip call ] }
[ mask true-quot call false-quot call v? ] [ [ call ] dip call v? ]
} cond ; inline } cond ; inline
: vfloor ( u -- v ) [ floor ] map ; : vfloor ( u -- v ) [ floor ] map ;