Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Model hacking

From: joel:neely:fedex at: 23-Jun-2001 8:14

rehi, Ladislav, Ladislav Mecir wrote:
> > Would it do violence to your model to address the notion > > that > > > > index? foo > > > > must lie within the range 1 thru 1 + LENGTH? FOO and that > > I would say, that it must lie within the range 1 thru > 1 + LENGTH? HEAD FOO >
My typo, oops! (corrected a few lines further on)
> > > > tail? foo > > > > is equivalent to > > > > index? foo = (1 + length? head foo) > > > > > > > > 1) LITERAL -- Some types (e.g., decimal!, time!, > > > > block!) have the property that you > > > > can explicitly represent a value of that type in REBOL > > > > source code. For other types (e.g., list!, object!, or > > > > function!) you can only write expressions (e.g., make or > > > > copy) that cause such a value to be constructed when the > > > > expression is evaluated. >
I should add that LOGIC! and NONE! are (in the terms above) non-literal types. Failure to understand this is another fruitful source of confusion for REBOL beginners.
> > > This is an interesting category. The only "problem" > > > (thinking out loud) is, that if you want, you can use any > > > Rebol value as "literal" in a composed block. >
As COMPOSE is a native which causes further evaluation of (parts of) its argument, I view COMPOSE (and REDUCE, for that matter) in the same category as MAKE and COPY. If one of them is required to cause the construction of values of a given type at run time , then that type is not "literal" in the sense I was attempting to define.
> > Part of the motivation has to do with our old friend... > > > > koan: func [x /local z] [ > > z: [] append z x mold head z > > ] > > > > ...snip... > > > Finally, if we > > wished KOAN to deal with LIST! instead of BLOCK! data, we > > are forced to write... > > > > koan: func [x /local z] [ > > z: make list! 0 append z x mold head z > > ]
...
> > Consequently, we cannot create the situation that occurred > > in the first case. > > My motivation was exactly the same: you can create almost > anything (especially in Rebol!), if you will: > > koan: func [x /local z] reduce [ > first [z:] make list! 0 'append 'z 'x 'mold 'head 'z > ]
...
> koan 4 ; == "make list! [4]" > koan 6 ; == "make list! [4 6]" > koan 17 ; == "make list! [4 6 17]" >
While a nice demonstration of the REBOL's subtlety, this is IMHO a *different* subtlety than the one I was discussing as the situation above. Since it uses REDUCE to construct the function body prototype, we're no longer dealing with literal values. What I mean by "the situation" was the case in which the programmer uses in his/her source code a literal value instead of an expression that evaluates to a value of the same type, and where that substitution causes different (side-)effects in later evaluations. I conjecture that your demonstration above was not an oversight, but rather that you deliberately thought about how to obtain the effect you wanted to demonstrate! (i.e., you're too bright for me to believe it was an accident ;-) Now, confession time. I wimped out. I had originally considered calling this characteristic LEXICAL instead of "LITERAL", but backed off in hopes of avoiding the issue of whether that word was too technical. Lo and behold, R/CUGV2.3 states on page A-19 Hash blocks must be constructed by using MAKE or TO-HASH. They have no lexical format. and again on page A-24 List blocks muste be constructed by MAKE or TO-LIST. They have no lexical format. Clearly I should have had the courage to stick with "lexical"! I now propose, with reddened face, that this property take its rightful name. In the interest of precision, here's a proposed test. Given a file named lexical.r which contains 8<------------------------------------------------------------ REBOL [] 123 123.4 1.2.3 [1 2 3] 12:34:56 2001-06-23 now is the time {those were the days} true false none 8<------------------------------------------------------------ I can ask REBOL to evaluate the following:
>> foo: load %lexical.r
== [ 123 123.4 1.2.3 [1 2 3] 12:34:56 23-Jun-2001 "now is the time" "those were the days" ...
>> length? foo
== 11
>> foreach item foo [print [type? item "^-" item]]
integer 123 decimal 123.4 tuple 1.2.3 block 1 2 3 time 12:34:56 date 23-Jun-2001 string now is the time string those were the days word true word false word none as the basis for stating that integer!, decimal!, tuple!, block!, time!, date!, and string! are lexical types and that logic! and none! are not. Further, if I insert another line at the beginning of the file, so that it begins 8<------------------------------------------------------------ REBOL [] make list! [1 2 3] 123 123.4 1.2.3 8<------------------------------------------------------------ ... and so on ... I can repeat the experiment.
>> foo: load %lexical.r
== [ make list! [1 2 3] 123 123.4 1.2.3 ...
>> length? foo
== 14
>> foreach item foo [print [type? item "^-" item]]
word make word list! block 1 2 3 integer 123 decimal 123.4 ... etc. Since I did not suceed in getting a list! as the first element of FOO, I consider list! as non-lexical. I'd be very interested to see any demonstration of text typed into the front of the file that actually does load to a list! value. We can continue the experiment by performing an additional evaluation step, as in
>> baz: reduce foo
== [make list! [1 2 3] 123 123.4 1.2.3 [1 2 3] ...
>> length? baz
== 12
>> foreach item baz [print [type? item "^-" item]]
list 1 2 3 integer 123 decimal 123.4 tuple 1.2.3 ... but there was no list! until the REDUCE performed its evaluation. -jn- ------------------------------------------------------------ Programming languages: compact, powerful, simple ... Pick any two! joel'dot'neely'at'fedex'dot'com