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: Thu, 29 Oct 1992 15:06:54 -0600

on Tuesday, i posted the question as to why i got the error message below.


voteTuesday[1,0] := a
voteTuesday[0,1] := b
voteTuesday[x_,y_] := c
Attributes[voteTuesday] = Listable;

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

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

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


voteTwice[1,0] := a
voteTwice[0,1] := b
voteTwice[x_,y_] := c

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

==============

dan scott (thanks dan) pointed out that mathematica is pattern-matching the
entire expression voteTwice[cat,dog] to give c and of course, Thread[c]
then produces the message.

i thought i might avoid the problem using the following rule set:

vote[1,0] := a
vote[0,1] := b
vote[x_Integer,y_Integer] := c

but this produces:

Thread[vote[cat,dog]]
{vote[{1, 0, 0}, {1, 1, 0}], vote[{0, 1, 0}, {1, 0, 0}]}

so what i've come up with is the incredibly ugly


Map[(Thread[#])&,Thread[vote[cat,dog]]]
{{c, b, c}, {b, a, c}}

so Listable is really different than just automatically Threading, i guess.


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






  • Prev by Date: Tables of special functions
  • Next by Date: RE: Uses in h.s.APcalculus
  • Previous by thread: Re: Tables of special functions
  • Next by thread: Listable vs. Thread