Add inc-at word to core, and update some usages of at+ to use it instead
parent
b5e8b14722
commit
a90118da5d
|
@ -151,14 +151,14 @@ SYMBOL: node-count
|
|||
H{ } clone intrinsics-called set
|
||||
|
||||
0 swap [
|
||||
>r 1+ r>
|
||||
[ 1+ ] dip
|
||||
dup #call? [
|
||||
word>> {
|
||||
{ [ dup "intrinsics" word-prop over "if-intrinsics" word-prop or ] [ intrinsics-called ] }
|
||||
{ [ dup generic? ] [ generics-called ] }
|
||||
{ [ dup method-body? ] [ methods-called ] }
|
||||
[ words-called ]
|
||||
} cond 1 -rot get at+
|
||||
} cond inc-at
|
||||
] [ drop ] if
|
||||
] each-node
|
||||
node-count set
|
||||
|
|
|
@ -152,7 +152,7 @@ DEFER: (flat-length)
|
|||
SYMBOL: history
|
||||
|
||||
: remember-inlining ( word -- )
|
||||
[ [ 1 ] dip inlining-count get at+ ]
|
||||
[ inlining-count get inc-at ]
|
||||
[ history [ swap suffix ] change ]
|
||||
bi ;
|
||||
|
||||
|
|
|
@ -67,6 +67,8 @@ HELP: :>
|
|||
{ $syntax ":> binding" }
|
||||
{ $description "Introduces a new binding, lexically scoped to the enclosing quotation or definition." }
|
||||
{ $notes
|
||||
"This word can only be used inside a lambda word, lambda quotation or let binding form."
|
||||
$nl
|
||||
"Lambda and let forms are really just syntax sugar for " { $link POSTPONE: :> } "."
|
||||
$nl
|
||||
"Lambdas desugar as follows:"
|
||||
|
|
|
@ -13,10 +13,10 @@ SYMBOL: message-histogram
|
|||
|
||||
: analyze-entry ( entry -- )
|
||||
dup level>> { ERROR CRITICAL } memq? [ dup errors get push ] when
|
||||
1 over word-name>> word-histogram get at+
|
||||
dup word-name>> word-histogram get inc-at
|
||||
dup word-name>> word-names get member? [
|
||||
1 over [ level>> ] [ word-name>> ] [ message>> ] tri 3array
|
||||
message-histogram get at+
|
||||
dup [ level>> ] [ word-name>> ] [ message>> ] tri 3array
|
||||
message-histogram get inc-at
|
||||
] when
|
||||
drop ;
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ IN: tools.memory
|
|||
|
||||
: heap-stat-step ( obj counts sizes -- )
|
||||
[ over ] dip
|
||||
[ [ [ drop 1 ] [ class ] bi ] dip at+ ]
|
||||
[ [ class ] dip inc-at ]
|
||||
[ [ [ size ] [ class ] bi ] dip at+ ] 2bi* ;
|
||||
|
||||
PRIVATE>
|
||||
|
|
|
@ -90,6 +90,7 @@ ARTICLE: "assocs-mutation" "Storing keys and values in assocs"
|
|||
{ $subsection rename-at }
|
||||
{ $subsection change-at }
|
||||
{ $subsection at+ }
|
||||
{ $subsection inc-at }
|
||||
{ $see-also set-at delete-at clear-assoc push-at } ;
|
||||
|
||||
ARTICLE: "assocs-conversions" "Associative mapping conversions"
|
||||
|
@ -349,6 +350,11 @@ HELP: at+
|
|||
{ $description "Adds " { $snippet "n" } " to the value associated with " { $snippet "key" } "; if there is no value, stores " { $snippet "n" } ", thus behaving as if the value was 0." }
|
||||
{ $side-effects "assoc" } ;
|
||||
|
||||
HELP: inc-at
|
||||
{ $values { "key" object } { "assoc" assoc } }
|
||||
{ $description "Adds 1 to the value associated with " { $snippet "key" } "; if there is no value, stores 1." }
|
||||
{ $side-effects "assoc" } ;
|
||||
|
||||
HELP: >alist
|
||||
{ $values { "assoc" assoc } { "newassoc" "an array of key/value pairs" } }
|
||||
{ $contract "Converts an associative structure into an association list." }
|
||||
|
|
|
@ -141,8 +141,9 @@ M: assoc assoc-clone-like ( assoc exemplar -- newassoc )
|
|||
: change-at ( key assoc quot -- )
|
||||
[ [ at ] dip call ] 3keep drop set-at ; inline
|
||||
|
||||
: at+ ( n key assoc -- )
|
||||
[ 0 or + ] change-at ;
|
||||
: at+ ( n key assoc -- ) [ 0 or + ] change-at ; inline
|
||||
|
||||
: inc-at ( key assoc -- ) [ 1 ] 2dip at+ ; inline
|
||||
|
||||
: map>assoc ( seq quot exemplar -- assoc )
|
||||
[ [ 2array ] compose { } map-as ] dip assoc-like ; inline
|
||||
|
|
Loading…
Reference in New Issue