4 ms·
You certainly could solve that with a symbol, I suppose, but that's a bit like doing a word-for-word translation of 'it's raining cats and dogs' into a foreign
by msbarnett 16y ago
You certainly could solve that with a symbol, I suppose, but that's a bit like doing a word-for-word translation of 'it's raining cats and dogs' into a foreign language. Better to translate to the local idiom than to try to blindly write Fortran in any language, as the saying goes.
So, for instance, you might solve it with:
result = case
when baz>10 then foo
else bar
end
This is synthetic, of course. If the goal is to pass around methods, there are lambdas and codeblocks that can be passed around and may fit the problem more naturally than sending yourself a symbol as a message.
- spicyj 16y agoOr a slightly more direct translation is: result = if baz > 10 foo else bar end
- Dylan16807 16y agoresult = case when baz>10 then foo else bar end is a translation of if baz>10: result = self.foo() else: result = self.bar() while result = if baz > 10 foo else bar end is a translation of result = self.foo() if baz>10 else self.bar() It's true that some things have to be changed when translating, but you can't ignore the deliberate structure of the original. Let's say I want to look at how inter-sentence objects work in two languages. I give you the phrase: "Raining cats and dogs. This is what the weather is like." You can't translate it as if it said "It's raining cats and dogs" without losing the basis of comparison entirely.