summaryrefslogtreecommitdiff
path: root/com/simatime
diff options
context:
space:
mode:
Diffstat (limited to 'com/simatime')
-rw-r--r--com/simatime/core.scm71
1 files changed, 71 insertions, 0 deletions
diff --git a/com/simatime/core.scm b/com/simatime/core.scm
index 611aaca..155214c 100644
--- a/com/simatime/core.scm
+++ b/com/simatime/core.scm
@@ -39,3 +39,74 @@
(for-each display args))
(define (prn . a) (apply pr a) (newline))
+
+(define first
+ "Return the first item in the collection."
+ car)
+
+(define next
+ "Returns a list of the items after the first."
+ cadr)
+
+(define (second x)
+ (first (next x)))
+
+(define (ffirst x)
+ (first (first x)))
+
+(define (nnext x)
+ (next (next)))
+
+(define (last coll)
+ "Return the last time in coll, in linear time."
+ (if (next coll)
+ (last coll)
+ (first coll)))
+
+(define (false? x)
+ (eq? #f x))
+
+(define (true? x)
+ (eq? #t x))
+
+(define nil 'nil)
+
+(define (nil? x)
+ (eq? nil x))
+
+(define-syntax when-not
+ (syntax-case
+ (())))
+
+#|
+
+If I implement ML-like interface abstractions in scheme, what would it look like?
+
+
+;; seq
+
+(define-class <seq> () (_first))
+
+
+;; Functor
+
+(define-class <functor> ())
+
+(define-method (fmap (f <procedure>) (coll <functor>)))
+
+
+;; Applicative
+
+;; a -> f a
+(define-method (pure (a <any>)))
+
+;; f (a -> b) -> f a -> f b
+(define-method (<*> (f <procedure>) (a <applicative>) (b <applicative>)))
+
+;; f a -> f b -> f b
+(define-method (*> (a <applicative>) (b <applicative>)))
+
+;; f a -> f b -> f a
+(define-method (<* (a <applicative>) (b <applicative>)))
+
+|#