fix the tuple subclassing example docs
							parent
							
								
									0f5c3c5d3f
								
							
						
					
					
						commit
						584cd44856
					
				| 
						 | 
				
			
			@ -129,17 +129,18 @@ ARTICLE: "tuple-inheritance-example" "Tuple subclassing example"
 | 
			
		|||
}
 | 
			
		||||
"Rectangles and parallelograms use the same algorithm for computing the area, whereas they use different algorithms for computing perimiter. Also, rectangles and parallelograms both have " { $snippet "width" } " and " { $snippet "height" } " slots. We can exploit this with subclassing:"
 | 
			
		||||
{ $code
 | 
			
		||||
    "USING: math.constants math.functions ;"
 | 
			
		||||
    "GENERIC: area ( shape -- n )"
 | 
			
		||||
    "GENERIC: perimiter ( shape -- n )"
 | 
			
		||||
    ""
 | 
			
		||||
    "TUPLE: shape ;"
 | 
			
		||||
    ""
 | 
			
		||||
    "TUPLE: circle < shape radius ;"
 | 
			
		||||
    "M: area circle radius>> sq pi * ;"
 | 
			
		||||
    "M: perimiter circle radius>> 2 * pi * ;"
 | 
			
		||||
    "M: circle area radius>> sq pi * ;"
 | 
			
		||||
    "M: circle perimiter radius>> 2 * pi * ;"
 | 
			
		||||
    ""
 | 
			
		||||
    "TUPLE: quad < shape width height"
 | 
			
		||||
    "M: area quad [ width>> ] [ height>> ] bi * ;"
 | 
			
		||||
    "TUPLE: quad < shape width height ;"
 | 
			
		||||
    "M: quad area [ width>> ] [ height>> ] bi * ;"
 | 
			
		||||
    ""
 | 
			
		||||
    "TUPLE: rectangle < quad ;"
 | 
			
		||||
    "M: rectangle perimiter [ width>> 2 * ] [ height>> 2 * ] bi + ;"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue