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.
! 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 ;
<PRIVATE
: ?set-nth ( elt n seq -- )
2dup bounds-check? [ set-nth-unsafe ] [ 3drop ] if ; inline
PRIVATE>
M: bit-set delete
! This isn't allowed to throw an error if the elt wasn't
! in the set

View File

@ -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> ]

View File

@ -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
<PRIVATE
@ -139,9 +138,6 @@ PRIVATE>
! 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

View File

@ -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 } "." }

View File

@ -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 )

View File

@ -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 ;
<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 ;
: choices ( cell -- seq )