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

Summing a list

 [1/7] from: emekamicro:gmai:l at: 2-Sep-2010 16:43


Hello All, suma: func [series] [ if empty? series [0] [add first series suma next series] ] Why is it that I am getting error here. Regards, Emeka

 [2/7] from: dhsunanda::gmail at: 2-Sep-2010 16:57


Try this: suma: func [series] [ if empty? series [return 0] add first series suma next series ] Your problem was having the [add first...] in a block. It needs to be open code Sunanda

 [3/7] from: emekamicro::gmail at: 2-Sep-2010 17:06


Sunanda, I thought that "if" signature is this: if good-enough? nums [ bla blal] [weep weep] Why is it that yours is different? Emeka On Thu, Sep 2, 2010 at 4:57 PM, Sunanda <dhsunanda-gmail.com> wrote:

 [4/7] from: izkata::gmail at: 2-Sep-2010 11:23


'if doesn't have an else-block by default. You can use "help if" to see its refinements. Two ways to do it, one with the refinement, the other with a different function: if/else empty? series [0] [add first series suma next series] either empty? series [0] [add first series suma next series] What Sunanda is doing is, exiting the function early if the series is empty. That way the remainder only gets evaluated if the series is not empty, acting like an 'else' without actually being one. On Thu, Sep 2, 2010 at 11:06 AM, Emeka <emekamicro-gmail.com> wrote:
> Sunanda, > I thought that "if" signature is this:
<<quoted lines omitted: 23>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
-- <*>

 [5/7] from: andreas:bolka:gmx at: 2-Sep-2010 18:24


On Thu Sep 02 18:06:41 +0200 2010, Emeka wrote:
> I thought that "if" signature is this: > > if good-enough? nums [ bla blal] [weep weep] >> ? if
USAGE: IF condition then-block /else else-block
>> ? either
USAGE: EITHER condition true-block false-block -- a

 [6/7] from: dhsunanda:gma:il at: 2-Sep-2010 17:28


> I thought that "if" signature is this: > > if good-enough? nums [ bla blal] [weep weep]
That's the either signature: for a 1 3 1 [ print a either a = 2 [print true] [print false] ] Compare running the code above with this code: for a 1 3 1 [ print a if a = 2 [print true] print "it's any number" ] You can also use if/else, but most REBOLers prefer the EITHER method: http://www.rebol.com/docs/words/wif.html Sunanda.

 [7/7] from: emekamicro:gma:il at: 2-Sep-2010 17:38


Thanks :( On Thu, Sep 2, 2010 at 5:28 PM, Sunanda <dhsunanda-gmail.com> wrote:

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