Paste: Experimenting with "Object-oriented" Factor

Author: Loryn
Mode: factor
Date: Sun, 19 Apr 2009 00:20:57
Plain Text |
IN: cricket

TUPLE: innings current-score current-overs target ;

GENERIC: run-rate ( innings -- n )
GENERIC: gap-to-target ( innings -- n )
GENERIC: remaining-overs ( innings -- n )
GENERIC: remaining-runs ( innings -- n )
GENERIC: target-run-rate ( innings -- n )

M: innings run-rate
    [ current-score>> ] [ current-overs>> ] bi / ;

M: innings gap-to-target
    [ target>> ] [ current-score>> ] bi - ;

M: innings remaining-overs
    current-overs>> 50 swap - ;

M: innings target-run-rate
    [ gap-to-target ] [ remaining-overs ] bi / ;

New Annotation

Summary:
Author:
Mode:
Body: