]> gitweb.factorcode.org Git - factor.git/commitdiff
some new matrix words
authorSlava Pestov <slava@factorcode.org>
Sat, 21 May 2005 06:28:23 +0000 (06:28 +0000)
committerSlava Pestov <slava@factorcode.org>
Sat, 21 May 2005 06:28:23 +0000 (06:28 +0000)
CHANGES.txt
library/alien/c-types.factor
library/bootstrap/boot-stage3.factor
library/math/matrices.factor
library/math/more-matrices.factor [new file with mode: 0644]

index ef75bc65a19b91ce45a4323341c018f5dc99403b..ad930ae220be1a813fa847eaf571898bbc640aef 100644 (file)
@@ -10,11 +10,8 @@ for controlling it:
 The compiler now does constant folding for certain words with literal
 operands. The compiler's peephole optimizer has been improved.
 
-The alien interface now supports "float" and "double" types.
-
-Defining a predicate subclass of tuple is supported now. Note that
-unions and complements over tuples are still not supported. Also,
-predicate subclasses of concrete tuple classes are not supported either.
+The alien interface now supports "float" and "double" types, and arrays
+of C types.
 
 The SO_OOBINLINE socket flag is now set. In 0.74, sending out-of-band
 data could fill up the buffer and cause a denial-of-service attack.
@@ -32,33 +29,8 @@ Note that GENERIC: foo is the same as
 
  G: foo [ dup ] [ type ] ;
 
-The seq-each and seq-map words have been renamed to each and map, and
-now work with lists. The each and map words in the lists vocabulary have
-been removed; use the new generic equivalents instead.
-
-Added two new types of 'virtual' sequences: a range sequence containing
-a range of integers, and a slice sequence containing a subsequence of
-another sequence.
-
-Some string words were made generic, and now work with all sequences:
-
-Old word:     New word:
----------     ---------
-string-head   head
-string-head?  head?
-?string-head  ?head
-string-tail   tail
-vector-tail   tail
-vector-tail*  tail*
-string-tail?  tail?
-?string-tail  ?tail
-substring     subseq
-cat2          append
-cat3          append3
-string/       cut
-string//      cut*
-split1        split1
-split         split
+Sequence API refactoring, as described in
+http://www.jroller.com/page/slava/20050518.
 
 Factor 0.74:
 ------------
index 3d79d02ca32acaa3eb622890be8bb4b17b62add2..3876fffe7f1eaaa31eff713cae862cf7f32e6f29 100644 (file)
@@ -225,9 +225,13 @@ global [ c-types nest drop ] bind
     \ %unbox-double "unbox-op" set
 ] "double" define-primitive-type
 
-: alias-c-type ( old new -- )
+: (alias-c-type)
     c-types get [ >r get r> set ] bind ;
 
+: alias-c-type ( old new -- )
+    over "*" append over "*" append
+    (alias-c-type) (alias-c-type) ;
+
 ! FIXME for 64-bit platforms
 "int" "long" alias-c-type
 "uint" "ulong" alias-c-type
index 89a5939392d2425ee949f80104ca033c15beb7b6..4b3f18f6db11189ad36ce4caef820b883240dc28 100644 (file)
@@ -45,6 +45,7 @@ compile? [
 t [
     "/library/math/constants.factor"
     "/library/math/pow.factor"
+    "/library/math/matrices.factor"
     "/library/math/trig-hyp.factor"
     "/library/math/arc-trig-hyp.factor"
     "/library/math/random.factor"
index 555676e4bb115f0f8aabd39d8c5424d9b9aef863..b50a7f338c3f8a01a86d50c6d0bd60dc94b36b8c 100644 (file)
@@ -18,7 +18,17 @@ vectors ;
 ! : v. ( v v -- x ) 0 swap [ * + ] 2each ;
 : v. ( v v -- x ) v** 0 swap [ + ] each ;
 
-: norm ( v -- a ) dup v. sqrt ;
+: (cross) ( v1 v2 i1 i2 -- n )
+    rot nth >r swap nth r> * ;
+
+: cross ( { x1 y1 z1 } { x2 y2 z2 } -- { z1 z2 z3 } )
+    #! Cross product of two 3-dimensional vectors.
+    [
+        2dup 2 1 (cross) >r 2dup 1 2 (cross) r> - ,
+        2dup 0 2 (cross) >r 2dup 2 0 (cross) r> - ,
+        2dup 1 0 (cross) >r 2dup 0 2 (cross) r> - ,
+        2drop
+    ] make-vector ;
 
 ! Matrices
 ! The major dimension is the number of elements per row.
diff --git a/library/math/more-matrices.factor b/library/math/more-matrices.factor
new file mode 100644 (file)
index 0000000..cc951dd
--- /dev/null
@@ -0,0 +1,10 @@
+! Copyright (C) 2005 Slava Pestov.
+! See http://factor.sf.net/license.txt for BSD license.
+IN: matrices
+USING: kernel math ;
+
+: norm ( v -- a )
+    dup v. sqrt ;
+
+: normalize ( v -- v )
+    [ norm recip ] keep n*v ;