Re: subscripts
- Posted by Lewis Townsend <keroltarr at HOTMAIL.COM> May 11, 2000
- 598 views
Hello Robert, >Lewis Townsend writes: > > b = {1, 2, 1} > > c = a [b] -- this would work like x[1][2][1] > >I think you meant a[1][2][1]. Yes, I originally used variables like x,i, and a and decided to change it but forgot to change everything. >It seems logical that Euphoria should define >what it means to subscript a sequence with a sequence. >Another way to define it would be to allow code like: > > a["Lewis"] = 99 > a["Townsend"] = {1,2,3} > ? a["Lewis"] + a["Townsend"] I don't think I understand this syntax. Does it mean that it looks for the string "Lewis" in a and replaces it wit 99? This hardly seems logical but maybe you are doing something else? In my proposed syntax: a["Lewis"] = 99 -- would convert to: a[['L']['e']['w']['i']['s']] = 99 which would generate an error because the innermost set of subscripts isn't even subscripting anything! This isn't at all what I was talking about. >I haven't been impressed enough with either way. >They are both fairly easy to implement, and won't >break existing code, but I suspect that neither would >be used that often or with that much advantage over >alternative ways of coding. I don't want to clutter >up the language with lots of features that are rarely >of much use. It would also allow some >subscript errors to evade immediate detection. What about vertical slicing? I believe this would be used quite often by lots of people. Would it be easy to implement? Also, I guess that my main point is that I would like sequences to be legal subscripts. Of cours it could still flag an error if someone tried this: x = {1,2} a = {1,2,3,4} ? a [x] -- ERROR -- obviously 'a' isn't a two deminsional sequence so it would -- error out with a subcripting an atom message. > > If anyone is interested in why (specifically) > > I want this, I'll be glad to post a more real-life example. > >Sure. Let's see it. Okay, I have some code I'm working on (and will post it too if you like), but here is the jist of what I am doing: I have a sequence that defines the structure of another sequence. Let's call the first sequence 'human'. The second: 'Lewis' human = {{"Name", {"First", "Last"}}, "Age"} Lewis {{"Lewis", "Townsend"}, 21} Can you see the relation ship between these? I now have a function that is fed 'human' and a string that coresponds to a string inside 'human' x = GetSubscript (human, "Name") -- This would return {1} becuase "Name" is the name of -- the first subsequence of 'human' x = GetSubscript (human, "Name.Last") --I do parsing first -- This would return {1,2} -- First it looks for "Name" and then it looks for "Last" -- returning the appropriate subscripts I would then like to use these sequences to subscript the 'Lewis' sequence: x = GetSubscript (human, "Age") -- {2} Lewis [x] += 1 -- Lewis [2] = 22 x = GetSubscript (human, "Name.Last") -- {1,2} puts (1, Lewis [x]) -- prints "Townsend" Obviously this would be helpful with OOP for Euphoria. You could define classes as I have defined 'human' and you could define objects similar to how I defined 'Lewis'. I will post more specific code if you want. This would allow having "Name" in different places for different classes. Let me know what you think. later, Lewis Townsend ________________________________________________________________________ Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com