Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #5238
| From | Richard Fateman <fateman@cs.berkeley.edu> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Bug with Sequence and Assignment by Part... |
| Date | 2011-09-27 00:10 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j5r49a$icj$1@smc.vnet.net> (permalink) |
| References | <j5f6ai$q8a$1@smc.vnet.net> <201109250942.FAA29324@smc.vnet.net> <j5pcqu$8jc$1@smc.vnet.net> |
The pronouncement that a bug is a feature is one way to cure it.
It can be fixed another way. Though I have not pondered on all the
examples, the simplest one by DanL seems to illustrate the problem
adequately.
Here is the example.
s={1,2,3}
s[[1]]=Sequence[4,5] ... sets s to apparently {4,5,2,3} (*)
s[[2]]= aha ... sets s to apparently {4,5,aha,2,3}
NOT
{4,aha,2,3}
which illustrates that (*) is apparently not the value of s.
whereas
s={1,2,3}
s[[1]]=Sequence[4,5] ... sets s to apparently {4,5,2,3} (*)
s = s ... only change from above, insert this
s[[2]]= aha ... sets s to apparently {4,aha,2,3}
note change, in last line. s is now correct.
..........
Note that z=Sequence[4,5] is really the same as Set[z,4,5].
Here's a fix. Require that Set take exactly 2 arguments. In
particular, that
means that s[[1]]=Sequence[4,5] is ILLEGAL.
Perhaps it can be converted to mean s[[1]] = List[4,5] or {4,5}
............
Will this break stuff? Only Set of items to Sequences,
and the implicit set of a pattern x__. e.g.
f[x__]:=x
y=f[1,2,3] ... sets y to Sequence[1,2,3]
Ramifications:
I think that the old use of Sequence
stuff= Sequence [a,b,c]
is used only in this way...
f[1,2,stuff,3] to simulate f[1,2,a,b,c,3].
Now consider re-writing it this way...
new={a,b,c}
f@@Join[{1,2},new,{3}]
and if you have a pattern Sequence (e.g. stuff) you write
f@@Join[{1,2},{stuff},{3}].
I suppose one could write another program, say conjoin, which would
allow the following...
f@@conjoin[1,2,stuff,3].
Another, more wholesale change would have f[x__]:=x return a List
rather than a Sequence.
in the example above, s=s would then be required -- actually,
s=conjoin@@s, or something like that
Presumably a change of this magnitude would result in disruption of the
existing code base. On the other hand, it seems to be unacceptable to
have the insertion of the command s=s change the meaning of a program.
.....
Another run through this...
Or I suppose a hack could be put in place forcing some kind of
re-evaluation after Set[<NonAtomic>, Sequence[...]]. which was
previously mentioned but thought to be too expensive...
RJF
On 9/26/2011 1:23 AM, DrMajorBob wrote:
> Amen.
>
> Bobby
>
> On Sun, 25 Sep 2011 04:42:00 -0500, BernieTheJet<berniethejet@gmail.com>
> wrote:
>
>> Thank you Leonid for the link, and thank you Oleksandr for pointing me
>> to OwnValues, I hadn't ever used that before.
>>
>> So everyone's opinion seems to be that this is not a bug and that this
>> construct is something of a manipulation of proper Mathematica syntax -
>> something approaching a hack - because Sequence is a low-level
>> function that one should understand Mathematica's evaluation sequence
>> before
>> using. Ok, that is fine. Certainly that is one interpretation ('when
>> looked at from a certain perspective'). Certainly one can't claim
>> that the use of Sequence is hidden, or in anyway indicated to be a
>> 'low-level' operator by its presentation in the Help, except insofar
>> as it is given a perfunctory presentation.
>>
>> But I think that it is just as valid to say that this 'bug' it is
>> counter to one of my favourite Mathematica design philosophy which is,
>> somewhat similar to Apple in this regard, to remove all the tedious
>> and computer-ish work from the user's care, to take care of that
>> behind the scenes, while still delivering as much of the power of the
>> language as possible. So for users to have to understand Mathematica's
>> evaluation sequence, SequenceHold (which I have never once used, or
>> perhaps even needed), or OwnValues (ditto) in order to get logical
>> behaviour from a function seems to clearly go against this
>> philosophy. Of course one can counter that there is another design
>> philosophy in Mathematica of mixing the best of all worlds, and never
>> forcing
>> oneself to strictly subscribe to any one design structure, which I
>> also support.
>>
>> For me, I just guess that Sequence is a 'hack' that WRI implemented to
>> get around the limitation that everything be a List. A 'hack' in that
>> it defied their initial plan that everything be representable as
>> Lists, and then a 'hack' in that they couldn't get it to work in a
>> logical fashion in all subsequent interactions with other functions,
>> as seen here.
>>
>> B
>>
>
>
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Bug with Sequence and Assignment by Part... BernieTheJet <berniethejet@gmail.com> - 2011-09-22 11:31 +0000
Re: Bug with Sequence and Assignment by Part... "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-09-23 07:48 +0000
Re: Bug with Sequence and Assignment by Part... David Bailey <dave@removedbailey.co.uk> - 2011-09-23 07:43 +0000
Re: Bug with Sequence and Assignment by Part... BernieTheJet <berniethejet@gmail.com> - 2011-09-25 09:42 +0000
Re: Bug with Sequence and Assignment by Part... BernieTheJet <berniethejet@gmail.com> - 2011-09-26 08:15 +0000
Re: Bug with Sequence and Assignment by Part... DrMajorBob <btreat1@austin.rr.com> - 2011-09-26 08:23 +0000
Re: Bug with Sequence and Assignment by Part... Richard Fateman <fateman@cs.berkeley.edu> - 2011-09-27 00:10 +0000
csiph-web