MathGroup Archive 2002

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

Search the Archive

Assignments

  • To: mathgroup at smc.vnet.net
  • Subject: [mg36295] Assignments
  • From: "Thomas J. Fararo" <tjf2+ at pitt.edu>
  • Date: Fri, 30 Aug 2002 01:19:21 -0400 (EDT)
  • Organization: University of Pittsburgh
  • Sender: owner-wri-mathgroup at wolfram.com

Hello,

         I am fairly new to Mathematica and once before asked a question and
received some
very helpful responses.  This time the problem seems very odd and I may be
making a very
elementary error.  Here is the context:

        I define a function of the form:

                              f[...,listA_, newEntry_,...]:= Which[...]

Here Which has the form of a set of  logically exclusive and exhausive
tests, each test with its own
action that modifies the concrete list subsituted for listA_.

        For instance, if there were only two tests the rhs above would be
one that puts the newEntry
at the start of listA and the other that puts it at the end:

                       Which[
                             test1, listA = Insert[listA, newEntry, 1],
                             test2, listA = Insert[listA, newEntry, -1]
                             ]

Then I try to use the function, substituting values for the arguments:
f[..., listA, newEntry, ...].  The
output should be the appropriately modified list.   But my actual output
reproduces the input form,
i.e., it is simply f[...listA,newEntry,...].

        Yet, the program does do something, as the use of "evaluate in
place"shows:

        Suppose that test1 is satisfied by the particular values of the
arguments.  Then when
I apply "evaluate in place" to the lhs of the action that is supposed to
occur when test1 is true,
in fact the value of Insert[listA,newEntry,1] is correct, but the rhs gives
only the initial value of
listA and not the modified value that is on the rhs.

       Concretely, suppose that in the function argument listA is {121} and
newEntry is 200.
Then after evaluation of the function (input to the kernel), that line
reads, according to
"evaluate in place":

                                   true, {121} = {200, 121}

So it seems that only part of the correct action was taken: 200 was put at
the start of listA. But
the assignment of this value -- the extended list -- to be the new value of
listA did not take place.

 I then tried using a new name for the modified list, substituting this
program line for test1:

                                   test1, newListA = Insert[listA, newEntry,
1]

What I get here, applying "evaluate in place" after evaluating the function
with concrete values as above
is:

                                   true, newListA = {200, 121}

       Trace doesn't help because all I get back is the function name with
its concrete arguments.

       Any thoughts?

                                   Thank you,
                                   Tom





  • Prev by Date: Operating on Level Subparts of an Expression
  • Next by Date: Re: CirclePlus precedence and bigoplus
  • Previous by thread: RE: Operating on Level Subparts of an Expression
  • Next by thread: PlotLabel