From a3cf0d70bac0eb2ad5737d82b80972120d5bfc8b Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Mon, 6 May 2013 08:34:32 -0700 Subject: [PATCH] math.combinators: fix help-lint errors. --- .../math/combinators/combinators-docs.factor | 30 ++++++++----------- .../math/combinators/combinators-tests.factor | 5 ++-- extra/math/combinators/combinators.factor | 18 +++++++---- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/extra/math/combinators/combinators-docs.factor b/extra/math/combinators/combinators-docs.factor index 494e9fe249..49da14fcf2 100644 --- a/extra/math/combinators/combinators-docs.factor +++ b/extra/math/combinators/combinators-docs.factor @@ -1,24 +1,18 @@ -USING: arrays help.markup help.syntax math -sequences.private vectors strings kernel math.order layouts -quotations generic.single ; +USING: help.markup help.syntax math ; IN: math.combinators HELP: when-negative -{ $values - { "n" "an integer" } { "true" "a quotation" } { "m" "an integer" } } -{ $description "When the n value is negative, calls the true quotation. The n value is passed to the quotation." } -{ $examples "The following two lines are equivalent." - { $example "-1 [ 1 + ] when-negative\n-1 dup 0 < [ 1 + ] when" - "0\n0" - } +{ $values { "n" real } { "true" "the first quotation of an " { $link if-negative } } } +{ $description "When " { $snippet "n" } " is negative, calls the " { $snippet "true" } " quotation with " { $snippet "n" } "." } +{ $examples + { $example "USING: math math.combinators prettyprint ;" "-3 [ 1 + ] when-negative ." "-2" } + { $example "USING: math math.combinators prettyprint ;" "3.5 [ 1 + ] when-negative ." "3.5" } } ; HELP: when-positive -{ $values - { "n" "an integer" } { "true" "a quotation" } { "m" "an integer" } } -{ $description "When the n value is positive, calls the true quotation. The n value is passed to the quotation." } -{ $examples "The following two lines are equivalent." - { $example "1 [ 1 + ] when-positive\n1 dup 0 > [ 1 + ] when" - "2\n2" - } -} ; \ No newline at end of file +{ $values { "n" real } { "true" "the first quotation of an " { $link if-positive } } } +{ $description "When " { $snippet "n" } " is positive, calls the " { $snippet "true" } " quotation with " { $snippet "n" } "." } +{ $examples + { $example "USING: math math.combinators prettyprint ;" "1.5 [ 1 + ] when-positive ." "2.5" } + { $example "USING: math math.combinators prettyprint ;" "-1 [ 1 + ] when-positive ." "-1" } +} ; diff --git a/extra/math/combinators/combinators-tests.factor b/extra/math/combinators/combinators-tests.factor index 430c07b765..a8448d6d6b 100644 --- a/extra/math/combinators/combinators-tests.factor +++ b/extra/math/combinators/combinators-tests.factor @@ -1,7 +1,6 @@ ! Copyright (C) 2013 Loryn Jenkins. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel math math.combinators - tools.test ; +USING: kernel math math.combinators tools.test ; IN: math.combinators.tests [ 0 ] [ -3 [ drop 0 ] when-negative ] unit-test @@ -10,4 +9,4 @@ IN: math.combinators.tests [ 0 ] [ 3 [ drop 0 ] when-positive ] unit-test [ 4 ] [ 3 [ 1 + ] when-positive ] unit-test -[ -2 ] [ -2 [ 0 ] when-positive ] unit-test \ No newline at end of file +[ -2 ] [ -2 [ 0 ] when-positive ] unit-test diff --git a/extra/math/combinators/combinators.factor b/extra/math/combinators/combinators.factor index bad04f5917..cc29c39e2c 100644 --- a/extra/math/combinators/combinators.factor +++ b/extra/math/combinators/combinators.factor @@ -1,10 +1,16 @@ ! Copyright (C) 2013 Loryn Jenkins. ! See http://factorcode.org/license.txt for BSD license. -USING: kernel math fry ; +USING: kernel math ; IN: math.combinators -: when-negative ( ..n true: ( ..a -- ..b ) -- ..m ) - '[ _ dup 0 < [ @ ] when ] call ; inline - -: when-positive ( ..n true: ( ..a -- ..b ) -- ..m ) - '[ _ dup 0 > [ @ ] when ] call ; inline \ No newline at end of file +: if-negative ( ..a n true: ( ..a n -- ..b ) false: ( ..a n -- ..b ) -- ..b ) + [ dup 0 < ] 2dip if ; inline + +: if-positive ( ..a n true: ( ..a n -- ..b ) false: ( ..a n -- ..b ) -- ..b ) + [ dup 0 > ] 2dip if ; inline + +: when-negative ( ..a n true: ( ..a n -- ..b ) -- ..b ) + [ ] if-negative ; inline + +: when-positive ( ..a n true: ( ..a n -- ..b ) -- ..b ) + [ ] if-positive ; inline