! 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 } ;
! 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
-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
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> ]
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
! 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
{ $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 } "." }
: ?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 )
! 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
: 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 )