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

[REBOL] Re: change/at

From: joel:neely:fedex at: 19-Sep-2002 13:32

Hi, Pat, Think of the brackets around a literal block as being similar to quotation marks. See below. pat665 wrote:
> The original problem was to change false to true for the ith > position in a block ( [ false false false ] becoming > [ false true false ] > > Romano and Gabriele suggested poke, which I had obviously missed. > Joel Neely's answer was interesting and pointed to another gotcha > > >> test: [[0] [0] [0]] == [[0] [0] [0]] > >> i: 2 == 2 > >> test/:i/1: 1 == [1] > > >> neither of the expressions > >> test: [false false false] > >> nor > >> test: [[false][false][false]] > >> contain LOGIC! values ;-) > > Isn't odd ? Because I needed logic! values. I found out that the > correct way to do it was > > test: reduce [false false false] > > How come it is so ? I frankly do not understand ! >
In the case of foo: "1 23 456 -7" a human being might say that there are four numbers in the value of FOO, but to REBOL FOO is just set to a STRING! value. If I want the numeric values I think I'm seeing, then I have to ask REBOL to convert from a string to a block of numbers, which I can do via baz: load foo which sets BAZ to a block of four numbers by "interpreting" the string. Similarly, if I say foo: [false true none] I have just created a block containing four "uninterpreted" words, as illustrated by the following snippet:
>> foreach item foo [print type? item]
word word word
If I want to ask for those words to be interpreted as the (non- literal) REBOL values that my eyes keep trying to tell me are present, I need to REDUCE the block.
>> baz: reduce foo
== [false true none]
>> foreach item baz [print type? item]
logic logic none
Of course, there are drawbacks to this need to REDUCE what might be arbitrary blocks of words/expressions. That's why RT has added a couple of new features, CONSTRUCT and source syntax for several previously un-expressible values. For details, see: 3.1. CONSTRUCT Object Creator and 4.1. Source Code Form for Values of NONE, TRUE, etc. in the document at -jn-