[REBOL] Life Streams
From: al::bri::xtra::co::nz at: 21-Mar-2002 16:41
Life Streams
************
Life Streams is based on LifeStreams by David Gelertner in his book,
'Machine Beauty'. Life Stream is Rebol script and is intended to serve as a
repository for data, for the past, present and future.
Life Streams is a block! of Rebol block! values. Each block! value contains
a Date! value, with either a Name Value pair or a block! of Name Value
pairs. For example:
[
[21/Mar/2002/09:28:27 "Creation" {Started work on this
document!}]
[21/Mar/2002/09:29:00 [
"Example" {Example of Name Value pairs, inside a block!
value.}
Email [Al--Bri--xtra--co--nz] ; My email address
Author "Andrew Martin"
]
]
]
A Life Stream extends both into the past and to the future. For example:
LS1: [
[1/Jan/3001 Event "First day of the third millenium."]
[1/Jan/2001 Event "First day of the second millenium."]
[25/Dec/3001 Event "First Christmas of the third millenium."]
[25/Dec/2001 Event "First Christmas of the second millenium."]
]
describes some days of the current (2001) and next (3001) milleniums.
The 'Squish operation takes a Life Stream and a Date! value, with an
optional /Before or /After refinement! value, and produces a block of Name
Value pairs which reflects the past, current or future state of the Life
Stream. For example:
Squish: func [Life_Stream [block!] Date [date!] /Before /After]
[]
Here's some examples of 'Squish in operation on the above Life Stream,
referred to by 'LS1:
Squish LS1 21/Mar/2002
== []
Squish/Before LS1 21/Mar/2002
== [
[25/Dec/2001 Event "First Christmas of the second millenium."]
[1/Jan/2001 Event "First day of the second millenium."]
]
Squish/After LS1 21/Mar/2002
== [
[1/Jan/3001 Event "First day of the third millenium."]
[25/Dec/3001 Event "First Christmas of the third millenium."]
]
Note that the resultant Life Stream eliminates dates that are not a concern
and is ordered so that the date! values closest to the current date are
first.
Note: Should 'Squish take a range of dates? Can easily create this with a
'Squish/Before and 'Squish/After on the range limits. Squish on a range of
dates probably shouldn't sort the dates.
[
Rebol []
Squish: function [Life_Stream [block!] Date [date!] /Before /After /Filter
Block block!]] [Squished Operator] [
Squished: make block! length? Life_Stream
Operator: any [
if Before [:lesser-or-equal?]
if After [:greater-or-equal?]
:equal?
]
foreach Event Life_Stream [
if Operator first Event Date [
append/only Squished Event
]
]
any [
if Before [sort/reverse Squished]
if After [sort Squished]
]
Squished
]
LS1: [
[1/Jan/3001 Event "First day of the fourth millenium."]
[25/Dec/3001 Event "First Christmas of the fourth millenium."]
[1/Jan/2001 Event "First day of the third millenium."]
[25/Dec/2001 Event "First Christmas of the third millenium."]
[21/Mar/2002 Event "Now!"]
[1/Jan/1001 Event "First day of the second millenium."]
[25/Dec/1001 Event "First Christmas of the second millenium."]
]
probe Squish LS1 21/Mar/2002
probe Squish/Before LS1 21/Mar/2002
probe Squish/After LS1 21/Mar/2002
probe Squish/After Squish/Before LS1 31/Dec/2002 1/Jan/2000
halt
]
It's an alternative to conventional databases, which exist in an eternal now
moment.
Andrew Martin
Rebol Lifer...
ICQ: 26227169 http://valley.150m.com/