Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1992
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1992

[Date Index] [Thread Index] [Author Index]

Search the Archive

Listable vs. Thread

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: Listable vs. Thread
  • From: gaylord at ux1.cso.uiuc.edu
  • Date: Wed, 28 Oct 1992 06:53:31 -0600

i understood Listable to be an attribute which automatically threads a function.

I therefore expect that i could either makea function Listable or I could
'manually' Thread it to its arguments. 

However, as the example below shows, using Thread with the function does
not work the same as  maing the function Listable (in fact using Thread
appears to go to too low a level producing an error message.

could someone please explain exactly what's going on here (i don't
understand why using Thread produced an error) and what functions need to
be 'manually' applied to a function for it to work the same way as it does
when its Listable.

thanks.







dog = {{1,0,1,1},{1,1,1,0}};

cat = {{1,1,0,1},{1,1,0,0}};

doIt[x_,0] := a
doIt[0,y_] := b
doIt[x_,y_] := c
Attributes[doIt] = Listable

Listable

doIt[dog,cat]
{{c, b, a, c}, {c, c, a, a}}


dontDoIt[x_,0] := a
dontDoIt[0,y_] := b
dontDoIt[x_,y_] := c


Thread[dontDoIt[dog,cat]]
Thread::normal: 
   Normal expression expected at position 1 in Thread[c].
Thread[c]

richard j. gaylord, university of illinois, gaylord at ux1.cso.uiuc.edu

"if you're not programming functionally, then you must be programming
dysfunctionally"








  • Prev by Date: Re: Question about changing variables in PDEs
  • Next by Date: Re: Question about changing variables in PDEs
  • Previous by thread: Listable vs. Thread
  • Next by thread: RE: Uses in h.s.APcalculus