Description Objects from the Class Slots Extends Methods Author(s) See Also Examples
A class for the rule which adds the two previous elements of a number sequence. It inherits from class DoubleRule
Objects can be created by calls of the form new("AddDoubleRule",... )
.
firstRule
:Object of class "SingleRule"
- a rule to be executed on the first element of numeric sequence, before executing DoubleRule (doesn't need to be specified)
secondRule
:Object of class "SingleRule"
- a rule to be executed on the second element of numeric sequence, before executing DoubleRule (doesn't need to be specified)
nextSingle
:Object of class "SingleRule"
- a rule to be executed on the result of DoubleRule (doesn't need to be specified)
.S3Class
:Object of class "character"
- S3 methods apply for these objects
Class "DoubleRule"
, directly.
signature(x = "AddDoubleRule", y = "numeric", z = "numeric")
: ...
Maria Rafalak <m.rafalak@practest.com.pl>
calculate
,
DoubleRule
,
SingleRule
,
createSR
,
createDR
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #[1] simple DoubleRule
p <- new("AddDoubleRule")
calculate(p,12,5) #12+5=17
unlist(sequenceR(1,p,8)[[1]]) # first 8 elements of Fibonacci sequence
#[2] combining rules
m <- new("DigSumSingleRule")
# SingleRule that calculates digitsum of an element of numeric sequence
r <- new("AddConstSingleRule", constantVal=6)
# a SingleRule that adds constant value '6' to the element of numeric sequence
f <- new("MultConstSingleRule", constantVal=2)
# a SingleRule that muliplies an element of a sequence by constant value '4'
g <- new("AddDoubleRule", firstRule=r, secondRule=f, nextSingle=m)
calculate(g,12,5) #10
## How is rule 'g' executed ?
## Starting elements are '12' and '5'
## Rule 'r'(firstRule) is applied to the first element of numeric sequence (12+6=18)
## Rule 'f'(secondRule) is applied to the second element of numeric sequence (5*2=10)
## "AddDoubleRule" is executed on the results of firstRule and secondRule (18+10=28)
## Rule 'm' is applies to the result of DoubleRule (2+8=10)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.