sequences namespaces parser kernel kernel.private classes
classes.private arrays hashtables vectors classes.tuple sbufs
hashtables.private sequences.private math classes.tuple.private
-growable namespaces.private assocs words command-line vocabs io
+growable namespaces.private shuffle assocs words command-line vocabs io
io.encodings.string libc splitting math.parser memory compiler.units
math.order quotations quotations.private assocs.private ;
FROM: compiler => enable-optimizer ;
quotations classes classes.algebra classes.tuple.private
continuations growable namespaces hints alien.accessors
compiler.tree.builder compiler.tree.optimizer sequences.deep
-compiler definitions generic.single ;
+compiler definitions generic.single shuffle ;
IN: compiler.tests.optimizer
GENERIC: xyz ( obj -- obj )
[ 1024 bignum ] [ 10 [ 1 >bignum swap >fixnum shift ] compile-call dup class ] unit-test
! Not sure if I want to fix this...
-! [ t [ [ f ] [ 3 ] if >fixnum ] compile-call ] [ no-method? ] must-fail-with
\ No newline at end of file
+! [ t [ [ f ] [ 3 ] if >fixnum ] compile-call ] [ no-method? ] must-fail-with
compiler.tree.recursive compiler.tree.normalization
compiler.tree.checker tools.test kernel math stack-checker.state
accessors combinators io prettyprint words sequences.deep
-sequences.private arrays classes kernel.private ;
+sequences.private arrays classes kernel.private shuffle ;
IN: compiler.tree.dead-code.tests
: count-live-values ( quot -- n )
--- /dev/null
+USING: help.markup help.syntax ;
+IN: shuffle
+
+HELP: roll $complex-shuffle ;
+HELP: -roll $complex-shuffle ;
USING: shuffle tools.test ;
+IN: shuffle.tests
[ 1 2 3 4 ] [ 3 4 1 2 2swap ] unit-test
[ 4 2 3 ] [ 1 2 3 4 shuffle( a b c d -- d b c ) ] unit-test
+
+[ 2 3 4 1 ] [ 1 2 3 4 roll ] unit-test
+[ 1 2 3 4 ] [ 2 3 4 1 -roll ] unit-test
+
SYNTAX: shuffle(
")" parse-effect suffix! \ shuffle-effect suffix! ;
+: roll ( x y z t -- y z t x ) [ rot ] dip swap ; inline deprecated
+
+: -roll ( x y z t -- t x y z ) swap [ -rot ] dip ; inline deprecated
+
: 2swap ( x y z t -- z t x y ) 2 2 mnswap ; inline
: 4dup ( a b c d -- a b c d a b c d ) 4 ndup ; inline
HELP: dupd ( x y -- x x y ) $complex-shuffle ;
HELP: swapd ( x y z -- y x z ) $complex-shuffle ;
HELP: tuck ( x y -- y x y ) $complex-shuffle ;
-HELP: roll $complex-shuffle ;
-HELP: -roll $complex-shuffle ;
HELP: datastack ( -- ds )
{ $values { "ds" array } }
"[ p ] [ q ] 3bi"
"3dup p q"
}
- "If " { $snippet "[ p ]" } " and " { $snippet "[ q ]" } " have stack effect " { $snippet "( x y z -- w )" } ", then the following two lines are equivalent:"
- { $code
- "[ p ] [ q ] 3bi"
- "3dup p -roll q"
- }
"In general, the following two lines are equivalent:"
{ $code
"[ p ] [ q ] 3bi"
swapd
rot
-rot
- roll
- -roll
spin
} ;
[ -7 <byte-array> ] must-fail
-[ 2 3 4 1 ] [ 1 2 3 4 roll ] unit-test
-[ 1 2 3 4 ] [ 2 3 4 1 -roll ] unit-test
-
[ 3 ] [ t 3 and ] unit-test
[ f ] [ f 3 and ] unit-test
[ f ] [ 3 f and ] unit-test
! Stack stuff
: spin ( x y z -- z y x ) swap rot ; inline
-: roll ( x y z t -- y z t x ) [ rot ] dip swap ; inline
-
-: -roll ( x y z t -- t x y z ) swap [ -rot ] dip ; inline
-
: 2over ( x y z -- x y z x y ) pick pick ; inline
: clear ( -- ) { } set-datastack ;
: dip ( x quot -- x ) swap [ call ] dip ;
-: 2dip ( x y quot -- x y ) -rot [ call ] 2dip ;
+: 2dip ( x y quot -- x y ) swap [ dip ] dip ;
-: 3dip ( x y z quot -- x y z ) -roll [ call ] 3dip ;
+: 3dip ( x y z quot -- x y z ) swap [ 2dip ] dip ;
: 4dip ( w x y z quot -- w x y z ) swap [ 3dip ] dip ; inline
: badness ( word -- n )\r
H{\r
{ -nrot 5 }\r
- { -roll 4 }\r
{ -rot 3 }\r
{ bi@ 1 }\r
{ 2curry 1 }\r
{ nwith 4 }\r
{ over 2 }\r
{ pick 4 }\r
- { roll 4 }\r
{ rot 3 }\r
{ spin 3 }\r
{ swap 1 }\r
lists.lazy locals math math.functions math.parser math.ranges
models.product monads random sequences sets ui ui.gadgets.controls
ui.gadgets.layout models.combinators ui.gadgets.alerts vectors fry
-ui.gadgets.labels ;
+ui.gadgets.labels shuffle ;
IN: sudokus
: row ( index -- row ) 1 + 9 / ceiling ;
] with-self , ] <vbox> { 280 220 } >>pref-dim
"Sudoku Sleuth" open-window ] with-ui ;
-MAIN: do-sudoku
\ No newline at end of file
+MAIN: do-sudoku