Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: visual subscripts with assignment



Hi Isaac,

the problem is that Subscript evaluate it's argument. When x has a value
assigned Subscript[x,_] will evaluate to the value ({1,2,3,4,5} in Your
example) 

Here is the woking definition

SetAttributes[Subscript,HoldFirst]
x/: Subscript[x,i_]:=x[[i]] /; Length[x]>i

h
Hope that helps 
  Jens


> Can someone tell me why assignment doesn't seem to work with visual
> subscripting?  Here's what I got:
> 
> In[1]:=
> \!\(x_\_i_ := x[\([i]\)]\)
> In[2]:=
> x={1,2,3,4}
> Out[2]=
> {1,2,3,4}
> In[3]:=
> \!\(x\_2\)
> Out[3]=
> 2
> In[4]:=
> \!\(x\_2 = 5\)
> Out[4]=
> 5
> In[5]:=
> x
> Out[5]=
> {1,2,3,4}
> 
> Issac
> 
> 
> 



  • Prev by Date: Unpredictable effects of comments
  • Next by Date: Re: sort and find in MATHEMATICA like in MATLAB
  • Prev by thread: visual subscripts with assignment
  • Next by thread: Re: visual subscripts with assignment