Paste: method override: jsvar-encode
Author: | otoburb |
Mode: | factor |
Date: | Tue, 21 Jun 2011 20:45:13 |
Plain Text |
M: hashtable json-print ( hashtable -- )
CHAR: { write1
[ [ swap jsvar-encode >json % CHAR: : , >json % ] "" make ]
{ } assoc>map "," join write
CHAR: } write1 ;
M: hashtable json-print ( hashtable -- )
CHAR: { write1
[ [ swap >json % CHAR: : , >json % ] "" make ]
{ } assoc>map "," join write
CHAR: } write1 ;
Author: | otoburb |
Mode: | factor |
Date: | Thu, 23 Jun 2011 05:36:10 |
Plain Text |
M: hashtable json-print ( hashtable -- )
CHAR: { write1
jsvar-encode? get
[ [ [ swap jsvar-encode >json % CHAR: : , >json % ] "" make ] ]
[ [ [ swap >json % CHAR: : , >json % ] "" make ] ] if
{ } assoc>map "," join write
CHAR: } write1 ;
M: hashtable json-print ( hashtable -- )
CHAR: { write1
[ [ swap jsvar-encode? get [ jsvar-encode ] when >json % CHAR: : , >json % ] "" make ]
{ } assoc>map "," join write
CHAR: } write1 ;
Author: | jon |
Mode: | factor |
Date: | Thu, 23 Jun 2011 15:03:19 |
Plain Text |
If you want to avoid getting the variable for each key/value, I'd say the idiomatic way to go would be to get jsvar-encode? outside and currify it into the quotation:
M: hashtable json-print ( hashtable -- )
CHAR: { write1
jsvar-encode? get
'[ [ swap _ [ jsvar-encode ] when >json % CHAR: : , >json % ] "" make ]
{ } assoc>map "," join write
CHAR: } write1 ;
(or something along these lines..)
Author: | otoburb |
Mode: | factor |
Date: | Tue, 5 Jul 2011 02:55:52 |
Plain Text |
@jon You are awesome. That worked like a charm. I had a needlessly complex solution that also currified, but yours was much more elegant. Thanks.
New Annotation