]> gitweb.factorcode.org Git - factor.git/commitdiff
python: word for converting python lists to vectors
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 30 Jan 2014 19:46:55 +0000 (20:46 +0100)
committerJohn Benediktsson <mrjbq7@gmail.com>
Tue, 4 Mar 2014 17:23:04 +0000 (09:23 -0800)
extra/python/python.factor

index 379e1952db459065592961510fbcc4742067ccd8..2dcd45d2486e530559ff22b397f4147dbeeede8a 100644 (file)
@@ -115,6 +115,9 @@ ERROR: python-error type message ;
 : py-tuple>array ( py-tuple -- arr )
     dup py-tuple-size iota [ py-tuple-get-item ] with map ;
 
+: py-list>vector ( py-list -- vector )
+    dup py-list-size iota [ py-list-get-item ] with V{ } map-as ;
+
 GENERIC: (>py) ( obj -- obj' )
 M: string (>py) utf8>py-unicode ;
 M: math:fixnum (>py) PyLong_FromLong ;
@@ -143,9 +146,7 @@ DEFER: >factor
         { "bool" [ PyObject_IsTrue 1 = ] }
         { "dict" [ PyDict_Items (check-return) >factor >hashtable ] }
         { "int" [ PyInt_AsLong ] }
-        { "list" [
-            dup py-list-size iota [ py-list-get-item >factor ] with V{ } map-as
-        ] }
+        { "list" [ py-list>vector [ >factor ] map ] }
         { "long" [ PyLong_AsLong ] }
         { "str" [ PyString_AsString (check-return) ] }
         { "tuple" [ py-tuple>array [ >factor ] map ] }