From: Doug Coleman Date: Sat, 25 Feb 2023 19:15:47 +0000 (-0600) Subject: extras: remove circular dependency X-Git-Tag: 0.99~513 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=d2b012ef8c05c48c8c85cb11d89eb2ea5af844c0 extras: remove circular dependency --- diff --git a/extra/assocs/extras/extras.factor b/extra/assocs/extras/extras.factor index adf8ceb81a..8ac28df46e 100644 --- a/extra/assocs/extras/extras.factor +++ b/extra/assocs/extras/extras.factor @@ -1,9 +1,12 @@ ! Copyright (C) 2012 John Benediktsson, Doug Coleman ! See https://factorcode.org/license.txt for BSD license USING: arrays assocs assocs.private kernel math math.statistics -sequences sequences.extras sets ; +sequences sets ; IN: assocs.extras +: change-of ( ..a assoc key quot: ( ..a value -- ..b newvalue ) -- ..b assoc ) + [ [ of ] dip call ] 2keepd rot set-of ; inline + : of* ( assoc key -- value/f ? ) swap at* ; inline : of+ ( assoc key n -- assoc ) '[ 0 or _ + ] change-of ; inline @@ -21,17 +24,10 @@ IN: assocs.extras : rename-of ( assoc key newkey -- assoc ) [ delete-of* ] dip swap [ set-of ] [ 2drop ] if ; -: at+* ( n key assoc -- old new ) [ 0 or [ + ] keep swap dup ] change-at ; inline - -: inc-at* ( key assoc -- old new ) [ 1 ] 2dip at+* ; inline - : inc-of ( assoc key -- assoc ) 1 of+ ; inline : inc-of* ( assoc key -- assoc old new ) 1 of+* ; inline -: change-of ( ..a assoc key quot: ( ..a value -- ..b newvalue ) -- ..b assoc ) - [ [ of ] dip call ] 2keepd rot set-of ; inline - : ?change-of ( ..a assoc key quot: ( ..a value -- ..b newvalue ) -- ..b assoc ) [ set-of ] compose [ 2dup ?of ] dip [ 2drop ] if ; inline @@ -57,12 +53,6 @@ IN: assocs.extras : deep-set-of ( assoc seq elt -- ) [ deep-of-but-last ] dip spin set-at ; inline -: zip-longest-with ( seq1 seq2 fill -- assoc ) - pad-longest zip ; - -: zip-longest ( seq1 seq2 -- assoc ) - f zip-longest-with ; - : substitute! ( seq assoc -- seq ) substituter map! ; diff --git a/extra/sequences/extras/extras.factor b/extra/sequences/extras/extras.factor index 39d03fa9df..a36caa74de 100644 --- a/extra/sequences/extras/extras.factor +++ b/extra/sequences/extras/extras.factor @@ -1,3 +1,4 @@ + USING: accessors arrays assocs combinators generalizations grouping growable heaps kernel math math.order ranges sequences sequences.private shuffle sorting splitting vectors ; @@ -60,6 +61,12 @@ IN: sequences.extras pick surround-as ] if-zero ; +: zip-longest-with ( seq1 seq2 fill -- assoc ) + pad-longest zip ; + +: zip-longest ( seq1 seq2 -- assoc ) + f zip-longest-with ; + : change-nths ( ... indices seq quot: ( ... elt -- ... elt' ) -- ... ) [ change-nth ] 2curry each ; inline @@ -295,12 +302,13 @@ PRIVATE> : 0accumulate ( ... seq quot: ( ... prev elt -- ... next ) -- ... final newseq ) over 0accumulate-as ; inline -: occurrence-count-by ( seq quot: ( elt -- elt' ) -- hash seq' ) - '[ nip @ over inc-at* drop ] [ H{ } clone ] 2dip 0accumulate ; inline - : nth-index ( n obj seq -- i ) [ = dup [ drop 1 - dup 0 < ] when ] with find drop nip ; +: at+* ( n key assoc -- old new ) [ 0 or [ + ] keep swap dup ] change-at ; inline + +: inc-at* ( key assoc -- old new ) [ 1 ] 2dip at+* ; inline + : progressive-index-by-as ( seq1 seq2 quot exemplar -- hash seq' ) [ pick length '[