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

change/at

 [1/12] from: rebol665:ifrance at: 18-Sep-2002 13:21


Hi List, I think I fall in a very common gotcha. The starting point was: test: [ false false false ] i: 2 I wanted to change false to true for the ith position ( [ false false false ] becoming [ false true false ] ). My first attemp was: test/:i: true The result was ** Syntax Error: Invalid word -- :i: ** Near: (line 1) test/:i: true I ran thru my Core.pdf, reading every line with a path word inside. I failed. I was tired. I gave up. Isn't it too bad ? Now I have found a solution change at test i true Does anyone know a better answer ? Wouldn't it be nice to have a /at refinement for change, giving a more intuitive (in my eyes) ? change/at test i true Patrick

 [2/12] from: rotenca:telvia:it at: 18-Sep-2002 18:43


Hi pat
> test/:i: true
you could try with poke. --- Ciao Romano

 [3/12] from: tomc:darkwing:uoregon at: 18-Sep-2002 10:02


yes, it is true that you cannot both get and set a word with the same variable in your example ":i:" there are many ways around it of course an old standby is
>> test: [false false false]
== [false false false]
>> i: 2
== 2
>> poke test i true
== [false true false] another Gerald C.(?) inspired back in June
>> test: [false false false]
== [false false false]
>> i: 2
== 2
>> do rejoin['test "/" i ": " true]
== [false true false] I am sure there are many others. On Wed, 18 Sep 2002, pat665 wrote:

 [4/12] from: g:santilli:tiscalinet:it at: 18-Sep-2002 19:46


Hi pat665, On Wednesday, September 18, 2002, 1:21:21 PM, you wrote: p> change/at test i true poke test i true Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [5/12] from: joel:neely:fedex at: 18-Sep-2002 13:09


Hi, Pat, pat665 wrote:
> Hi List, > I think I fall in a very common gotcha. The starting point was:
<<quoted lines omitted: 10>>
> ** Syntax Error: Invalid word -- :i: > ** Near: (line 1) test/:i: true
Very common indeed. I think most of us have been bitten by that (or at least struggled to find a way to accomplish the equivalent) somewhere along our respective REBOL paths. The best solution I've found (in terms of consistency and speed, but not necessarily in terms of obviousness ;-) is this:
>> test: [[0] [0] [0]] == [[0] [0] [0]] >> i: 2 == 2
<<quoted lines omitted: 4>>
>> test/:i/1: 2 == [2] >> test == [[0] [1] [2]]
(I switched to numeric values to avoid having to discuss why neither of the expressions test: [false false false] nor test: [[false][false][false]] contain LOGIC! values ;-) The extra level of structure apparently costs less than the extra words required to do PICK or POKE or CHANGE ... AT ... or any other variation that I've found thusfar. -jn-

 [6/12] from: greggirwin:mindspring at: 18-Sep-2002 17:40


Hi Pat, << Wouldn't it be nice to have a /at refinement for change, giving a more intuitive (in my eyes) ? >> Other gave you some thoughts, so I'll just add that, to me, there doesn't seem to be any benefit to adding an /AT refinement to CHANGE. change at test i true vs. change/at test i true --Gregg

 [7/12] from: rebol665::ifrance::com at: 19-Sep-2002 17:59


Hi List, I have been "unsubscribed" from the list for a couple of days. Therefore I have not been able to see the replies to my "change/at" post. 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
<<quoted lines omitted: 4>>
>> 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 ! Ciao, Patrick

 [8/12] 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
<<quoted lines omitted: 13>>
> 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 http://www.reboltech.com/downloads/changes.html -jn-

 [9/12] from: g:santilli:tiscalinet:it at: 20-Sep-2002 1:02


Hi pat665, On Thursday, September 19, 2002, 5:59:35 PM, you wrote: p> test: reduce [false false false] The new betas also allow to write: test: [#[false] #[false] #[false]] p> How come it is so ? I frankly do not understand ! FALSE is a word, which in the global context of a "plain" REBOL interpreter has the value of a logic! "false". But if you don't evaluate it, it is just a word!. In the current release version of REBOL there is no way to make LOAD return a value of some types (such as logic!, none!, object!, function! etc.); you always need to do some evaluation. The beta versions introduce MOLD/ALL and the new syntax to directly represent all REBOL values. Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [10/12] from: rebol665:ifrance at: 20-Sep-2002 8:35


Hi List Many thanks Joel and Gabriele for your very understandable replies. I think the Core manual should emphasize more on these kinds of thing. As many, I suppose I am used to test code on the console while using a text processor. Imagine the effect of such a test on a newbie:
>> test: [false false false]
== [false false false]
>> if test/2 = false [ print "ok" ]
== none
>> test/2
== false It's not good for the Rebolution ! May be Rebol has not yet the right documentation system. I am thinking of a kind of collaborative manual, based for example on the Core.pdf, but annotated by the List. Patrick

 [11/12] from: rebol665:ifrance at: 20-Sep-2002 8:41


Hi List, Gregg said
>> to me, there doesn't seem to be any benefit to adding an /AT refinement
to CHANGE.
>> change at test i true >>vs. >> change/at test i true >>--Gregg
I see an important difference. What a newbie will do is to try "help change" at the console. Change being the function that "Changes a value in a series and returns the series after the change.", it seems logical to search the answer here. Here again, it's not good for the rebolution ! USAGE: CHANGE series value /part range /only /dup count DESCRIPTION: Changes a value in a series and returns the series after the change. CHANGE is an action value. ARGUMENTS: series -- Series at point to change (Type: series port) value -- The new value (Type: any-type) REFINEMENTS: /part -- Limits the amount to change to a given length or position. range -- (Type: number series port) /only -- Changes a series as a series. /dup -- Duplicates the change a specified number of times. count -- (Type: number) Patrick

 [12/12] from: al:bri:xtra at: 20-Sep-2002 20:23


> Imagine the effect of such a test on a newbie: > >> test: [false false false]
<<quoted lines omitted: 5>>
> It's not good for the Rebolution ! >> test: [false false false]
== [false false false]
>> if test/2 = 'false [ print "ok" ]
ok
>> test/2
== false
>> test: [foo foo foo]
== [foo foo foo]
>> if test/2 = 'foo [ print "ok" ]
ok
>> test/2
== foo Andrew Martin ICQ: 26227169 http://valley.150m.com/

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted