Talk:This=That

Queries
-- Smjg 11:50, 22 August 2009 (UTC)
 * 1) "The variable names can be anything including special names."  Does this mean you can redefine any reserved word or numeric literal, and put symbols, spaces, newlines, control characters, whatever you want in a variable name?
 * 2) Where is the line drawn between plus meaning arithmetic addition and plus meaning string concatenation?  (What exactly defines what's a number and what's a string?)
 * 3) Going by the 99 bottles of beer example, it would appear that variables in rvalues are sometimes by value and sometimes by reference.  What exactly is the rule on this?
 * 4) Can a variable and a loop have the same name?
 * 5) What is an if loop, anyway?

Answers

 * 1) The variable names should be limited to the printable ASCII characters (32-126) for the sake of clarity and ease, but you could potentially use control characters if you so choose.
 * 2) If both of the values are numerals, then the plus is used for arithmetic, but if one or the other value is not entirely numeral the plus acts by string concatenation.
 * 3) You can use either.  If the value referenced is a variable name, then the variable's value is used, otherwise the value given is used.  This means that using numbers as variable names is probably not a smart idea.
 * 4) Yes, but naming them seperately is preferable for clarity reasons.
 * 5) An if loop executes once if the condition is true, while a while loop executes as long as the condition is true when the loop ends.  Technically an if loop is not actually a loop because it does not loop, but is similar to the if... then... statement in many other non-esoteric languages.  This is probably what was confusing you.

Hopefully I've successfully answered your questions. PuzzleHunter84 22:11, 22 August 2009 (UTC)

I see ... but still: a=99 b= bottles of beer on the wall. c=a plus b d=a minus 42 a=98
 * 1) Allowing control characters would seem to lead to ambiguity.  OK, so maybe it's unambiguous as long as   cannot be in a variable name.
 * 2) I thought so ... but for this to be meaningful, we need a complete spec of number syntax.  Are negative numbers allowed?  Decimals?  What about scientific notation?  And does whitespace around the number change things?
 * 3) Let me clarify.  Given
 * how is one to know whether b is now "99 bottles of beer on the wall" or "98 bottles of beer on the wall", and whether d is now 57 or 56? If followed by

a=d plus 3
 * then will this expand to

a=a minus 42 plus 3 a=d plus 3 minus 42 plus 3
 * and so on indefinitely, or will some unspecified rule trigger a value assignment to happen instead? -- Smjg 20:26, 28 August 2009 (UTC)

More Answers
a=5 b=5 c=a plus b
 * 1)   cannot be used in variable names or values, correct.
 * 2) For clarification on number syntax: only signed integers (- indicating negative numbers) should be used and   is used for integer division.  Any non-numeral character other than - (even whitespace) would cause the value to become a string. For example
 * would result in c being 10, but

a=5 b=5 c=a plus b
 * would result in c being the string "55 " without the quotes.

a=99 b= bottles of beer on the wall. c=a plus b d=a minus 42 a=98 a=d plus 3
 * 1) When a variable is given a new value, that value is used in place of the old value in math, string concatenation, etc. to decide other values.  In your example
 * At line 1, a is set to 99. At line 2, b is set to the string " bottles of beer on the wall.  " without the quotes.  At line 3, c is set to a plus b, which is currently the string "99 bottles of beer on the wall.  " without the quotes.  At line 4, d is set to a minus 42, which is currently 57.  At line 5, a is set to the new value of 98; this changes the value of c to the string "98 bottles of beer on the wall.  " without the quotes and the value of d to 56.  At line 6, a is set to the new value of d plus 3 which is currently 59.  In another case where you have something like this

a=10 a=a plus 5
 * In this case, a would be set to 10. Then a would be set to the new value that is a plus 5.  For this the old value of a is used to determine the new value, which would be 15.  A variable is only set once for each time it appears as the variable name (except in the case of specials such as print, input, and loops).

Hope this helped with clarification.

Damn it all. That last 1 should be a 3. --PuzzleHunter84 00:29, 30 August 2009 (UTC)


 * So variables  and   hold the expressions   and   respectively.  When   is assigned , it expands to  , but since this means   is now defined in terms of itself, the   in that expression is replaced with its existing value.  Have I got the right idea?


 * Moreover, if I did something like

a=42 d=69 a=a plus d d=105
 * then what would happen? Does   now equal 111, 147 or what? -- Smjg 01:18, 30 August 2009 (UTC)

Yes, you have the right idea. In the last example,  would now equal a plus d, which would be 42 plus 105 or 147. Once the value of  is changed from 69 to 105,   changes its value to act as if d had always held a value of 105... if that makes any sense at all. I doubt anything like that will pop up in practical programs but you never know. -- PuzzleHunter84 01:30, 30 August 2009 (UTC)

The construct above is similar to all variables acting as more of a pointer/reference than an actual "variable" but still... PuzzleHunter84


 * So once line 3 has been executed, the expression stored as  is  . -- Smjg 18:04, 12 September 2010 (UTC)


 * Essentially PuzzleHunter84