Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

O'Scheme

Name: Anonymous 2008-07-01 16:00


(class (Cat)
    (property age)
    (property name)
    (property weight)

    (define (constructor name age weight)
        (self name name)
        (self age age)
        (self weight weight))

    (define (display)
        (display "<Cat named ")
        (display (self name))
        (display ">")
        (newline)))

(let ((cat (Cat "Kitty" 7 10)))
    (cat display))

Name: Anonymous 2008-07-01 16:12

Nya nya nya

Name: Anonymous 2008-07-01 16:18

Let's see your generic functions.

Name: Anonymous 2008-07-01 16:28

I see someone hasn't read their TAMP.

Name: Anonymous 2008-07-01 22:09

Nyan nyan nyan nyan nihao nyan

Name: Anonymous 2008-07-01 22:53

There are plenty of better ways to do this. Also clojure is fun to play with. Try clojure!

Name: Anonymous 2008-07-02 4:52

stop selling clojure to us you fuck.

Name: Anonymous 2008-07-02 17:04

Clojure.
Clojure...



Clojure!

Name: Anonymous 2008-07-02 21:10

>>1
This is good but I would recommend CROMA-LISP

Name: Anonymous 2008-07-02 21:22

>>9
The Ginger?

Name: Patrick Collison 2008-07-02 23:14

>>10
Although my e-mail address is patrick@ginger.cn, I prefer to be called my real name, Patrick Collison.

Name: Anonymous 2008-07-02 23:15

O'Scheme -> Irish
The Ginger -> Irish

Hence....?

Name: Anonymous 2008-07-03 3:26

>>11
Back to bed Ginger

Name: Anonymous 2008-07-03 4:24

fails for MixedCase

Name: Anonymous 2008-07-03 4:26

ginger.cn
I laughed.

Name: Anonymous 2008-07-03 5:14

>>15

http://ginger.cn/

Ginger news, Ginger photos and Ginger reference

Latest Flickr results for Ginger

Warning: Invalid argument supplied for foreach() in /home/john/www/widgets/flickr_images.php on line 57

Name: Anonymous 2008-07-03 18:33

Name: Anonymous 2008-07-03 21:17

>>17
Twitter is currently down for maintenance to prepare for the holiday.

Name: Testing formatting 2009-12-23 3:59

