]> gitweb.factorcode.org Git - factor.git/commitdiff
Update JSON writer for inheritance
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 30 Mar 2008 13:16:19 +0000 (08:16 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sun, 30 Mar 2008 13:16:19 +0000 (08:16 -0500)
extra/json/writer/writer.factor

index 1741b96e75d0467ec3d4b7fc59975d2b2f2b3473..6ad0774e387b8311daaa3e53bfe32b53584ba245 100644 (file)
@@ -26,32 +26,27 @@ M: number json-print ( num -- )
 M: integer json-print ( num -- )  
   number>string write ;
 
-M: sequence json-print ( array -- string 
+M: sequence json-print ( array -- ) 
   CHAR: [ write1 [ >json ] map "," join write CHAR: ] write1 ;
 
-: (jsvar-encode) ( char -- char )
-  #! Convert the given character to a character usable in
-  #! javascript variable names.
-  dup H{ { CHAR: - CHAR: _ } } at dup [ nip ] [ drop ] if ;
-
 : jsvar-encode ( string -- string )
   #! Convert the string so that it contains characters usable within
   #! javascript variable names.
-  [ (jsvar-encode) ] map ;
+  { { CHAR: - CHAR: _ } } substitute ;
   
-: tuple>fields ( object -- string )
+: tuple>fields ( object -- seq )
   <mirror> [
     [ swap jsvar-encode >json % " : " % >json % ] "" make
   ] { } assoc>map ;
 
-M: tuple json-print ( tuple -- string )
+M: tuple json-print ( tuple -- )
   CHAR: { write1 tuple>fields "," join write CHAR: } write1 ;
 
-M: hashtable json-print ( hashtable -- string )
+M: hashtable json-print ( hashtable -- )
   CHAR: { write1 
   [ [ swap jsvar-encode >json % CHAR: : , >json % ] "" make ]
   { } assoc>map "," join write 
   CHAR: } write1 ;
 
-M: object json-print ( object -- string )
+M: object json-print ( object -- )
     unparse json-print ;