3 ms·
Honestly it's pretty strange that assignment has a directionality.
by phendrenad2 6y ago
Honestly it's pretty strange that assignment has a directionality.
- sjwright 6y agoIt has to though. X = Y; // what should change?
- edejong 6y agoX_{t+1} = Y_t Doesn’t have to.
- dragonwriter 6y agoYou say nothing has to change, but what you write to support it is explicitly that X changes based on Y, since you are just making the time sequence explicit in the code instead of implicit in the operator syntax.
- fernmyth 6y agoIn a declarative language, nothing.
- pron 6y agoBut computation has an intrinsic directionality. If you have two expressions a, and b, and you want to unify them in a declarative language as a = b, then having an unknown subterm in one or the other can make the computation have a completely different complexity, making one direction easy and the other intractable. The P vs. NP problem is a famous question exactly about this directionality. Here's a simple example (in a declarative language that allows non-terminating computation; in a total language similar examples can be given, except "impossible" means intractable rather than non-computable, which, for all intents and purposes is the same): X = terminates?(P(1)) If X is known then finding a P is easy; if vice-versa, finding X is possibly impossible.
- phendrenad2 6y agoOh, I meant in the special case of something that can only be an r-value on the left such, such as a constant or function result. But yeah, it could still confuse newbies, because the problem is not understand that it's procedural.
- dragonwriter 6y agoWhichever isn't currently bound to a concrete value, or neither (except that they become bound to each other) if neither is; if both are, it's an error should occur, since they cannot be unified.
- ISL 6y agoThe primary difficulty that I had was the overloaded usage of the "=" character. I had a clear mathematical understanding that the "=" symbol was symmetric, that 5 = x and x = 5 were equivalent. That someone could abuse that notion so brazenly was the source of my frustration. Some languages use directional notation for assignment (see [1]): 5 -> x is clear. [1] https://en.wikipedia.org/wiki/Assignment_(computer_science)#Notation https://en.wikipedia.org/wiki/Assignment_(computer_science)#...
- teddyh 6y agoPascal and related languages use the notation x := 5 I have heard that this was to mimic (in ASCII) the look of an arrow: x ⇐ 5
- Wowfunhappy 6y agoMy first thought was, if they wanted an arrow why wouldn’t they go with: x <= 5 But of course, that means “less than or equal to”. You could do: x <- 5 But I suppose the mere presence of the “less than” symbol is weird in context. (Although, maybe not inherently weirder than using the equals sign for something other than equality?) Perhaps we would have been better off if we’d all just agreed early on, that @, #, or ~ should represent assignment.
- teddyh 6y agoThe original 1963 version of ASCII had a left-arrow (←) symbol, but it was replaced with underscore (_) in the 1965 version.
- magicalhippo 6y agoOne of the reasons I still quite like Pascal.
- Wowfunhappy 6y agoI know it's more verbose, but I'm deeply fond of Applescript's syntax for assigning variables: set x to 5