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

reduce second [one two]

 [1/8] from: gchillemi:aliceposta:it at: 14-Jan-2009 0:52


Hello, I tought it was a bug but it seems a feature: Whith the following script two: 2 probe reduce second [one two] I get "TWO" as result when I expected "2". An user told me that "second [one two]" returns 'TWO instead of TWO. I do I get TWO and have it reduced to "2" ? Giuseppe Chillemi

 [2/8] from: ammon:johnson::gmail at: 13-Jan-2009 18:30


You just have 'reduce in the wrong place...
>> one: 1
== 1
>> two: 2
== 2
>> probe second reduce [one two]
2 == 2 HTH! ~Ammon ;~> On Tue, Jan 13, 2009 at 3:52 PM, Giuseppe Chillemi <gchillemi-aliceposta.it>wrote:
> Hello, > I tought it was a bug but it seems a feature:
<<quoted lines omitted: 8>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- Joe E. Lewis - "There's only one thing money won't buy, and that is poverty."

 [3/8] from: anton::wilddsl::net::au at: 14-Jan-2009 14:44


Hi Giuseppe, SECOND returns a word, and REDUCE does not reduce a word to its associated value. (REDUCE does reduce words inside a block that it is passed, so this might seem strange.) To reduce a word to its value, use GET. probe get 'two or probe get second [one two] but of course you need to know in advance that the item in the block is a word. If not, then you must do some tests on the item to see what type it is before evaluating/reducing/getting it. Anton. Giuseppe Chillemi wrote:

 [4/8] from: gchillemi:aliceposta:it at: 14-Jan-2009 7:47


> SECOND returns a word, and REDUCE does not reduce a word to > its associated value. > (REDUCE does reduce words inside a block that it is passed, > so this might seem > strange.)
In fact I have reported it as a bug making a mistake because I presumed that two: 2 Probe REDUCE second [one two] was the same of two: 2 probe REDUCE TWO Instead "second [one two]" returns 'TWO rather than TWO which is a thing you don't notice in the consolle as the ouput is TWO in both situations.
> To reduce a word to its value, use GET. > > probe get 'two > > or > > probe get second [one two]
The latter is the answer I have been searching for. Thanks in advance Giuseppe Chillemi

 [5/8] from: compkarori::gmail at: 14-Jan-2009 10:47


I think this is a common error. While it's in the block, it's just unevaluated words. but do second [ one two ] should work. On Wed, Jan 14, 2009 at 7:47 PM, Giuseppe Chillemi <gchillemi-aliceposta.it> wrote:
>> SECOND returns a word, and REDUCE does not reduce a word to >> its associated value.
<<quoted lines omitted: 21>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- Graham Chiu http://www.synapsedirect.com Synapse - the use from anywhere EMR.

 [6/8] from: tim-johnsons::web::com at: 13-Jan-2009 15:28


On Tuesday 13 January 2009, Giuseppe Chillemi wrote:
> probe reduce second [one two]
I've never used 'reduce on a "singleton" value, which is what you are doing here: (evaluating right to left)
>> second [one two]
== two ;; get the value
>> probe get reduce second[one two]
2 == 2 Is this what you are after? cheers tim

 [7/8] from: santilli:gabriele:gma:il at: 14-Jan-2009 11:39


[Also sent privately because Ecartis does not like me anymore] On Wed, Jan 14, 2009 at 7:47 AM, Giuseppe Chillemi <gchillemi-aliceposta.it> wrote:
> Instead "second [one two]" returns 'TWO rather than TWO which is a thing you > don't notice in the consolle as the ouput is TWO in both situations.
It's the opposite:
>> second [one two]
== two
>> type? second [one two]
== word!
>> two
== 2
>> type? two
== integer!
>> 'two
== two
>> type? 'two
== word!
>> type? second ['one 'two]
== lit-word! two is a word!. When a word is evaluated (DO or REDUCE), it produces the value it is set to. "'two" is a lit-word!. When a lit-word is evaluated (DO or REDUCE), it produces the respective word value. You are not getting a lit-word from second, but a word, which is indeed the second value in the block. But, if you type:
>> reduce two
== 2 the REDUCE function is not getting a word as argument, it is getting the integer 2, because the word is evaluated BEFORE being passed to REDUCE. Notice above how "two" produces "2" and how "type? two" returns "integer!" and NOT "word!". HTH, Gabriele.

 [8/8] from: Izkata::Comcast::net at: 26-Jan-2009 1:44


On Wed, 2009-01-14 at 11:39 +0100, Gabriele Santilli wrote:
> "two" is a word!. When a word is evaluated (DO or REDUCE), it produces > the value it is set to. "'two" is a lit-word!. When a lit-word is > evaluated (DO or REDUCE), it produces the respective word value. You > are not getting a lit-word from second, but a word, which is indeed > the second value in the block. But, if you type:
Reduce will not evaluate a word unless it is in a block:
>> two: 2
== 2
>> type? second [one two]
== word!
>> type? 'two
== word!
>> reduce 'two
== two
>> reduce [two]
== [2]

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