calculate: Caculate the next element of a sequence

Description Usage Arguments Details Value See Also Examples

Description

Caculate the next element of a sequence from previous element(s) and a rule.

Usage

1
calculate(x, y, z = NULL)

Arguments

x

- an object of class SingleRule or DoubleRule

y

- first element of numeric sequence

z

- second element of numeric sequence

Details

argument z is ignored if x inherits from class SingleRule

Value

function returs single value of class numeric

See Also

calculateSpecific

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#[1] for objects of class SingleRule

# a rule adding a constant value '6' to  the element of numeric sequence
p<-new("AddConstSingleRule", constantVal=6) 
calculate(p,4)# 4+6=10


#[2] for combined objects

m<-new("DigSumSingleRule")
r<-new("AddConstSingleRule", constantVal=6)
g<-new("MultDoubleRule", firstRule=m, secondRule=m, nextSingle=r)

calculate(g,12,34) #27

# rule 'm' (first rule) is executed on the first element of numeric sequence (1+2=3)
# rule 'm' (second rule) is executed on the second element of numeric sequence (3+4=7)
# rule 'g' is executed on the result of firstRule and secondRule (3*7=21)
# rule 'r' (nextSingle) is executed on the result of DoubleRule (21+6=27)
#[(1+2) * (3+4)] + 6 = 27

ruleR documentation built on May 2, 2019, 5:49 p.m.