       RE: Assignments

• To: mathgroup at smc.vnet.net
• Subject: [mg36388] RE: [mg36295] Assignments
• From: "DrBob" <drbob at bigfoot.com>
• Date: Wed, 4 Sep 2002 02:56:46 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```>>But my actual output reproduces the input form, i.e., it is simply
f[...listA,newEntry,...].

That means your arguments don't fit a pattern for which the function is
defined.  That is, it has nothing to do with what's on the right side of
":=".  It's about making sure there are the right number and type of
arguments passed to the function.  You haven't told us what the pattern

Bobby

-----Original Message-----
From: Thomas J. Fararo [mailto:tjf2+ at pitt.edu]
To: mathgroup at smc.vnet.net
Subject: [mg36388] [mg36295] Assignments

Hello,

I am fairly new to Mathematica and once before asked a question
and
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
"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: Re: 3D plot -Reply
• Next by Date: RE: Re: Re: Re: An interesting math problem
• Previous by thread: Re: 3D plot - resend
• Next by thread: Running Mathematica in background.