sequences: define a single "?set-nth" that is used.

db4
John Benediktsson 2013-02-20 10:42:21 -08:00
parent 55cfbf072f
commit 1524d43c9c
6 changed files with 16 additions and 32 deletions

View File

@ -1,7 +1,7 @@
! Copyright (C) 2009 Slava Pestov. ! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: kernel accessors sequences byte-arrays bit-arrays math USING: kernel accessors sequences byte-arrays bit-arrays math
math.bitwise hints sets sequences.private ; math.bitwise hints sets ;
IN: bit-sets IN: bit-sets
TUPLE: bit-set { table bit-array read-only } ; TUPLE: bit-set { table bit-array read-only } ;
@ -19,13 +19,6 @@ M: bit-set adjoin
! go in the set ! go in the set
[ t ] 2dip table>> set-nth ; [ t ] 2dip table>> set-nth ;
<PRIVATE
: ?set-nth ( elt n seq -- )
2dup bounds-check? [ set-nth-unsafe ] [ 3drop ] if ; inline
PRIVATE>
M: bit-set delete M: bit-set delete
! This isn't allowed to throw an error if the elt wasn't ! This isn't allowed to throw an error if the elt wasn't
! in the set ! in the set

View File

@ -1,11 +1,9 @@
USING: cocoa cocoa.plists core-foundation iokit iokit.hid USING: accessors alien alien.c-types arrays assocs bit-arrays
kernel cocoa.enumeration destructors math.parser cocoa.application cocoa.application cocoa.enumeration cocoa.plists combinators
core-foundation.data core-foundation.strings combinators.short-circuit core-foundation core-foundation.data
sequences locals combinators.short-circuit threads core-foundation.run-loop core-foundation.strings destructors
namespaces assocs arrays combinators hints alien game.input hints iokit iokit.hid kernel locals math namespaces
core-foundation.run-loop accessors sequences.private sequences vectors ;
alien.c-types alien.data math parser game.input vectors
bit-arrays unix.types ;
FROM: namespaces => change-global ; FROM: namespaces => change-global ;
IN: game.input.iokit IN: game.input.iokit
@ -177,9 +175,6 @@ CONSTANT: pov-values
HINTS: record-controller { controller-state alien } ; 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 -- ) : record-keyboard ( keyboard-state value -- )
dup IOHIDValueGetElement dup keyboard-key? [ dup IOHIDValueGetElement dup keyboard-key? [
[ IOHIDValueGetIntegerValue c-bool> ] [ IOHIDValueGetIntegerValue c-bool> ]

View File

@ -5,8 +5,7 @@ io.files hashtables quotations splitting grouping arrays io
math.parser math.order byte-arrays namespaces math.bitwise math.parser math.order byte-arrays namespaces math.bitwise
compiler.units parser io.encodings.ascii interval-maps compiler.units parser io.encodings.ascii interval-maps
ascii sets combinators locals math.ranges sorting make ascii sets combinators locals math.ranges sorting make
strings.parser io.encodings.utf8 memoize simple-flat-file strings.parser io.encodings.utf8 memoize simple-flat-file ;
sequences.private ;
IN: unicode.data IN: unicode.data
<PRIVATE <PRIVATE
@ -139,9 +138,6 @@ PRIVATE>
! the maximum unicode char in the first 3 planes ! 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 ) :: fill-ranges ( table -- table )
name-map sort-values keys name-map sort-values keys
[ { [ "first>" tail? ] [ "last>" tail? ] } 1|| ] filter [ { [ "first>" tail? ] [ "last>" tail? ] } 1|| ] filter

View File

@ -179,6 +179,10 @@ HELP: ?nth
{ $values { "n" "an integer" } { "seq" sequence } { "elt/f" "an object or " { $link f } } } { $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 } "." } ; { $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 HELP: ?first
{ $values { "seq" sequence } { "elt/f" "an object or " { $link f } } } { $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 } "." } { $description "A forgiving version of " { $link first } ". If the sequence is empty, or if the sequence is " { $link f } ", simply outputs " { $link f } "." }

View File

@ -175,6 +175,9 @@ PRIVATE>
: ?nth ( n seq -- elt/f ) : ?nth ( n seq -- elt/f )
2dup bounds-check? [ nth-unsafe ] [ 2drop f ] if ; inline 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 : ?first ( seq -- elt/f ) 0 swap ?nth ; inline
: ?second ( seq -- elt/f ) 1 swap ?nth ; inline : ?second ( seq -- elt/f ) 1 swap ?nth ; inline
: ?last ( seq -- elt/f ) : ?last ( seq -- elt/f )

View File

@ -1,7 +1,7 @@
! From http://www.ffconsultancy.com/ocaml/maze/index.html ! From http://www.ffconsultancy.com/ocaml/maze/index.html
USING: accessors arrays fry kernel math math.order math.vectors USING: accessors arrays fry kernel math math.order math.vectors
namespaces opengl.gl random sequences ui ui.gadgets namespaces opengl.gl random sequences ui ui.gadgets
ui.gadgets.canvas ui.render sequences.private ; ui.gadgets.canvas ui.render ;
IN: maze IN: maze
CONSTANT: line-width 8 CONSTANT: line-width 8
@ -10,13 +10,6 @@ SYMBOL: visited
: unvisited? ( cell -- ? ) first2 visited get ?nth ?nth ; : unvisited? ( cell -- ? ) first2 visited get ?nth ?nth ;
<PRIVATE
: ?set-nth ( elt n seq -- )
2dup bounds-check? [ set-nth-unsafe ] [ 3drop ] if ; inline
PRIVATE>
: visit ( cell -- ) f swap first2 visited get ?nth ?set-nth ; : visit ( cell -- ) f swap first2 visited get ?nth ?set-nth ;
: choices ( cell -- seq ) : choices ( cell -- seq )