! Copyright (C) 2009 Yun, Jonghyouk. ! See http://factorcode.org/license.txt for BSD license. USING: kernel locals math sequences sequences.last ; IN: math.fibonacci : fib-next ( seq -- n ) [ last-0 ] [ last-1 ] bi + ; : fib-next-push ( seq -- newseq ) dup fib-next suffix ; : fib-initial-seq ( -- seq ) { 1 1 } ; : fib-produce-seq ( seq max -- newseq ) [let | max_ [ ] seq_ [ ] | seq_ fib-next max_ < [ seq_ fib-next-push max_ fib-produce-seq ] [ seq_ ] if ] ;