Permalink
Browse files

Coin counting with non-parameterized numeric operators! Plus, fixed a…

… few message calls that weren't passing a context.
  • Loading branch information...
1 parent fbca3a5 commit ffcdbd16ed7fe9ff602121d2b000ac1fb75f5874 @Phrogz committed Jul 8, 2008
View
@@ -23,7 +23,7 @@ runtime.Meta.__tostring = function( object )
elseif object == String then
return runtime.luastring[object.__name]
else
- return runtime.luastring[ sendMessage( object, messageCache['toString'] ) ]
+ return runtime.luastring[ sendMessage( object, messageCache['toString'], Roots.Lawn ) ]
end
end
View
@@ -20,7 +20,7 @@ Roots.Number['+'] = createLuaFunc( 'addend', function( context ) -- Number#+
error( "Number#+ is missing an addend" )
end
context.callState.callingContext.nextMessage = theNextMessageOrLiteral.next
- rvalue = runtime.luanumber[ sendMessage( context.callState.callingContext, theNextMessageOrLiteral ) ]
+ rvalue = runtime.luanumber[ sendMessage( context.callState.callingContext, theNextMessageOrLiteral, context.callState.callingContext ) ]
end
return runtime.number[ lvalue + rvalue ]
end )
@@ -34,7 +34,7 @@ Roots.Number['-'] = createLuaFunc( 'subtrahend', function( context ) -- Number#-
error( "Number#- is missing a subtrahend" )
end
context.callState.callingContext.nextMessage = theNextMessageOrLiteral.next
- rvalue = runtime.luanumber[ sendMessage( context.callState.callingContext, theNextMessageOrLiteral ) ]
+ rvalue = runtime.luanumber[ sendMessage( context.callState.callingContext, theNextMessageOrLiteral, context.callState.callingContext ) ]
end
return runtime.number[ lvalue - rvalue ]
end )
@@ -60,7 +60,7 @@ Roots.Number['*'] = createLuaFunc( 'multiplicand', function( context ) -- Number
error( "Number#* is missing a multiplicand" )
end
context.callState.callingContext.nextMessage = theNextMessageOrLiteral.next
- rvalue = runtime.luanumber[ sendMessage( context.callState.callingContext, theNextMessageOrLiteral ) ]
+ rvalue = runtime.luanumber[ sendMessage( context.callState.callingContext, theNextMessageOrLiteral, context.callState.callingContext ) ]
end
return runtime.number[ lvalue * rvalue ]
end )
@@ -74,7 +74,7 @@ Roots.Number['/'] = createLuaFunc( 'divisor', function( context ) -- Number#/
error( "Number#/ is missing a divisor" )
end
context.callState.callingContext.nextMessage = theNextMessageOrLiteral.next
- rvalue = runtime.luanumber[ sendMessage( context.callState.callingContext, theNextMessageOrLiteral ) ]
+ rvalue = runtime.luanumber[ sendMessage( context.callState.callingContext, theNextMessageOrLiteral, context.callState.callingContext ) ]
end
return runtime.number[ lvalue / rvalue ]
end )
View
@@ -11,7 +11,7 @@ Roots.String['*'] = createLuaFunc( 'reps', function( context ) -- String#*
error( "String#* is missing a repetition count" )
end
context.callState.callingContext.nextMessage = theNextMessageOrLiteral.next
- rvalue = runtime.luanumber[ sendMessage( context.callState.callingContext, theNextMessageOrLiteral ) ]
+ rvalue = runtime.luanumber[ sendMessage( context.callState.callingContext, theNextMessageOrLiteral, context.callState.callingContext ) ]
end
return runtime.string[ string.rep( string, reps ) ]
end )
@@ -0,0 +1,16 @@
+setSlot( 'coins', Array new( 1, 2, 5, 10, 20, 50, 100, 200 ) )
+setSlot( 'countChange', method( amount,
+ cc( amount, coins size )
+))
+
+setSlot( 'cc', method( amount, kindsOfCoins,
+ if( amount ==(0),
+ 1,
+ if( amount <(0) or( kindsOfCoins ==(0) ),
+ 0,
+ cc( amount, kindsOfCoins - 1 ) + cc( amount -( coins at(kindsOfCoins) ), kindsOfCoins )
+ )
+ )
+))
+
+p( countChange( 20 ) )
View
@@ -23,6 +23,7 @@ tests = {
"13b_arraySieve",
"14_changeMaker",
"14b_changeMaker_simple",
+ "14c_changeMaker_with_operators",
"15_ObjectScope",
"15b_SubtleObjectScope",
"16_locals_shadow_context",

0 comments on commit ffcdbd1

Please sign in to comment.