From bf3b15409148ce2a0cdedb285e87a460111ebf63 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 24 Sep 2009 19:43:57 -0500 Subject: [PATCH 1/5] rename a couple of strings.parser words --- core/strings/parser/parser.factor | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/core/strings/parser/parser.factor b/core/strings/parser/parser.factor index 49287ed112..6ef5075fd9 100644 --- a/core/strings/parser/parser.factor +++ b/core/strings/parser/parser.factor @@ -84,11 +84,6 @@ name>char-hook [ lexer get (>>column) ] bi ; -: find-next-token ( ch -- i elt ) - CHAR: \ 2array - [ lexer get [ column>> ] [ line-text>> ] bi ] dip - [ member? ] curry find-from ; - : rest-of-line ( lexer -- seq ) [ line-text>> ] [ column>> ] bi tail-slice ; @@ -107,10 +102,6 @@ ERROR: escaped-char-expected ; escaped-char-expected ] if ; -: next-line% ( lexer -- ) - [ rest-of-line % ] - [ next-line "\n" % ] bi ; - : rest-begins? ( string -- ? ) [ lexer get [ line-text>> ] [ column>> ] bi tail-slice @@ -119,6 +110,15 @@ ERROR: escaped-char-expected ; : advance-lexer ( n -- ) [ lexer get ] dip [ + ] curry change-column drop ; inline +: find-next-token ( ch -- i elt ) + CHAR: \ 2array + [ lexer get [ column>> ] [ line-text>> ] bi ] dip + [ member? ] curry find-from ; + +: next-line% ( lexer -- ) + [ rest-of-line % ] + [ next-line "\n" % ] bi ; + : take-double-quotes ( -- string ) lexer get dup current-char CHAR: " = [ [ ] [ column>> ] [ line-text>> ] tri @@ -138,38 +138,38 @@ ERROR: escaped-char-expected ; lexer get advance-char ] if ; -DEFER: (parse-long-string) +DEFER: ((parse-multiline-string)) : parse-found-token ( i string token -- ) [ lexer-before % ] dip CHAR: \ = [ - lexer get [ next-char , ] [ next-char , ] bi (parse-long-string) + lexer get [ next-char , ] [ next-char , ] bi ((parse-multiline-string)) ] [ dup rest-begins? [ end-string-parse ] [ - lexer get next-char , (parse-long-string) + lexer get next-char , ((parse-multiline-string)) ] if ] if ; ERROR: trailing-characters string ; -: (parse-long-string) ( string -- ) +: ((parse-multiline-string)) ( string -- ) lexer get still-parsing? [ dup first find-next-token [ parse-found-token ] [ drop lexer get next-line% - (parse-long-string) + ((parse-multiline-string)) ] if* ] [ unexpected-eof ] if ; -PRIVATE> +: (parse-multiline-string) ( string -- string' ) + [ ((parse-multiline-string)) ] "" make ; -: parse-long-string ( string -- string' ) - [ (parse-long-string) ] "" make ; +PRIVATE> : parse-multiline-string ( -- string ) lexer get rest-of-line "\"\"" head? [ @@ -177,4 +177,4 @@ PRIVATE> "\"\"\"" ] [ "\"" - ] if parse-long-string unescape-string ; + ] if (parse-multiline-string) unescape-string ; From c0294195e67f4e9b65c3d332ebd5a2eaa871d306 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 24 Sep 2009 19:45:03 -0500 Subject: [PATCH 2/5] rename another strings.parser word --- core/strings/parser/parser.factor | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/core/strings/parser/parser.factor b/core/strings/parser/parser.factor index 6ef5075fd9..a69c3becc3 100644 --- a/core/strings/parser/parser.factor +++ b/core/strings/parser/parser.factor @@ -138,37 +138,34 @@ ERROR: escaped-char-expected ; lexer get advance-char ] if ; -DEFER: ((parse-multiline-string)) +DEFER: (parse-multiline-string) : parse-found-token ( i string token -- ) [ lexer-before % ] dip CHAR: \ = [ - lexer get [ next-char , ] [ next-char , ] bi ((parse-multiline-string)) + lexer get [ next-char , ] [ next-char , ] bi (parse-multiline-string) ] [ dup rest-begins? [ end-string-parse ] [ - lexer get next-char , ((parse-multiline-string)) + lexer get next-char , (parse-multiline-string) ] if ] if ; ERROR: trailing-characters string ; -: ((parse-multiline-string)) ( string -- ) +: (parse-multiline-string) ( string -- ) lexer get still-parsing? [ dup first find-next-token [ parse-found-token ] [ drop lexer get next-line% - ((parse-multiline-string)) + (parse-multiline-string) ] if* ] [ unexpected-eof ] if ; -: (parse-multiline-string) ( string -- string' ) - [ ((parse-multiline-string)) ] "" make ; - PRIVATE> : parse-multiline-string ( -- string ) @@ -177,4 +174,4 @@ PRIVATE> "\"\"\"" ] [ "\"" - ] if (parse-multiline-string) unescape-string ; + ] if [ (parse-multiline-string) ] "" make unescape-string ; From 9963213900f0b758cc38d263bc1f51265e330030 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 24 Sep 2009 19:47:44 -0500 Subject: [PATCH 3/5] rename a couple more words --- core/strings/parser/parser.factor | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/strings/parser/parser.factor b/core/strings/parser/parser.factor index a69c3becc3..0a5572e530 100644 --- a/core/strings/parser/parser.factor +++ b/core/strings/parser/parser.factor @@ -74,7 +74,7 @@ name>char-hook [ > ] [ column>> ] bi tail-slice ] dip head? ; @@ -141,11 +141,11 @@ ERROR: escaped-char-expected ; DEFER: (parse-multiline-string) : parse-found-token ( i string token -- ) - [ lexer-before % ] dip + [ lexer-subseq % ] dip CHAR: \ = [ lexer get [ next-char , ] [ next-char , ] bi (parse-multiline-string) ] [ - dup rest-begins? [ + dup lexer-head? [ end-string-parse ] [ lexer get next-char , (parse-multiline-string) From 5e9de85aac9b55171c06916049ea7341485946f2 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 24 Sep 2009 22:11:23 -0500 Subject: [PATCH 4/5] add benchmarks to cacluate e using decimals, ratios --- work/benchmark/e-decimals/authors.txt | 1 + work/benchmark/e-decimals/e-decimals.factor | 14 ++++++++++++++ work/benchmark/e-ratios/authors.txt | 1 + work/benchmark/e-ratios/e-ratios.factor | 12 ++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 work/benchmark/e-decimals/authors.txt create mode 100644 work/benchmark/e-decimals/e-decimals.factor create mode 100644 work/benchmark/e-ratios/authors.txt create mode 100644 work/benchmark/e-ratios/e-ratios.factor diff --git a/work/benchmark/e-decimals/authors.txt b/work/benchmark/e-decimals/authors.txt new file mode 100644 index 0000000000..b4bd0e7b35 --- /dev/null +++ b/work/benchmark/e-decimals/authors.txt @@ -0,0 +1 @@ +Doug Coleman \ No newline at end of file diff --git a/work/benchmark/e-decimals/e-decimals.factor b/work/benchmark/e-decimals/e-decimals.factor new file mode 100644 index 0000000000..d202e5ff76 --- /dev/null +++ b/work/benchmark/e-decimals/e-decimals.factor @@ -0,0 +1,14 @@ +! Copyright (C) 2009 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: decimals kernel locals math math.combinatorics math.ranges +sequences ; +IN: benchmark.e-decimals + +:: calculate-e-decimals ( n -- e ) + n [1,b] [ factorial 0 D: 1 swap n D/ ] map + D: 1 [ D+ ] reduce ; + +: calculate-e-decimals-benchmark ( -- ) + 5 [ 800 calculate-e-decimals drop ] times ; + +MAIN: calculate-e-decimals-benchmark diff --git a/work/benchmark/e-ratios/authors.txt b/work/benchmark/e-ratios/authors.txt new file mode 100644 index 0000000000..b4bd0e7b35 --- /dev/null +++ b/work/benchmark/e-ratios/authors.txt @@ -0,0 +1 @@ +Doug Coleman \ No newline at end of file diff --git a/work/benchmark/e-ratios/e-ratios.factor b/work/benchmark/e-ratios/e-ratios.factor new file mode 100644 index 0000000000..4957822b5e --- /dev/null +++ b/work/benchmark/e-ratios/e-ratios.factor @@ -0,0 +1,12 @@ +! Copyright (C) 2009 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: kernel math math.combinatorics math.ranges sequences ; +IN: benchmark.e-ratios + +: calculate-e-ratios ( n -- e ) + iota [ factorial recip ] sigma ; + +: calculate-e-ratios-benchmark ( -- ) + 5 [ 300 calculate-e-ratios drop ] times ; + +MAIN: calculate-e-ratios-benchmark From b85616fa6197a0c1834940fbd60eadba29bb211e Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 24 Sep 2009 22:58:42 -0500 Subject: [PATCH 5/5] move benchmarks from work to extra. wtf oops --- {work => extra}/benchmark/e-decimals/authors.txt | 0 {work => extra}/benchmark/e-decimals/e-decimals.factor | 0 {work => extra}/benchmark/e-ratios/authors.txt | 0 {work => extra}/benchmark/e-ratios/e-ratios.factor | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename {work => extra}/benchmark/e-decimals/authors.txt (100%) rename {work => extra}/benchmark/e-decimals/e-decimals.factor (100%) rename {work => extra}/benchmark/e-ratios/authors.txt (100%) rename {work => extra}/benchmark/e-ratios/e-ratios.factor (100%) diff --git a/work/benchmark/e-decimals/authors.txt b/extra/benchmark/e-decimals/authors.txt similarity index 100% rename from work/benchmark/e-decimals/authors.txt rename to extra/benchmark/e-decimals/authors.txt diff --git a/work/benchmark/e-decimals/e-decimals.factor b/extra/benchmark/e-decimals/e-decimals.factor similarity index 100% rename from work/benchmark/e-decimals/e-decimals.factor rename to extra/benchmark/e-decimals/e-decimals.factor diff --git a/work/benchmark/e-ratios/authors.txt b/extra/benchmark/e-ratios/authors.txt similarity index 100% rename from work/benchmark/e-ratios/authors.txt rename to extra/benchmark/e-ratios/authors.txt diff --git a/work/benchmark/e-ratios/e-ratios.factor b/extra/benchmark/e-ratios/e-ratios.factor similarity index 100% rename from work/benchmark/e-ratios/e-ratios.factor rename to extra/benchmark/e-ratios/e-ratios.factor