MathGroup Archive 1999

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

Search the Archive

Re: an answer to Q: efficient in-place list elementreplacement?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21164] Re: an answer to [mg21091] Q: efficient in-place list elementreplacement?
  • From: Jacqueline Zizi <jazi at club-internet.fr>
  • Date: Fri, 17 Dec 1999 01:22:40 -0500 (EST)
  • References: <199912140513.AAA20897@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com


steve at smc.vnet.net wrote:

> Please resend you message as ascii text and not as an attachment which
> does not come through well.

I sent it using Eudora, not as an attachment. This time I try Netscape.
Hope it's alright now.

Please find included an answer of the question of  simon shannon
<sshannon at taz.dra.hmg.gb>

Question:(1) Why is the Sequence head still there?
--------

---> Answer: You hard put, with =, instead of a[[3]],  a sequence don't
you? So here it is. And if you ask what is 'a' you get the sequence as
well:
?a
"Global`a"
a = {4, 5, Sequence["a", "b", "c"], 7, 67, 89}


Question (2) Why was it invisible to Part---ie a[[4]] was happy to give
the
--------  result "b"

---> Answer: If you ask to print to screen the value of a [[4]] and also
a
[[7]] things are like expected:
a[[7]]
67
because then, Sequence is replaced by it's value.


Question (3) Why was it also invisible to Length?
---------
---> Answer:
same answer Length evaluate it's arguments before acting.


Question (4) why does even FullForm[a] and InputForm[a] not acknowledge
---------------- the presence of the Sequence head?
---> Answer: same answer FullForm evaluate it's arguments before acting.
You can see that on
the following example:
FullForm [x + x]
Times[2, x]
You have exactly the same thing in Lisp. Most functions evaluate there
parameters before acting
and especially the screen printing functions. Some not. So to work in
this
way, with an 'a' that has not the same design than the previous one, you
have to "push to" evaluation. We say "forcer l'évaluation" in Lisp in
France. But, when we are pushed to that , we know too that probably we
have to rethink the design of our program. Somewhere, probably, some
choice has not been done in the better way.

Question (5) what i am trying to avoid is copying the list a.
------------
One solution is:
a = Evaluate [a];
?a
"Global`a"
a = {4, 5, "a", "b",
"c", 7, 67, 89}
and then:
a [[7]] = Pi;
a
{4, 5, "a", "b", "c", 7, \[Pi],89}

Another solution is after clearing a and set the things again:
a = a /.Sequence [a, b, c] -> Sequence [a, b, c] a [[7]] = \[Pi]
Anything where a is evaluated will work.

Conclusion
=========
I answered your question as it is, but I could notice that, from my point
of view, you over use =.
For example p=3 then a [[p]=...Why not a [[3]]?
Therefore I manage an answer  with = in it to please you and to fit your
question.
But, I nearly never use = myself and I'm wondering if the situation where
you get could not be avoid.

Indeed you said: "my real problem a is a large complicated list with lots
of substructure".
Don't you think that in computer science like in Mathematics, like in
cooking, the simplest is the best?
Are you sure of the primary design of your real problem?






  • Prev by Date: Re: 2 coupled diff. eqns
  • Next by Date: Re: Q: efficient in-place list element replacement?
  • Previous by thread: Re: Dropping terms in a complex expression
  • Next by thread: [Fwd: Graphics3D[] objects clipping & PlotRange]