Code: Select all
; definitions
(define (Time:Time (t (date-value)) (zone 0))
(list Time t zone))
(define (Time:show t)
(date (t 1) (t 2)))
(define (Time:days-between t1 t2)
"Return difference in days between two times."
(div (abs (- (t1 1) (t2 1))) (* 24 60 60)))
(define (Time:get-hours t)
"Return hours."
(int (date (t 1) (t 2) {%H})))
(define (Time:get-day t)
"Return day of week."
(date (t 1) (t 2) {%A}))
(define (Time:leap-year? t)
(let ((year (int (date (t 1) (t 2) {%Y}))))
(and (= 0 (% year 4))
(or (!= 0 (% year 100)) (= 0 (% year 400))))))
; use
(set 'time-now (Time))
(set 'my-birthday (Time (date-value 2008 5 26)))
(set 'christmas-day (Time (date-value 2008 12 25)))
; call functions with full context prefix
(println (Time:show christmas-day))
; or call them with colon prefix mode
(println (:show christmas-day))
Code: Select all
$ newlisp foop.lsp
Wed Dec 24 21:00:00 2008
ERR: invalid function in function date : (MAIN:t 1)
called from user defined function Time:show
Code: Select all
> (context Time)
Time
Time> (set 'christmas-day (Time (date-value 2008 12 25)))
(Time 1230163200 0)
Time> (:show christmas-day)
ERR: invalid function in function date : (MAIN:t 1)
called from user defined function Time:show
Code: Select all
(define (Time:show Time:t)
(date (Time:t 1) (Time:t 2)))
Code: Select all
$ newlisp foop.lsp
Wed Dec 24 21:00:00 2008
ERR: invalid function in function date : (t 1)
called from user defined function Time:show
I don't know if this is something that has changed since that part of the book was writing or if I'm missing something. Any thoughts are welcome.