diff --git a/integration/array_lib_tests.rb b/integration/array_lib_tests.rb index 9a6cfe5..100ef73 100644 --- a/integration/array_lib_tests.rb +++ b/integration/array_lib_tests.rb @@ -283,6 +283,8 @@ class ArrayLibraryTester < Minitest::Test foorth_equal('[ 9 3 5 ] [ 4 1 ] << ', [[9,3,5,[4,1]]]) foorth_equal('[ 9 3 5 ] [ 4 1 ] << ', [[9,3,5,[4,1]]]) + foorth_equal('[ 9 3 5 ] 0 >> ', [[0,9,3,5]]) + foorth_equal('[ 9 3 5 ] 0 + ', [[9,3,5,0]]) foorth_equal('[ 9 3 5 ] [ 0 ] + ', [[9,3,5,0]]) foorth_equal('[ 9 3 5 ] { } + ', [[9,3,5,{}]]) diff --git a/lib/fOOrth/library/array_library.rb b/lib/fOOrth/library/array_library.rb index 60885ec..0860c50 100644 --- a/lib/fOOrth/library/array_library.rb +++ b/lib/fOOrth/library/array_library.rb @@ -119,6 +119,10 @@ module XfOOrth Array.create_shared_method('<<', NosSpec, [], &lambda {|vm| vm.poke(self << vm.peek); }) + # [ [ 3 1 2 ] n ] >> [ [ n 3 1 2 ] ] + Array.create_shared_method('>>', NosSpec, [], + &lambda {|vm| vm.poke(self.insert(0, vm.peek)); }) + # [[3 1 2] n] + [[3 1 2 n]] Array.create_shared_method('+', NosSpec, [], &lambda {|vm| vm.poke(self + vm.peek.in_array); })