1. RE: listed subscripting
- Posted by Cuvier Christian <christian.cuvier at insee.fr> Apr 24, 2006
- 501 views
> Subject: Re: listed subscripting > > > posted by: ags <eu at 531pi.co.nz> > > Antonio Alessi wrote: > > An expression like: > > }}} <eucode> > > newString- = > originalString[1..2]&"INSERT"&originalString[5..9]&originalStr > ing[27..$] > > </eucode> {{{ > > could simply become: > > }}} <eucode> > > newString- = originalString[1..2]&"INSERT"&[5..9]&[27..$] > > </eucode> {{{ > > It should be plain to implement, I mean more useful than > complicated... > > I don't think that would work very well. What if you wanted > to use multiple strings like: > > }}} <eucode> > newString = originalString[1..2] & "INSERT" & > otherString[3..5] & [5..9] > </eucode> {{{ > What would the "[5..9]" refer to? > > I like the idea of listed subscripts though. It would only > be useful IMHO if it worked with predefined sequences like: > > }}} <eucode> > constant REPORT_FIELDS = {1,5,9,13} > > sequence item > > --in some for loop > item = record[REPORT_FIELDS] > </eucode> {{{ > > That changes the semantics codepilot originally brought up though, ie: > > variable[1,5,9,13] > > does not look the same as > > variable[{1,5,8,13}] > > and Al Getz wrote: > > I've had my share of problems like this too, where you could use > > some sort of functionality to deal with sequences easier. > > Another that comes immediately to mind is > > {a,b,c,d}=s[1,2,3,4] > > I think Rob has already made his views clear on multiple > lvalue assignment and I tend to think it would be a headache > in the context of Euphoria. > > What happens (even in the case of a subscript list) if the > sequence s is not as long as the subscript list? > > Gary > Perhaps a cleaner syntax would be to mention the insert explicitly rather than through the use of & when only one sequence is involved, using & when really concatenating different things:
newString=insert(originalString[1..2,5..9,27..$],"INSERT",3) --but newString=originalString[1..2]&"INSERT"&otherString[5..9,27..$]
And of course, it is a real pain not to be able to write:
function doSomething(sequence vars) --... end function procedure whatEver() integer n1,n2 sequence s1,s2,s3 --... {n1,n2,s1,s2,s3}=doSomething({n1,n2,s1,s2,s3}) --... end procedure
The above code would allow to write a separate routine for what doSomething does, avoiding the error prone, tiresome, cluttered, unelegant urrent solution:
vars=doSomething({n1,n2,s1,s2,s3}) n1=vars[1] s1=vars[3] --etc
Rob, when will you decide to make Euphoria simple to use??? CChris
2. RE: listed subscripting
- Posted by Juergen Luethje <j.lue at gmx.de> Apr 24, 2006
- 475 views
Cuvier Christian wrote: <snip> > And of course, it is a real pain not to be able to write: > > }}} <eucode> > function doSomething(sequence vars) > --... > end function > > procedure whatEver() > integer n1,n2 > sequence s1,s2,s3 > --... > {n1,n2,s1,s2,s3}=doSomething({n1,n2,s1,s2,s3}) > --... > end procedure > </eucode> {{{ > > The above code would allow to write a separate routine for what doSomething > does, avoiding the error prone, tiresome, cluttered, unelegant urrent > solution: > > }}} <eucode> > vars=doSomething({n1,n2,s1,s2,s3}) > n1=vars[1] > s1=vars[3] > --etc > </eucode> {{{ > > Rob, when will you decide to make Euphoria simple to use??? Christian, I support your suggestion. Another eample for using the proposed syntax: -- elegant swap: {a,b} = {b,a} -- current swap: temp = a a = b b = temp Regards, Juergen -- Have you read a good program lately?
3. RE: listed subscripting
- Posted by Antonio Alessi <a.admin at myway.it> Apr 24, 2006
- 470 views
Juergen Luethje wrote: > .. .. > -- elegant swap: > {a,b} = {b,a} > > -- current swap: > temp = a > a = b > b = temp > > Regards, > Juergen > > -- > Have you read a good program lately? Hello Juergen, why temp? line = {1, 2} EU plain swap: line = line[2]&line[1] Regards, antonio -- Did you write a good program lately ? ;)
4. RE: listed subscripting
- Posted by Juergen Luethje <j.lue at gmx.de> Apr 24, 2006
- 491 views
Antonio Alessi wrote: > Juergen Luethje wrote: >> .. .. > >> -- elegant swap: >> {a,b} = {b,a} >> >> -- current swap: >> temp = a >> a = b >> b = temp > > > Hello Juergen, > > why temp? > > line = {1, 2} > > EU plain swap: > > line = line[2]&line[1] What I wrote is the classic algorithm for swapping the values of two variables, in German called "zyklische Vertauschung" (translates in English probably to something like "cyclic exchange"). In your code not the values of two variables are swapped, but the values of two elements of one variable. I was not talking about a variable 'line', which is a sequence of two elements, but of two separate variable 'a' and 'b'. Code similar to yours that does what I had described would look like this: line = {a, b} a = line[2] b = line[1] So your 'line' is a temp variable in disguise. I don't consider this way more elegant than the classic "cyclic exchange". Regards, Juergen
5. RE: listed subscripting
- Posted by Antonio Alessi <a.admin at myway.it> Apr 25, 2006
- 478 views
Juergen Luethje wrote: > > Antonio Alessi wrote: > > > Juergen Luethje wrote: > >> .. .. > > > >> -- elegant swap: > >> {a,b} = {b,a} > >> > >> -- current swap: > >> temp = a > >> a = b > >> b = temp > > > > > > Hello Juergen, > > > > why temp? > > > > line = {1, 2} > > > > EU plain swap: > > > > line = line[2]&line[1] > > What I wrote is the classic algorithm for swapping the values of two > variables, in German called "zyklische Vertauschung" (translates in > English probably to something like "cyclic exchange"). > > In your code not the values of two variables are swapped, but the values > of two elements of one variable. I was not talking about a variable > 'line', which is a sequence of two elements, but of two separate > variable 'a' and 'b'. > > Code similar to yours that does what I had described would look like this: > line = {a, b} > a = line[2] > b = line[1] > > So your 'line' is a temp variable in disguise. > I don't consider this way more elegant than the classic "cyclic exchange". > > Regards, > Juergen Sorry Juergen, but on the Euphoria ground I have to contradict what you say. Perhaps to write {a, b} = {b, a} may look "elegant", but it is not logic: the {a, b} notation, in lack of oneness is nothing, does not make sense. If you want to treat that as an entity, you must assign a Label to, i.e. identify in a unity. Cannot move two things toghether if we don't put them into the same "box". When you write an expression as {a, b} = , you introduce the concept of a variable anyhow. Fortunately Euphoria makes this possible, bringing in the concept of sequence, that overlaps without invalidating the independence of the two values; if we say: Label = {a, b} in order to handle them, we don't alter the original meaning of variable 'a' and the separate variable 'b'; simply we can hold them like an ensemble too, swapping and even using them for an expression like that of Christian: Label = doSomething({n1,n2,s1,s2,s3}) even simpler than: {n1,n2,s1,s2,s3} = doSomething({n1,n2,s1,s2,s3}) provided that: function doSomething(sequence vars)
return {n1,n2,s1,s2,s3}
end function All that with no need to add thereafter: n1 = Label[1] s1 = Label[3] since n1 IS Label[1] already; we have just to change our habit conceiving and using L[1] in place of n1, both being able to assume any kind of value. Other "programming" languages (we do not make literature here) may 'not to allow' this, as every element of an array can assume a single value, but cannot BE an unlimited sequence (a world, or individual) in itself. So your quote "In your code not the values of two variables are swapped, but the values of two elements of one VARIABLE" should be replaced with: "In your code not the values of two variables are swapped, but the values of two elements of one SEQUENCE", where the values of two variables, and the values of two elements of one sequence become the same thing, so that here we can directly do what you'd like to, respecting the taste of gracefulness in the form as well as into the idea. This is the 'soul' of Euphoria and I find it a waste to insist interpreting and using the way of any other "more traditional" language. Regards, antonio
6. RE: listed subscripting
- Posted by CChris <christian.cuvier at agriculture.gouv.fr> Apr 25, 2006
- 491 views
Antonio Alessi wrote: > > Juergen Luethje wrote: > > > > Antonio Alessi wrote: > > > > > Juergen Luethje wrote: > > >> .. .. > > > > > >> -- elegant swap: > > >> {a,b} = {b,a} > > >> > > >> -- current swap: > > >> temp = a > > >> a = b > > >> b = temp > > > > > > > > > Hello Juergen, > > > > > > why temp? > > > > > > line = {1, 2} > > > > > > EU plain swap: > > > > > > line = line[2]&line[1] > > > > What I wrote is the classic algorithm for swapping the values of two > > variables, in German called "zyklische Vertauschung" (translates in > > English probably to something like "cyclic exchange"). > > > > In your code not the values of two variables are swapped, but the values > > of two elements of one variable. I was not talking about a variable > > 'line', which is a sequence of two elements, but of two separate > > variable 'a' and 'b'. > > > > Code similar to yours that does what I had described would look like this: > > line = {a, b} > > a = line[2] > > b = line[1] > > > > So your 'line' is a temp variable in disguise. > > I don't consider this way more elegant than the classic "cyclic exchange". > > > > Regards, > > Juergen > > > Sorry Juergen, but on the Euphoria ground I have to contradict what you say. > Perhaps to write {a, b} = {b, a} may look "elegant", but it is not logic: > the {a, b} notation, in lack of oneness is nothing, does not make sense. > If you want to treat that as an entity, you must assign a Label to, > i.e. identify in a unity. Cannot move two things toghether if we don't > put them into the same "box". When you write an expression as > {a, b} = , you introduce the concept of a variable anyhow. > > Fortunately Euphoria makes this possible, bringing in the concept of sequence, > that overlaps without invalidating the independence of the two values; > if we say: > > Label = {a, b} > > in order to handle them, we don't alter the original meaning of variable 'a' > and the separate variable 'b'; simply we can hold them like an ensemble too, > > swapping and even using them for an expression like that of Christian: > > Label = doSomething({n1,n2,s1,s2,s3}) > > even simpler than: > {n1,n2,s1,s2,s3} = doSomething({n1,n2,s1,s2,s3}) > > provided that: > > function doSomething(sequence vars) > }}} <eucode> > return {n1,n2,s1,s2,s3} > </eucode> {{{ > end function > > All that with no need to add thereafter: > > n1 = Label[1] > s1 = Label[3] > > since n1 IS Label[1] already; we have just to change our habit conceiving and > > using L[1] in place of n1, both being able to assume any kind of value. > Other "programming" languages (we do not make literature here) may 'not to > allow' this, as every element of an array can assume a single value, but > cannot BE an unlimited sequence (a world, or individual) in itself. > > So your quote > "In your code not the values of two variables are swapped, > but the values of two elements of one VARIABLE" > > should be replaced with: > > "In your code not the values of two variables are swapped, > but the values of two elements of one SEQUENCE", where > > the values of two variables, and > the values of two elements of one sequence > > become the same thing, so that here we can directly do what you'd like to, > respecting the taste of gracefulness in the form as well as into the idea. > This is the 'soul' of Euphoria and I find it a waste to insist > interpreting and using the way of any other "more traditional" language. > > Regards, > antonio This construct is called "array" in the SAS language, which I daily use at work. It's pretty convenient: just declare array mySeq n,x,y,...z , these identifiers having been declared beforehand. Then, you can access n as mySeq[1], x as mySeq[2] etc, and mySeq = rhs causes n,x,...z to be assigned with the relevant item in the rhs. A length mismatch would cause an error, but you can disable this so as to ignore assignments that wouldn't make sense. This other feature would be VERY MUCH welcome in Eu. CChris
7. RE: listed subscripting
- Posted by Juergen Luethje <j.lue at gmx.de> Apr 25, 2006
- 474 views
Antonio Alessi wrote: > Juergen Luethje wrote: > > > > Antonio Alessi wrote: > > > > > Juergen Luethje wrote: > > >> .. .. > > > > > >> -- elegant swap: > > >> {a,b} = {b,a} > > >> > > >> -- current swap: > > >> temp = a > > >> a = b > > >> b = temp > > > > > > > > > Hello Juergen, > > > > > > why temp? > > > > > > line = {1, 2} > > > > > > EU plain swap: > > > > > > line = line[2]&line[1] > > > > What I wrote is the classic algorithm for swapping the values of two > > variables, in German called "zyklische Vertauschung" (translates in > > English probably to something like "cyclic exchange"). > > > > In your code not the values of two variables are swapped, but the values > > of two elements of one variable. I was not talking about a variable > > 'line', which is a sequence of two elements, but of two separate > > variable 'a' and 'b'. > > > > Code similar to yours that does what I had described would look like this: > > line = {a, b} > > a = line[2] > > b = line[1] > > > > So your 'line' is a temp variable in disguise. > > I don't consider this way more elegant than the classic "cyclic exchange". > > > > Regards, > > Juergen > > > Sorry Juergen, but on the Euphoria ground I have to contradict what you say. > Perhaps to write {a, b} = {b, a} may look "elegant", but it is not logic: > the {a, b} notation, in lack of oneness is nothing, does not make sense. > If you want to treat that as an entity, you must assign a Label to, > i.e. identify in a unity. Cannot move two things toghether if we don't > put them into the same "box". When you write an expression as > {a, b} = , you introduce the concept of a variable anyhow. > > Fortunately Euphoria makes this possible, bringing in the concept of sequence, > that overlaps without invalidating the independence of the two values; > if we say: > > Label = {a, b} > > in order to handle them, we don't alter the original meaning of variable 'a' > and the separate variable 'b'; simply we can hold them like an ensemble too, > > swapping and even using them for an expression like that of Christian: > > Label = doSomething({n1,n2,s1,s2,s3}) > > even simpler than: > {n1,n2,s1,s2,s3} = doSomething({n1,n2,s1,s2,s3}) > > provided that: > > function doSomething(sequence vars) > }}} <eucode> > return {n1,n2,s1,s2,s3} > </eucode> {{{ > end function > > All that with no need to add thereafter: > > n1 = Label[1] > s1 = Label[3] > > since n1 IS Label[1] already; we have just to change our habit conceiving and > > using L[1] in place of n1, both being able to assume any kind of value. > Other "programming" languages (we do not make literature here) may 'not to > allow' this, as every element of an array can assume a single value, but > cannot BE an unlimited sequence (a world, or individual) in itself. > > So your quote > "In your code not the values of two variables are swapped, > but the values of two elements of one VARIABLE" > > should be replaced with: > > "In your code not the values of two variables are swapped, > but the values of two elements of one SEQUENCE", where > > the values of two variables, and > the values of two elements of one sequence > > become the same thing, so that here we can directly do what you'd like to, > respecting the taste of gracefulness in the form as well as into the idea. > This is the 'soul' of Euphoria and I find it a waste to insist > interpreting and using the way of any other "more traditional" language. Hello Antonio, I'm not sure whether I understand what you want say. However, swapping the values of two separate variables a and b in Euphoria can currently be done e.g. like this:
-- one method sequence temp atom a, b a = 3 b = 7 temp = a a = b b = temp
-- another method sequence temp atom a, b a = 3 b = 7 temp = {a, b} a = temp[2] b = temp[1]
The only thing that I wanted to say is, that I would it consider more elegant, if we were able to achieve the same result by writing <currently no valid eucode> atom a, b a = 3 b = 7 {a, b} = {b, a} </currently no valid eucode> IMHO it would be even more elegant without the curly braces: <currently no valid eucode> atom a, b a = 3 b = 7 a, b = b, a </currently no valid eucode> This is possible e.g. in Lua. Is your point that you do not consider this elegant? Regards, Juergen -- De gustibus non est disputandum.
8. RE: listed subscripting
- Posted by Antonio Alessi <a.admin at myway.it> Apr 25, 2006
- 472 views
Juergen Luethje wrote: > > Hello Antonio, > > I'm not sure whether I understand what you want say. .. .. > > Is your point that you do not consider this elegant? > > Regards, > Juergen > > -- > De gustibus non est disputandum. No Juergen, it it isn't that. But I'm afraid we will meet problems if discussing in one Language other than ours; perhaps in the Latin.. ;) I was just trying to point out some concepts on the basis of Euphoria as the current common ground. Regards antonio