Author |
Message |
Dragon20942

|
Posted: Fri Jan 21, 2011 4:54 pm Post subject: Variable Concatenation |
|
|
I'm just wondering if one can concatentate variables in Turing.
say if I wanted to cycle through wave1 - wave2 with a for loop, could I somehow
Turing: |
var wave1 : array 0..4 of int := (1,2,3,4)
var wave2 : array 0..4 of int := (4,3,2,1)
for i 1..2
for j 0..4
put wave+i (j) %puts variables in wave1 before putting variables in wave2
end for
end for
|
? |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: Fri Jan 21, 2011 4:58 pm Post subject: RE:Variable Concatenation |
|
|
Quote:
puts variables in wave1 before putting variables in wave2
I don't understand what you are trying to ask. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
DemonWasp
|
Posted: Fri Jan 21, 2011 5:15 pm Post subject: RE:Variable Concatenation |
|
|
What you're asking about is typically called "variable variables", and while this feature occurs in a lot of scripting languages and "build languages", it's not common in "programming languages", like Turing. Turing does not possess this feature.
A "variable variable" is a (string) variable that contains the name of another symbol, which can then be evaluated to the value of the named variable. An example (looks like Turing but is NOT valid Turing):
code: |
var variableName : string := "otherVariable"
var otherVariable : array 1..3 of int := init ( 1, 2, 3 )
put $$variableName
|
Your example could be rewritten as:
Turing: |
var wave : array 0..1, array 0..4 of int
% init array contents...
for i : 1..2
for j : 0..4
put wave ( (i+j) mod 2, j )
end for
end for
|
|
|
|
|
|
 |
Dragon20942

|
Posted: Fri Jan 21, 2011 5:43 pm Post subject: RE:Variable Concatenation |
|
|
I was just asking if wave+i could be used as a concatenated variable with i still a functioning variable, thus outputting the values in wave1 and then outputting the varibles in wave2.
Oh and I made an error in declaring the arrays whoops!
Im saddened by a lack of variable concatenation, but am wondering how there can be two arrays in one variable. |
|
|
|
|
 |
Tony

|
Posted: Fri Jan 21, 2011 5:58 pm Post subject: RE:Variable Concatenation |
|
|
If you read the docs for array, you'll see that "array min..max of TYPE" is a TYPE. By extension, you can have an array of arrays of ints. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
Dragon20942

|
Posted: Fri Jan 21, 2011 6:54 pm Post subject: RE:Variable Concatenation |
|
|
Ok, so each element in the "first array" has a "second array" in it, all of it being in one variable? That is interesting.
Is record the only way to stuff more than one array into another? |
|
|
|
|
 |
Insectoid

|
Posted: Fri Jan 21, 2011 6:58 pm Post subject: RE:Variable Concatenation |
|
|
I record is convenient for storing multiple related variables of different types in an organized manner. Your program should be fine with a 2D array. |
|
|
|
|
 |
Dragon20942

|
Posted: Fri Jan 21, 2011 8:43 pm Post subject: RE:Variable Concatenation |
|
|
Ok I was just wondering because I had originally planned to do variable concatenation, but ended up doing records instead. My program has since become a whole lot more complicated and anything other than a record would have made it less efficient. "wave" now has 14 arrays and 2 arrays of arrays within it. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: Sat Jan 22, 2011 1:05 pm Post subject: Re: RE:Variable Concatenation |
|
|
Dragon20942 @ Fri Jan 21, 2011 8:43 pm wrote: variable concatenation
You guys might get a kick out of this
code: |
($=[$=[]][(__=!$+$)[_=-~-~-~$]+({}+$)[_/_]+($$=($_=!''+$)[_/_]+$_[+$])])()[__[_/_]+__[_+~$]+$_[_]+$$](_/_)
|
(add "javascript:" at the start and paste into the address bar to run)
with explanation at http://adamcecc.blogspot.com/2011/01/javascript.html |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
TokenHerbz

|
Posted: Sat Jan 22, 2011 4:56 pm Post subject: RE:Variable Concatenation |
|
|
thats awesome tony |
|
|
|
|
 |
|