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

The map function

 [1/4] from: sharriff::aina::med-iq::de at: 8-Nov-2000 8:12


Hi Andrew! USAGE: MAP Arg1 Arg2 /Only DESCRIPTION: Maps a function to all elements of a block. MAP is a function value. ARGUMENTS: Arg1 -- (Type: any-function block) Arg2 -- (Type: any-function block) REFINEMENTS: /Only -- Inserts the result of the function as a series. (SPECIAL ATTRIBUTES) throw catch
>> adder: func [ a b ] [ a + b ] >> testblock: [ "element1" "element2" ]
== ["element1" "element2"]
>> map testblock adder
** Script Error: adder is missing its a argument. ** Where: map testblock adder
>> printer: does [print "ho"] >> printer
ho
>> map [testblock] printer
ho ** Script Error: map expected Arg2 argument of type: any-function block. ** Where: map [testblock] printer
>> map [testblock] [printer]
** Script Error: Cannot use "Map block!" on "block!" value. ** Where: map [testblock] [printer]
>> map testblock [printer]
** Script Error: Cannot use "Map block!" on "block!" value. ** Where: map testblock [printer]
>>
According to the MAP help, it takes the types any-function block or block? what am I doing wrong? Sharriff Aina med.iq information & quality in healthcare AG www.med-iq.de

 [2/4] from: petr:krenzelok:trz:cz at: 8-Nov-2000 9:32


[Sharriff--Aina--med-iq--de] wrote:
> Hi Andrew! > USAGE:
<<quoted lines omitted: 32>>
> According to the MAP help, it takes the types any-function block or block? > what am I doing wrong?
map imho uses only ONE item thru each iteration, so doing a + b imho will not work (I never looked at map source thought :-) and so you can't do a + b upon "just-some-string" ... but maybe I am wrong ... -pekr-

 [3/4] from: al:bri:xtra at: 8-Nov-2000 22:48


Sharriff wrote:
> According to the MAP help, it takes the types any-function block or block?
what am I doing wrong?
>> f: func [a] [join a " hello"] >> f 3
== "3 hello"
>> type? :f
== function!
>> type? f
** Script Error: f is missing its a argument. ** Where: type? f
>> map [1 2 3] :f
== ["1 hello" "2 hello" "3 hello"]
>> map :f ["Andrew says"]
== ["Andrew says hello"] Note the ":", colon or "snake-bite". Andrew Martin Swanning about... ICQ: 26227169 http://members.nbci.com/AndrewMartin/

 [4/4] from: al:bri:xtra at: 8-Nov-2000 22:59


> >> adder: func [ a b ] [ a + b ] > >> testblock: [ "element1" "element2" ]
<<quoted lines omitted: 3>>
> ** Where: map testblock adder >> accumulate 0 [1 2 3 4] func [a v] [a + v]
== 10 Seems more appropriate. Andrew Martin Accumulating Zzzzzz... ICQ: 26227169 http://members.nbci.com/AndrewMartin/

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