From 0609f790c75c22b12592acc934616b1ca57226a4 Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Mon, 18 Apr 2016 20:16:33 -0700 Subject: [PATCH] money: cleanup. --- extra/money/money.factor | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/extra/money/money.factor b/extra/money/money.factor index a3ac4ebb13..9db6b19d6b 100644 --- a/extra/money/money.factor +++ b/extra/money/money.factor @@ -1,33 +1,42 @@ -USING: io kernel math math.functions math.parser parser lexer -namespaces make sequences splitting grouping combinators -continuations ; +! Copyright (C) 2008 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: grouping io kernel lexer math math.functions math.parser +namespaces sequences splitting ; IN: money SYMBOL: currency-token -CHAR: $ \ currency-token set-global +CHAR: $ currency-token set-global + +string) ( dollars cents -- string ) +: format-money ( dollars cents -- string ) [ number>string ] bi@ [ 3 group "," join ] [ 2 CHAR: 0 pad-head ] bi* "." glue ; -: money>string ( object -- string ) - dollars/cents (money>string) currency-token get prefix ; +PRIVATE> -: money. ( object -- ) money>string print ; +: money>string ( number -- string ) + dollars/cents format-money currency-token get prefix ; + +: money. ( number -- ) money>string print ; ERROR: not-an-integer x ; +number [ nip ] [ not-an-integer ] if* ] bi@ - ] keep length - 10^ / + swap [ neg ] when ; + ] keep length 10^ / + swap [ neg ] when ; + +PRIVATE> SYNTAX: DECIMAL: scan-token parse-decimal suffix! ;