From: John Benediktsson Date: Wed, 20 Feb 2013 18:42:21 +0000 (-0800) Subject: sequences: define a single "?set-nth" that is used. X-Git-Tag: 0.97~2028 X-Git-Url: https://gitweb.factorcode.org/gitweb.cgi?p=factor.git;a=commitdiff_plain;h=1524d43c9cedf47756c34e6be65d150c32c49fbb sequences: define a single "?set-nth" that is used. --- diff --git a/basis/bit-sets/bit-sets.factor b/basis/bit-sets/bit-sets.factor index 30e0561ad0..320f0d3fa7 100644 --- a/basis/bit-sets/bit-sets.factor +++ b/basis/bit-sets/bit-sets.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2009 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: kernel accessors sequences byte-arrays bit-arrays math -math.bitwise hints sets sequences.private ; +math.bitwise hints sets ; IN: bit-sets TUPLE: bit-set { table bit-array read-only } ; @@ -19,13 +19,6 @@ M: bit-set adjoin ! go in the set [ t ] 2dip table>> set-nth ; - - M: bit-set delete ! This isn't allowed to throw an error if the elt wasn't ! in the set diff --git a/basis/game/input/iokit/iokit.factor b/basis/game/input/iokit/iokit.factor index 1112bacc95..d07b069160 100644 --- a/basis/game/input/iokit/iokit.factor +++ b/basis/game/input/iokit/iokit.factor @@ -1,11 +1,9 @@ -USING: cocoa cocoa.plists core-foundation iokit iokit.hid -kernel cocoa.enumeration destructors math.parser cocoa.application -core-foundation.data core-foundation.strings -sequences locals combinators.short-circuit threads -namespaces assocs arrays combinators hints alien -core-foundation.run-loop accessors sequences.private -alien.c-types alien.data math parser game.input vectors -bit-arrays unix.types ; +USING: accessors alien alien.c-types arrays assocs bit-arrays +cocoa.application cocoa.enumeration cocoa.plists combinators +combinators.short-circuit core-foundation core-foundation.data +core-foundation.run-loop core-foundation.strings destructors +game.input hints iokit iokit.hid kernel locals math namespaces +sequences vectors ; FROM: namespaces => change-global ; IN: game.input.iokit @@ -177,9 +175,6 @@ CONSTANT: pov-values HINTS: record-controller { controller-state alien } ; -: ?set-nth ( elt n seq -- ) - 2dup bounds-check? [ set-nth-unsafe ] [ 3drop ] if ; inline - : record-keyboard ( keyboard-state value -- ) dup IOHIDValueGetElement dup keyboard-key? [ [ IOHIDValueGetIntegerValue c-bool> ] diff --git a/basis/unicode/data/data.factor b/basis/unicode/data/data.factor index e32740391b..860d5bb56f 100644 --- a/basis/unicode/data/data.factor +++ b/basis/unicode/data/data.factor @@ -5,8 +5,7 @@ io.files hashtables quotations splitting grouping arrays io math.parser math.order byte-arrays namespaces math.bitwise compiler.units parser io.encodings.ascii interval-maps ascii sets combinators locals math.ranges sorting make -strings.parser io.encodings.utf8 memoize simple-flat-file -sequences.private ; +strings.parser io.encodings.utf8 memoize simple-flat-file ; IN: unicode.data ! the maximum unicode char in the first 3 planes -: ?set-nth ( elt n seq -- ) - 2dup bounds-check? [ set-nth-unsafe ] [ 3drop ] if ; inline - :: fill-ranges ( table -- table ) name-map sort-values keys [ { [ "first>" tail? ] [ "last>" tail? ] } 1|| ] filter diff --git a/core/sequences/sequences-docs.factor b/core/sequences/sequences-docs.factor index 18c9683192..b80a9dbca9 100644 --- a/core/sequences/sequences-docs.factor +++ b/core/sequences/sequences-docs.factor @@ -179,6 +179,10 @@ HELP: ?nth { $values { "n" "an integer" } { "seq" sequence } { "elt/f" "an object or " { $link f } } } { $description "A forgiving version of " { $link nth } ". If the index is out of bounds, or if the sequence is " { $link f } ", simply outputs " { $link f } "." } ; +HELP: ?set-nth +{ $values { "elt" object } { "n" "an integer" } { "seq" sequence } } +{ $description "A forgiving version of " { $link set-nth } ". If the index is out of bounds, does nothing." } ; + HELP: ?first { $values { "seq" sequence } { "elt/f" "an object or " { $link f } } } { $description "A forgiving version of " { $link first } ". If the sequence is empty, or if the sequence is " { $link f } ", simply outputs " { $link f } "." } diff --git a/core/sequences/sequences.factor b/core/sequences/sequences.factor index a7db7b63b2..3e6be34882 100644 --- a/core/sequences/sequences.factor +++ b/core/sequences/sequences.factor @@ -175,6 +175,9 @@ PRIVATE> : ?nth ( n seq -- elt/f ) 2dup bounds-check? [ nth-unsafe ] [ 2drop f ] if ; inline +: ?set-nth ( elt n seq -- ) + 2dup bounds-check? [ set-nth-unsafe ] [ 3drop ] if ; inline + : ?first ( seq -- elt/f ) 0 swap ?nth ; inline : ?second ( seq -- elt/f ) 1 swap ?nth ; inline : ?last ( seq -- elt/f ) diff --git a/extra/maze/maze.factor b/extra/maze/maze.factor index bf98895b52..0e4af964d3 100644 --- a/extra/maze/maze.factor +++ b/extra/maze/maze.factor @@ -1,7 +1,7 @@ ! From http://www.ffconsultancy.com/ocaml/maze/index.html USING: accessors arrays fry kernel math math.order math.vectors namespaces opengl.gl random sequences ui ui.gadgets -ui.gadgets.canvas ui.render sequences.private ; +ui.gadgets.canvas ui.render ; IN: maze CONSTANT: line-width 8 @@ -10,13 +10,6 @@ SYMBOL: visited : unvisited? ( cell -- ? ) first2 visited get ?nth ?nth ; - - : visit ( cell -- ) f swap first2 visited get ?nth ?set-nth ; : choices ( cell -- seq )