Re: Re: part assigned sequence behavior puzzling
- To: mathgroup at smc.vnet.net
- Subject: [mg105380] Re: [mg105302] Re: part assigned sequence behavior puzzling
- From: danl at wolfram.com
- Date: Mon, 30 Nov 2009 06:11:30 -0500 (EST)
- References: <hekujm$96g$1@smc.vnet.net>
> I'd say that this is not a wise design decision. IMHO, a statement > like tmp=tmp should have no effect on tmp, whereas with this > SequenceHold situation it has. > > Cheers -- Sjoerd Perhaps so. I view it, paraphrasing Churchill, as the worst possible design, except for all the rest. In the alternative scenario, Sequence[...] things would (I guess) cause immediate evaluation of the left hand side. This has some bad consequences and maybe also raises a few questions. Bad consequences: (1) It changes assignment semantics. (2) It means that deeply nested expressions cannot readily be built because complexity of adding a level becomes worse (maybe this can largely be short-circuited, I'm not sure). Questions: (1) What is the expected/intended behavior of In[87]:= ss = {a, b, c, d}; Do[ss[[j]] = Sequence[j, j + 1], {j, Length[ss]}] ? (2) What about ss2 = Table[Unevaluated[Sequence[i, i^2]], {i, 4}] ? Maybe that second one is obvious, and no different from current behavior. All the same, I think it would not be good to have a semantics wherein the assignment in the Do loop causes evaluation of the lhs in each iteration. Daniel Lichtblau Wolfram Research > On Nov 26, 6:01 am, Bob Hanlon <hanl... at cox.net> wrote: >> As stated in the documentation for sequence: assignment and replacement >> f= > unctions have attribute SequenceHold >> >> Attributes[Set] >> >> {HoldFirst,Protected,SequenceHold} >> >> tmp = Range[15] >> tmp[[7]] = Sequence @@ Range[2]; >> tmp[[7]] = Sequence @@ Range[2]; >> tmp[[7]] = Sequence @@ Range[2]; >> tmp >> >> {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} >> >> {1,2,3,4,5,6,1,2,8,9,10,11,12,13,14,15} >> >> tmp = Range[15] >> tmp[[7]] = Sequence @@ Range[2]; >> tmp = tmp; >> tmp[[7]] = Sequence @@ Range[2]; >> tmp = tmp; >> tmp[[7]] = Sequence @@ Range[2]; >> tmp >> >> {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} >> >> {1,2,3,4,5,6,1,2,2,2,8,9,10,11,12,13,14,15} >> >> Bob Hanlon >> >> ---- mkr <mileskra... at gmail.com> wrote: >> >> ============= >> I am puzzled by the following behavior: >> >> tmp = Range[15] >> tmp[[7]] = Sequence @@ Range[2]; >> tmp[[7]] = Sequence @@ Range[2]; >> tmp[[7]] = Sequence @@ Range[2]; >> tmp >> >> yields >> >> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} >> {1, 2, 3, 4, 5, 6, 1, 2, 8, 9, 10, 11, 12, 13, 14, 15} >> >> I would have expected the repeated assignment to have a repeated >> effect, thus obtaining >> >> {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} >> {1, 2, 3, 4, 5, 6, 1, 2, 2, 2, 8, 9, 10, 11, 12, 13, 14, 15} >> >> Where/why am I wrong? > >