Hi, a toy for people who want to experiment with the use of
immutable lists in Rebol.
REBOL [
Title: "Imlist"
File: %imlist.r
Date: 10/1/2000
Author: Ladislav Mecir
E-mail: [EMAIL PROTECTED]
Purpose: {Immutable lists for experimenting purposes in Rebol
Primitives:
empty-il ; the empty IL
il-empty? ; finds out if an IL is empty - returns TRUE
or FALSE
il-first ; returns the first element of a non-empty IL
prepend ; prepends an element
il-next ; for a non-empty IL returns the IL without
it's first element
}
Comment: {Not truly immutable
a) the private attributes shall be really private,
b) you can prepend a mutable value
- the solution may be to simply forbid prepending
mutable values,
that requires a change of the prepend function
}
]
; An empty IL
empty-il: make object! [
;Private elements, do not touch!
what: nxt: none
]
; Basic manipulations
il-empty?: func [il] [none? il/nxt]
il-first: func [il] [
either il-empty? il [
print "Error, trying to get the first element of an empty
IL." halt
] [il/what]
]
prepend: func [elem il] [
make empty-il [what: elem nxt: il]
]
il-next: func [il] [
either il-empty? il [
print "Error, trying to shorten an empty IL." halt
] [il/nxt]
]
; Derived manipulations
; Warning! This version is recursive, you can't create a large
list!
enumerate: func [start end] [
either start > end [empty-il] [
prepend start enumerate start + 1 end
]
]
> That would leave us, at least in the short run, with options a)
or
> d). I certainly wouldn't ask anybody at REBOL, Inc. even to
THINK
> about b) or c) unless/until some compelling arguments could be
made
> that the resulting advantages were so great as to offset the
effort
> and schedule hit.
>
> Anybody game for d)?
>