Re: Types in Mathematica, a practical example
- To: mathgroup at smc.vnet.net
- Subject: [mg62946] Re: [mg62800] Types in Mathematica, a practical example
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Fri, 9 Dec 2005 05:10:27 -0500 (EST)
- References: <000f01c5fbf8$e3979330$996f1081@fy.chalmers.se>
- Sender: owner-wri-mathgroup at wolfram.com
On Dec 8, 2005, at 8:11 AM, Ingolf Dahl wrote: > Thanks for all answers. > In my previous submission I asked for a way to define/declare list > with > undefined elements. [deleted] > > What I would prefer is a new Mathematica word: "Undefined". Then I > could > define a list x as > > x = {1,Undefined,2}; > > x[[1]] should evaluate to 1 as usual, but for this word "Undefined" > the list > part x[[2]] should evaluate to x[[2]], precisely as for an undefined > unindexed symbol. > x[[4]] should give the usual error message: > > "Part::partw: Part 4 of {1, Undefined, 2} does not exist." > > x[[3]] =. and Clear[x[[3]]] should redefine x as > {1,Undefined,Undefined}, You can already do this: In[111]:= myclear[x_[[i_]]]:=x[[i]]=undefined SetAttributes[myclear,HoldFirst] x={a,b,c}; myclear[x[[2]]] x Out[114]= undefined Out[115]= {a,undefined,c} > and x = Undefined should be interpreted as x =. This would be problematic because x=Undefined assigns a value to x, x=. also assigns x a value but it's a different value, anything that depended on that behavior would break. In the sense of a general name for an undefined term, some languages offer a value called bottom, that would be an interesting addition to Mathematica but as far as I can tell it's not a common feature of LISP like languages. Regards, Ssezi