[Ruler-commits] r24 - pkg

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 31 11:46:41 CEST 2012


Author: merysionek
Date: 2012-07-31 11:46:41 +0200 (Tue, 31 Jul 2012)
New Revision: 24

Modified:
   pkg/New.R
Log:
basic pronting rules

Modified: pkg/New.R
===================================================================
--- pkg/New.R	2012-07-30 15:35:31 UTC (rev 23)
+++ pkg/New.R	2012-07-31 09:46:41 UTC (rev 24)
@@ -472,3 +472,54 @@
                       } 
                                                                     
  
+#---------------------------------------------------------------------------
+#------function to print objects of class SingleRule and DoubleRule---------
+#---------------------------------------------------------------------------
+
+h<-new("AddConstSingleRule")
+
+
+p<-new("AddConstSingleRule", constantVal=6)
+q<-new("MultConstSingleRule", constantVal=10, previousRule=p)
+g<-new("AddDoubleRule", firstRule=p, secondRule=p, nextSingle=q)
+
+
+calculate(q,4)# (4+6)*10=100
+
+
+n<-new("SubsDoubleRule")
+calculate(n,10,12) #10-12=-2
+
+p<-new("DigSumSingleRule")
+g<-new("AddDoubleRule", firstRule=p, secondRule=p, nextSingle=p)
+
+
+j<-new("DigSumSingleRule")
+
+
+print.SingleRule<-function(x){
+                                pr<-function(x){
+                                                cat(paste("\nname:", class(x)[1]))
+                                                if("constantVal"%in%slotNames(x)) {cat(paste(", constant value: ", x at constantVal))} 
+                                                }
+                                pr(x)
+                                
+                                if(!class(x at previousRule)=="SingleRule"){x<-x at previousRule; pr(x)}
+                                
+                              }
+
+
+
+print.DoubleRule<-function(x){
+                              x1=x
+                                             
+                                                             
+                                cat(class(x1)[1])
+                                
+                                if("firstRule"%in%slotNames(x)){cat("\n FIRST RULE:"); x<-x at firstRule;print.SingleRule(x)}
+                                x=x1
+                                if("secondRule"%in%slotNames(x)){cat("\n SECOND RULE:"); x<-x at secondRule;print.SingleRule(x)}
+                                x=x1
+                                if("nextSingle"%in%slotNames(x)){cat("\n NEXT SINGLE:"); x<-x at nextSingle;print.SingleRule(x)}
+                            
+                                }



More information about the Ruler-commits mailing list