(eval-when (:compile-toplevel :load-toplevel :execute)
  (asdf:oos 'asdf:load-op '#:local-time))

(defun seconds-elapsed-from-unix-timestamp (unix-timestamp &optional (from-timestamp (local-time:timestamp-to-unix (local-time:now))))
  \"Calculates the difference in seconds, between 2 unix timestamps. If the FROM-TIMESTAMP parameter is not supplied, the current time is used.\"
  (let* ((elapsed (- from-timestamp unix-timestamp))
         (from-future (< elapsed 0)))
    (values (abs elapsed) from-future)))

(defun decode-seconds (seconds)
  \"Decodes a seconds interval into seconds, minutes, hours, days, years.\"
  (multiple-value-bind (minutes seconds) (truncate seconds 60)
    (multiple-value-bind (hours minutes) (truncate minutes 60)
      (multiple-value-bind (days hours) (truncate hours 24)
        (multiple-value-bind (years days) (truncate days 365)
          (values seconds minutes hours days years))))))

(defmacro aif (test then &optional else)
  \"Anaphoric IF macro. Binds the result of evaluating TEST to the local variable IT.\"
  `(let ((it ,test))
     (declare (ignorable it))
     (if it ,then ,else)))

(defun make-seconds-interval-string (seconds &optional (use-numerals t))
  \"Makes an english readable description of the SECONDS parameter.
   USE-NUMERALS specifies wether the numerals should be written using decimals, or english words.\"
  (labels ((make-time-unit-string (value string)
             (let ((format-string (format nil\"~~[~~:;~~:*~~~A ~A~~:p~~]\" (if use-numerals \"d\" \"r\") string)))
               (format nil format-string value))))
    (aif (remove \"\" (mapcar #'(lambda (value string)
                                (make-time-unit-string value string))
                            (nreverse (multiple-value-list (decode-seconds seconds)))
                            '(\"year\" \"day\" \"hour\" \"minute\" \"second\"))
                 :test #'equal)   
         (format nil \"~{~#[~;~a~;~a and ~a~:;~@{~a~#[~;, and ~:;, ~]~}~]~}\" it))))

(defun format-seconds-elapsed-from-unix-timestamp-in-english (unix-timestamp &key (stream t) use-numerals reference-timestamp)
  \"Print an english readable description of the time that has passed since the given UNIX-TIMESTAMP to the stream STREAM (default *standard-output*).
   USE-NUMERALS specifies wether the numerals should be written using decimals, or english words.
   REFERENCE-TIMESTAMP specifies the timestamp from which time has supposedly passed or will pass. Ddefault is current time.\"
  (multiple-value-bind (elapsed-seconds from-future)
      (apply #'seconds-elapsed-from-unix-timestamp `(,unix-timestamp ,@(when reference-timestamp `(,reference-timestamp))))
    (format stream \"~@(~A~) ~A that timestamp.\"
            (aif (make-seconds-interval-string elapsed-seconds use-numerals) it \"no time has\")
            (if from-future \"will pass to reach\" \"passed since\"))))

;;; Sample usage
#|
CL-USER> (make-seconds-interval-string 1)
\"1 second\"
CL-USER> (make-seconds-interval-string 100)
\"1 minute and 40 seconds\"
CL-USER> (make-seconds-interval-string 1000)
\"16 minutes and 40 seconds\"
CL-USER> (make-seconds-interval-string 9999999)
\"115 days, 17 hours, 46 minutes, and 39 seconds\"
CL-USER> (make-seconds-interval-string 9999959)
\"115 days, 17 hours, 45 minutes, and 59 seconds\"
CL-USER> (make-seconds-interval-string 9999960)
\"115 days, 17 hours, and 46 minutes\"
CL-USER> (make-seconds-interval-string 9999960999)
\"317 years, 35 days, 6 hours, 56 minutes, and 39 seconds\"
CL-USER> (make-seconds-interval-string (+ (* 60 60 2)))
\"2 hours\"
CL-USER> (make-seconds-interval-string (+ (* 60 60 2) (* 60 60 24 9)))
\"9 days and 2 hours\"
CL-USER> (make-seconds-interval-string (+ (* 60 60 2) (* 60 60 24 1)))
\"1 day and 2 hours\"
CL-USER> (make-seconds-interval-string 9999960999 nil)
\"three hundred seventeen years, thirty-five days, six hours, fifty-six minutes, and thirty-nine seconds\"
CL-USER> (make-seconds-interval-string (+ (* 60 60 2)) nil)
\"two hours\"
CL-USER> (make-seconds-interval-string (+ (* 60 60 10)) nil)
\"ten hours\"
CL-USER> (make-seconds-interval-string (+ (* 60 60 1000)) nil)
\"forty-one days and sixteen hours\"
CL-USER> (make-seconds-interval-string 0 nil)
NIL
CL-USER> (make-seconds-interval-string 0)
NIL

CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 123 :reference-timestamp 123)
No time has passed since that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 123 :reference-timestamp 124)
One second passed since that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 9999 :reference-timestamp 124)
Two hours, forty-four minutes, and thirty-five seconds will pass to reach that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 9999 :reference-timestamp 124 :use-numerals t)
2 hours, 44 minutes, and 35 seconds will pass to reach that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 9999 :reference-timestamp 124 :use-numerals t)
2 hours, 44 minutes, and 35 seconds will pass to reach that timestamp.
NIL
CL-USER> (+ (* 60 60 2) (* 60 60 24 9))
#xBF9A0
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english #xBF9A0 :reference-timestamp 0 :use-numerals t)
9 days and 2 hours will pass to reach that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 0 :reference-timestamp #xBF9A0)
Nine days and two hours passed since that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 0)
Forty years, one day, sixteen hours, forty-eight minutes, and twenty-four seconds passed since that timestamp.
NIL
|#

Name: Testing formatting 2009-12-23 4:02

ENTERPRISE Lisp solution:

(eval-when (:compile-toplevel :load-toplevel :execute)
  (asdf:oos 'asdf:load-op '#:local-time))

(defun seconds-elapsed-from-unix-timestamp (unix-timestamp &optional (from-timestamp (local-time:timestamp-to-unix (local-time:now))))
  "Calculates the difference in seconds, between 2 unix timestamps. If the FROM-TIMESTAMP parameter is not supplied, the current time is used."
  (let* ((elapsed (- from-timestamp unix-timestamp))
         (from-future (< elapsed 0)))
    (values (abs elapsed) from-future)))

(defun decode-seconds (seconds)
  "Decodes a seconds interval into seconds, minutes, hours, days, years."
  (multiple-value-bind (minutes seconds) (truncate seconds 60)
    (multiple-value-bind (hours minutes) (truncate minutes 60)
      (multiple-value-bind (days hours) (truncate hours 24)
        (multiple-value-bind (years days) (truncate days 365)
          (values seconds minutes hours days years))))))

(defmacro aif (test then &optional else)
  "Anaphoric IF macro. Binds the result of evaluating TEST to the local variable IT."
  `(let ((it ,test))
     (declare (ignorable it))
     (if it ,then ,else)))

(defun make-seconds-interval-string (seconds &optional (use-numerals t))
  "Makes an english readable description of the SECONDS parameter.
   USE-NUMERALS specifies wether the numerals should be written using decimals, or english words."
  (labels ((make-time-unit-string (value string)
             (let ((format-string (format nil"~~[~~:;~~:*~~~A ~A~~:p~~]" (if use-numerals "d" "r") string)))
               (format nil format-string value))))
    (aif (remove "" (mapcar #'(lambda (value string)
                                (make-time-unit-string value string))
                            (nreverse (multiple-value-list (decode-seconds seconds)))
                            '("year" "day" "hour" "minute" "second"))
                 :test #'equal)   
         (format nil "~{~#[~;~a~;~a and ~a~:;~@{~a~#[~;, and ~:;, ~]~}~]~}" it))))

(defun format-seconds-elapsed-from-unix-timestamp-in-english (unix-timestamp &key (stream t) use-numerals reference-timestamp)
  "Print an english readable description of the time that has passed since the given UNIX-TIMESTAMP to the stream STREAM (default *standard-output*).
   USE-NUMERALS specifies wether the numerals should be written using decimals, or english words.
   REFERENCE-TIMESTAMP specifies the timestamp from which time has supposedly passed or will pass. Ddefault is current time."
  (multiple-value-bind (elapsed-seconds from-future)
      (apply #'seconds-elapsed-from-unix-timestamp `(,unix-timestamp ,@(when reference-timestamp `(,reference-timestamp))))
    (format stream "~@(~A~) ~A that timestamp."
            (aif (make-seconds-interval-string elapsed-seconds use-numerals) it "no time has")
            (if from-future "will pass to reach" "passed since"))))

;;; Sample usage
#|
CL-USER> (make-seconds-interval-string 1)
"1 second"
CL-USER> (make-seconds-interval-string 100)
"1 minute and 40 seconds"
CL-USER> (make-seconds-interval-string 1000)
"16 minutes and 40 seconds"
CL-USER> (make-seconds-interval-string 9999999)
"115 days, 17 hours, 46 minutes, and 39 seconds"
CL-USER> (make-seconds-interval-string 9999959)
"115 days, 17 hours, 45 minutes, and 59 seconds"
CL-USER> (make-seconds-interval-string 9999960)
"115 days, 17 hours, and 46 minutes"
CL-USER> (make-seconds-interval-string 9999960999)
"317 years, 35 days, 6 hours, 56 minutes, and 39 seconds"
CL-USER> (make-seconds-interval-string (+ (* 60 60 2)))
"2 hours"
CL-USER> (make-seconds-interval-string (+ (* 60 60 2) (* 60 60 24 9)))
"9 days and 2 hours"
CL-USER> (make-seconds-interval-string (+ (* 60 60 2) (* 60 60 24 1)))
"1 day and 2 hours"
CL-USER> (make-seconds-interval-string 9999960999 nil)
"three hundred seventeen years, thirty-five days, six hours, fifty-six minutes, and thirty-nine seconds"
CL-USER> (make-seconds-interval-string (+ (* 60 60 2)) nil)
"two hours"
CL-USER> (make-seconds-interval-string (+ (* 60 60 10)) nil)
"ten hours"
CL-USER> (make-seconds-interval-string (+ (* 60 60 1000)) nil)
"forty-one days and sixteen hours"
CL-USER> (make-seconds-interval-string 0 nil)
NIL
CL-USER> (make-seconds-interval-string 0)
NIL

CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 123 :reference-timestamp 123)
No time has passed since that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 123 :reference-timestamp 124)
One second passed since that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 9999 :reference-timestamp 124)
Two hours, forty-four minutes, and thirty-five seconds will pass to reach that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 9999 :reference-timestamp 124 :use-numerals t)
2 hours, 44 minutes, and 35 seconds will pass to reach that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 9999 :reference-timestamp 124 :use-numerals t)
2 hours, 44 minutes, and 35 seconds will pass to reach that timestamp.
NIL
CL-USER> (+ (* 60 60 2) (* 60 60 24 9))
#xBF9A0
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english #xBF9A0 :reference-timestamp 0 :use-numerals t)
9 days and 2 hours will pass to reach that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 0 :reference-timestamp #xBF9A0)
Nine days and two hours passed since that timestamp.
NIL
CL-USER> (format-seconds-elapsed-from-unix-timestamp-in-english 0)
Forty years, one day, sixteen hours, forty-eight minutes, and twenty-four seconds passed since that timestamp.
NIL
|#

Name: More testing 2009-12-23 7:33

Refactored my previous code a little:

The DECODE-SECONDS function seemed a bit repetitive, so I've abstracted the functionality into a macro:

(defmacro with-measurement-units (source unit-bindings &body body)
  (destructuring-bind (first second . rest) unit-bindings
    (let ((units (list (car first) (car second))))
          `(multiple-value-bind ,(reverse units) (truncate ,source ,(second first))
             ,@(if rest
                   `((with-measurement-units ,(second units) ,(cons second rest) ,@body))
                   body)))))

(defun decode-seconds (seconds)
  (with-measurement-units seconds ((seconds 60) (minutes 60) (hours 24) (days 365) (years))
    (values seconds minutes hours days years)))


Removed a local function which was only used once:

(defun make-seconds-interval-string (seconds &optional (use-numerals t))
  "Makes an english readable description of the SECONDS parameter.
   USE-NUMERALS specifies wether the numerals should be written using decimals, or english words." 
  (aif (remove "" (mapcar #'(lambda (value string)                               
                              (format nil (format nil "~~[~~:;~~:*~~~A ~A~~:p~~]" (if use-numerals "d" "r") string) value))
                          (nreverse (multiple-value-list (decode-seconds seconds)))
                          '("year" "day" "hour" "minute" "second"))
               :test #'equal)   
       (format nil "~{~#[~;~a~;~a and ~a~:;~@{~a~#[~;, and ~:;, ~]~}~]~}" it)))

Name: Anonymous 2011-02-04 13:53

Name: Sgt.Kabukiman헞๘ 2012-05-24 9:47

All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy
 All work and no play makes Jack a dull boy

Name: bampu pantsu 2012-05-29 4:01

bampu pantsu

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List