Added >> to the Array class.

This commit is contained in:
Peter Camilleri 2016-04-10 22:11:53 -04:00
parent 5108b2cdcc
commit a698d6c145
2 changed files with 6 additions and 0 deletions

View file

@ -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,{}]])

View file

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