From d1117a66cbaf89c5b7804093a10c5850187a913a Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 20 Nov 2009 04:27:00 -0600 Subject: [PATCH 1/6] clean up the end of the easter word --- basis/calendar/calendar.factor | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/basis/calendar/calendar.factor b/basis/calendar/calendar.factor index fd51feeed9..ff55d26cdb 100644 --- a/basis/calendar/calendar.factor +++ b/basis/calendar/calendar.factor @@ -143,8 +143,7 @@ GENERIC: easter ( obj -- obj' ) 32 2 e * + 2 i * + h - k - 7 mod :> l a 11 h * + 22 l * + 451 /i :> m - h l + 7 m * - 114 + 31 /mod 1 + :> ( month day ) - month day ; + h l + 7 m * - 114 + 31 /mod 1 + ; M: integer easter ( year -- timestamp ) dup easter-month-day ; From 97288b8a0492d863da0cf5a3ff94bd37287ec11f Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 21 Nov 2009 18:01:25 -0600 Subject: [PATCH 2/6] remove >duration word and instead make a private >nanoseconds word in alarms --- basis/alarms/alarms.factor | 10 ++++++---- basis/calendar/calendar.factor | 5 ----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/basis/alarms/alarms.factor b/basis/alarms/alarms.factor index 251d82eec8..b006131182 100755 --- a/basis/alarms/alarms.factor +++ b/basis/alarms/alarms.factor @@ -19,13 +19,15 @@ SYMBOL: alarm-thread : notify-alarm-thread ( -- ) alarm-thread get-global interrupt ; -: normalize-argument ( obj -- nanoseconds ) - >duration duration>nanoseconds >integer ; +GENERIC: >nanoseconds ( obj -- duration/f ) +M: f >nanoseconds ; +M: real >nanoseconds >integer ; +M: duration >nanoseconds duration>nanoseconds >integer ; : ( quot start interval -- alarm ) alarm new - swap dup [ normalize-argument ] when >>interval - swap dup [ normalize-argument nano-count + ] when >>start + swap >nanoseconds >>interval + swap >nanoseconds nano-count + >>start swap >>quot >>entry ; diff --git a/basis/calendar/calendar.factor b/basis/calendar/calendar.factor index ff55d26cdb..25cf35c062 100644 --- a/basis/calendar/calendar.factor +++ b/basis/calendar/calendar.factor @@ -170,11 +170,6 @@ M: timestamp easter ( timestamp -- timestamp ) : microseconds ( x -- duration ) 1000000 / seconds ; : nanoseconds ( x -- duration ) 1000000000 / seconds ; -GENERIC: >duration ( obj -- duration/f ) -M: duration >duration ; -M: real >duration seconds ; -M: f >duration ; - GENERIC: year ( obj -- n ) M: integer year ; M: timestamp year year>> ; From a0b13cdb2c7f6f75ec89b141e7710e4f9c2515c4 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 23 Nov 2009 16:37:14 -0600 Subject: [PATCH 3/6] alarms: Stop repeated alarms after an error is thrown --- basis/alarms/alarms.factor | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/basis/alarms/alarms.factor b/basis/alarms/alarms.factor index b006131182..c2cee3afb4 100644 --- a/basis/alarms/alarms.factor +++ b/basis/alarms/alarms.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors assocs boxes calendar -combinators.short-circuit fry heaps init kernel math.order +USING: accessors assocs boxes calendar combinators.short-circuit +continuations fry heaps init kernel math.order namespaces quotations threads math system ; IN: alarms @@ -11,11 +11,14 @@ TUPLE: alarm interval { entry box } ; -> [ alarms get-global heap-delete ] if-box? ; + +nanoseconds duration>nanoseconds >integer ; : call-alarm ( alarm -- ) [ entry>> box> drop ] [ dup interval>> [ reschedule-alarm ] [ drop ] if ] - [ quot>> "Alarm execution" spawn drop ] tri ; + [ + [ quot>> ] [ ] bi + '[ _ [ _ dup interval>> [ cancel-alarm ] [ drop ] if rethrow ] recover ] + "Alarm execution" spawn drop + ] tri ; : (trigger-alarms) ( alarms n -- ) over heap-empty? [ @@ -89,6 +96,3 @@ PRIVATE> : later ( quot duration -- alarm ) f add-alarm ; : every ( quot duration -- alarm ) dup add-alarm ; - -: cancel-alarm ( alarm -- ) - entry>> [ alarms get-global heap-delete ] if-box? ; From a37908e00ec37993e59ba1b5b95df50d5764f7eb Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 23 Nov 2009 19:19:34 -0600 Subject: [PATCH 4/6] store the current alarm in current-alarm --- basis/alarms/alarms.factor | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/basis/alarms/alarms.factor b/basis/alarms/alarms.factor index c2cee3afb4..9ab30a1fa4 100644 --- a/basis/alarms/alarms.factor +++ b/basis/alarms/alarms.factor @@ -13,6 +13,7 @@ TUPLE: alarm SYMBOL: alarms SYMBOL: alarm-thread +SYMBOL: current-alarm : cancel-alarm ( alarm -- ) entry>> [ alarms get-global heap-delete ] if-box? ; @@ -49,9 +50,14 @@ M: duration >nanoseconds duration>nanoseconds >integer ; [ entry>> box> drop ] [ dup interval>> [ reschedule-alarm ] [ drop ] if ] [ - [ quot>> ] [ ] bi - '[ _ [ _ dup interval>> [ cancel-alarm ] [ drop ] if rethrow ] recover ] - "Alarm execution" spawn drop + [ ] [ quot>> ] [ ] tri + '[ + _ current-alarm + [ + _ [ _ dup interval>> [ cancel-alarm ] [ drop ] if rethrow ] + recover + ] with-variable + ] "Alarm execution" spawn drop ] tri ; : (trigger-alarms) ( alarms n -- ) From 5793d2e2eb6212c7a735374728d2ee2c8314a256 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Mon, 23 Nov 2009 19:49:47 -0600 Subject: [PATCH 5/6] update docs for new alarms changes --- basis/alarms/alarms-docs.factor | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/basis/alarms/alarms-docs.factor b/basis/alarms/alarms-docs.factor index 2c5a567d62..396011a351 100644 --- a/basis/alarms/alarms-docs.factor +++ b/basis/alarms/alarms-docs.factor @@ -4,9 +4,23 @@ IN: alarms HELP: alarm { $class-description "An alarm. Can be passed to " { $link cancel-alarm } "." } ; +HELP: current-alarm +{ $description "A symbol that contains the currently executing alarm, availble only to the alarm quotation. One use for this symbol is if a repeated alarm wishes to cancel itself from executing in the future." +} +{ $examples + { $unchecked-example + """USING: alarms calendar io threads ;""" + """[""" + """ "Hi, this should only get printed once..." print flush""" + """ current-alarm get cancel-alarm""" + """] 1 seconds every""" + "" + } +} ; + HELP: add-alarm { $values { "quot" quotation } { "start" duration } { "interval" { $maybe "duration/f" } } { "alarm" alarm } } -{ $description "Creates and registers an alarm to start at " { $snippet "start" } " offset from the current time. If " { $snippet "interval" } " is " { $link f } ", this will be a one-time alarm, otherwise it will fire with the given frequency, with scheduling happening before the quotation is called in order to ensure that the next event will happen on time. The quotation will be called from the alarm thread." } ; +{ $description "Creates and registers an alarm to start at " { $snippet "start" } " offset from the current time. If " { $snippet "interval" } " is " { $link f } ", this will be a one-time alarm, otherwise it will fire with the given frequency, with scheduling happening before the quotation is called in order to ensure that the next event will happen on time. The quotation will be called from a new thread spawned by the alarm thread. If a repeated alarm's quotation throws an exception, the alarm will not be rescheduled." } ; HELP: later { $values { "quot" quotation } { "duration" duration } { "alarm" alarm } } @@ -27,7 +41,7 @@ HELP: every { $values { "quot" quotation } { "duration" duration } { "alarm" alarm } } -{ $description "Creates and registers an alarm which calls the quotation repeatedly, using " { $snippet "dt" } " as the frequency." } +{ $description "Creates and registers an alarm which calls the quotation repeatedly, using " { $snippet "dt" } " as the frequency. If the quotation throws an exception that is not caught inside it, the alarm scheduler will cancel the alarm and will not reschedule it again." } { $examples { $unchecked-example "USING: alarms io calendar ;" @@ -44,6 +58,8 @@ ARTICLE: "alarms" "Alarms" { $subsections every } "Register a one-time alarm:" { $subsections later } +"The currently executing alarm:" +{ $subsections current-alarm } "Low-level interface to add alarms:" { $subsections add-alarm } "Cancelling an alarm:" From 7a00f24d6ba3ee694ccd05ea19a9eea651aedb4e Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 24 Nov 2009 20:41:59 -0600 Subject: [PATCH 6/6] revert math.matrices.elimintion until someone fixes it properly --- basis/math/matrices/elimination/elimination.factor | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/basis/math/matrices/elimination/elimination.factor b/basis/math/matrices/elimination/elimination.factor index 4dc29ad951..371eb8a36c 100644 --- a/basis/math/matrices/elimination/elimination.factor +++ b/basis/math/matrices/elimination/elimination.factor @@ -52,8 +52,11 @@ SYMBOL: matrix [ first-col ] keep dup 1 + rows-from clear-col ; +: find-row ( row# quot -- i elt ) + [ rows-from ] dip find ; inline + : pivot-row ( col# row# -- n ) - rows-from swap '[ [ _ ] dip nth-row nth abs ] sort-with last ; + [ dupd nth-row nth zero? not ] find-row 2nip ; : (echelon) ( col# row# -- ) over cols < over rows < and [