|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Number
ATNumber is the public interface to an AmbientTalk native number (an integer value).
Method Summary | |
---|---|
Number |
/-(Number nbr)
Returns the floor division between the number and another number passed as argument. |
Fraction |
??(Number nbr)
Returns a random fraction in the exclusive range from the number to a number passed as argument. |
Number |
%(Number nbr)
Returns the modular arithmetic between the number and another number passed as argument. |
Table |
***(Number end)
Returns a table containing the inclusive range from the number to a number passed as argument. |
Table |
**(Number end)
Returns a table containing the exclusive range from the number to a number passed as argument. |
Number |
abs()
Returns the absolute value of a number. |
Number |
dec()
Returns the number minus 1. |
Nil |
doTimes:(Closure code)
Iterates as many times as the value of the number applying a closure passed as argument. |
Number |
inc()
Returns the number plus 1. |
|
millisec()
Converts an AmbientTalk number representing a time period in milliseconds into a Java long representing the same time period in milliseconds. |
|
minutes()
Converts an AmbientTalk number representing a minute time period into a Java long * 1000 * 60 representing a millisecond time period. |
|
seconds()
Converts an AmbientTalk number representing a time period in seconds into a Java long * 1000 representing a time period in milliseconds. |
Nil |
to:do:(Number end,
Closure code)
Iterates from the value of the receiver to the one passed as argument applying a closure. |
Nil |
to:step:do:(Number end,
Number inc,
Closure code)
Iterates from the value of the receiver to the one passed as argument applying a closure. |
Methods inherited from interface edu.vub.at.objects.Numeric |
---|
/, =, >=, >, <=>, <=, <, -, !=, +, *, addFraction, addNumber, ceiling, cos, divideFraction, divideNumber, expt, floor, gequalsFraction, gequalsNumber, log, round, sin, sqrt, subtractFraction, subtractNumber, tan, timesFraction, timesNumber, toText |
Methods inherited from interface edu.vub.at.objects.AbstractGrammar |
---|
freeVariables |
Methods inherited from interface edu.vub.at.objects.Object |
---|
super |
Method Detail |
---|
Number inc()
Number dec()
Number abs()
More specifically:
Nil doTimes:(Closure code)
More specifically, the equivalent pseudo-code for this construct is:
for i = 1 to receiver do code.eval(i); nil
Here comes an example about how the doTimes: construct can be used to calculate the factorial of a number. def fact(n) { def res := 1; n.doTimes: { |i| res := res * i}; res }
code
- a closure expected to take one argument to be applied in each iteration
edu.vub.at.exceptions.InterpreterException
- if raised inside the iterator block.Nil to:do:(Number end, Closure code)
More specifically, this method calls:
receiver.to: end step: 1 do: { |i| code }
The end boundary is inclusive. If end is bigger than the receiver, the code block is not executed. For such uses, use downTo:do: instead.
end
- a number representing the stop value of the loop.code
- a closure expected to take one argument to be applied in each iteration.
edu.vub.at.exceptions.InterpreterException
- if raised inside the iterator block.Nil to:step:do:(Number end, Number inc, Closure code)
More specifically, the equivalent pseudo-code for this method is:
for (i = receiver; i < end ; i := i + inc) do code.eval(i); nil
Note that if end is bigger than the receiver, the construct behaves as a down-to operation. If receiver is equals to end, the code is not executed.
end
- a number representing the stop value of the loop.inc
- a number representing the step value of the loop.code
- a closure expected to take one argument to be applied in each iteration.
edu.vub.at.exceptions.InterpreterException
- if raised inside the iterator block.Table **(Number end)
Usage example:
2 ** 5 => [ 2, 3, 4 ]
5 ** 2 => [ 5, 4, 3 ]
end
- a number representing the stop value of the range.
Table
representing [ receiver, ..., end [Table ***(Number end)
Usage example:
2 *** 5 => [ 2, 3, 4, 5 ]
5 *** 2 => [ 5, 4, 3, 2 ]
end
- a number representing the stop value of the range.
Table
representing [ receiver, ..., end ]Fraction ??(Number nbr)
nbr
- a number representing the stop value of the range.
Fraction
chosen randomly in [ receiver, ..., nbr [Number %(Number nbr)
nbr
- a number.
Number
resulting of the remainder of the division (of receiver by nbr) that truncates towards zero.Number /-(Number nbr)
nbr
- a number.
Number
resulting of the floor division of receiver by nbr.millisec()
seconds()
minutes()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |