Hello everybody,
Here a few more snippets on PRIMO design I've been
thinking about.
I often read Ladislav's writings on REBOL and share
a lot of concerns and appreciate his deep understanding
about many of the aspects and implications of REBOL
as it currently is.
Here, I would like to address certain aspects which
he pointed out in his excellent REBOL enhancement
proposal, and consider these fixes which address
some of the points he raised there.
First of all words & values.
Some Rules for PRIMO,
1. All words are local to the context they are
created in, including and especially functions.
No need to declare /locals, all local by default.
2. Ways of (re)Defining words.
>> Constant word value ; note value any-type! even unset
; note constants can NOT be changed and are immutable for
; the duration / lifetime of the porgram. Use with caution,
; they are CONSTANT and can not be changed once set.
: there is No contant-word! format, word must be explicitly
; defined as constant with the 'CONSTANT function.
>> set word value ; note value any-type! even unset
>> word: value ; set-word! format
; as per existing REBOL behaviour except the word arg
; can be of ordinary word format as it is quoted as a
; lit-word! in the function definition.
>> reset word value ; note value any-type! even unset
>> word:= value ; reset-word! format
; If you try to 'Set a word that is already defined then
; this will raise an exception or fire an error! hence the
; need for a reset-word! type and 'reset function.
; I got this form from PICO language which defines and
; redefines words / variables in this manner.
>> unset ; a value of type? == unset!
== unset
>> first reduce [()]
== unset
Proposal is to make UNSET a first class legal value which
can represent itself just as none represents a none! value.
The function UNSET will be replaced with a To-Unset word
function and also words can be Set or Reset to the unset value.
All words which are unset would still raise an exception or
fire an error! except for the special case word 'UNSET which
would represent the unset value of unset! type.
All this would need is an internal function to identify
words with unset values ( except of course for the word Unset)
see example code below for more examples...
unset-word?: func [ 'word ] [ pick [ true false]
(word? word) and (unset? get/any word) and ((mold word) <> "unset")]
>> x: 1
== 1
>> print x
1
>> loop 4 [ print x:= x + 1]
2
3
4
5
>> x: 2
** Script Error! word x already defined in this context
** Near x: 2
>> x:= 2
== 2
>> print x
== 2
>> x:= unset ; unset is a first class value
== unset
>> type? get/any 'x
== unset! ; unset! is the datatype
>> get/any 'x
== unset ; unset the value
>> unset ; unset used as a word! similar
== unset ; to the way the word! none denotes itself
>> type? unset
== unset!
>> unset? unset
== true
>> word? unset
== false
>> word? 'unset
== true
>> unset? get/any 'x
== true
let me know what you think,
cheers,
Mark Dickson