]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/factor
authorJoe Groff <joe@victoria.(none)>
Fri, 14 Aug 2009 14:55:05 +0000 (10:55 -0400)
committerJoe Groff <joe@victoria.(none)>
Fri, 14 Aug 2009 14:55:05 +0000 (10:55 -0400)
1  2 
basis/inverse/inverse.factor
core/math/parser/parser.factor

index 2183c95f080db60145007c7016d888ea7188d3a5,7a9e821b37740a2ce9a1fdd45a632f2ab7acb678..39a2d5f3dc96f0f0b01de3f8535cf95f1bd5b02a
@@@ -1,6 -1,6 +1,6 @@@
  ! Copyright (C) 2007, 2009 Daniel Ehrenberg.
  ! See http://factorcode.org/license.txt for BSD license.
- USING: accessors kernel words summary slots quotations
+ USING: accessors kernel locals words summary slots quotations
  sequences assocs math arrays stack-checker effects
  continuations debugger classes.tuple namespaces make vectors
  bit-arrays byte-arrays strings sbufs math.functions macros
@@@ -231,12 -231,24 +231,24 @@@ DEFER: _
  \ output>sequence 2 [ [undo] '[ dup _ assure-same-class _ input<sequence ] ] define-pop-inverse
  \ input<sequence 1 [ [undo] '[ _ { } output>sequence ] ] define-pop-inverse
  
+ ! conditionals
+ :: undo-if-empty ( result a b -- seq )
+    a call( -- b ) result = [ { } ] [ result b [undo] call( a -- b ) ] if ;
+ :: undo-if* ( result a b -- boolean )
+    b call( -- b ) result = [ f ] [ result a [undo] call( a -- b ) ] if ;
+ \ if-empty 2 [ swap [ undo-if-empty ] 2curry ] define-pop-inverse
+ \ if* 2 [ swap [ undo-if* ] 2curry ] define-pop-inverse
  ! Constructor inverse
  : deconstruct-pred ( class -- quot )
      "predicate" word-prop [ dupd call assure ] curry ;
  
  : slot-readers ( class -- quot )
 -    all-slots [ name>> reader-word 1quotation ] map [ cleave ] curry ;
 +    class-slots [ name>> reader-word 1quotation ] map [ cleave ] curry ;
  
  : ?wrapped ( object -- wrapped )
      dup wrapper? [ wrapped>> ] when ;
@@@ -283,4 -295,4 +295,4 @@@ M: no-match summary drop "Fall through 
      reverse [ [ [undo] ] dip compose ] { } assoc>map
      recover-chain ;
  
- MACRO: switch ( quot-alist -- ) [switch] ;
+ MACRO: switch ( quot-alist -- ) [switch] ;
index cc01699bd4d2790ae1de5fb99660fd55de3915ed,ef8f350e27c9e4870633da2e69e0e2a4228e4214..21062baf4bbe985c8d007023720a2d28eb560846
@@@ -28,16 -28,13 +28,16 @@@ IN: math.parse
          { CHAR: d 13 }
          { CHAR: e 14 }
          { CHAR: f 15 }
 -    } at 255 or ; inline
 +        { CHAR: , f }
 +    } at* [ drop 255 ] unless ; inline
  
  : string>digits ( str -- digits )
      [ digit> ] B{ } map-as ; inline
  
  : (digits>integer) ( valid? accum digit radix -- valid? accum )
 -    2dup < [ swapd * + ] [ 2drop 2drop f 0 ] if ; inline
 +    over [
 +        2dup < [ swapd * + ] [ 2drop 2drop f 0 ] if
 +    ] [ 2drop ] if ; inline
  
  : each-digit ( seq radix quot -- n/f )
      [ t 0 ] 3dip curry each swap [ drop f ] unless ; inline
@@@ -83,7 -80,6 +83,7 @@@ SYMBOL: negative
      ] if ; inline
  
  : string>float ( str -- n/f )
 +    [ CHAR: , eq? not ] filter
      >byte-array 0 suffix (string>float) ;
  
  PRIVATE>
@@@ -135,7 -131,7 +135,7 @@@ M: ratio >bas
      [
          dup 0 < negative? set
          abs 1 /mod
-         [ dup zero? [ drop "" ] [ (>base) sign append ] if ]
+         [ [ "" ] [ (>base) sign append ] if-zero ]
          [
              [ numerator (>base) ]
              [ denominator (>base) ] bi