2,047 karma · joined July 19, 2011
DataType = union({ 'type1': ['field1', 'field2'], 'type2': ['field3'] })
DataType.type1(val1, val2)
DataType.type2(val3)
# pretend syntax
case datum:
DataType.type1(a, b):
doSomethingWith(a, b)
DataType.type2(c):
doSomethingWith(c)hey look, a page redirect :D
As far as APIs go, one way would just be to return a list always. The DOM, afaik, returns a special NodeList thing that isn't even an array. ( https://developer.mozilla.org/en-US/docs/Web/API/NodeList?re... ). What's the actual issue with using wrappers?
If multiple elements of the same tag exist, a proper
array of elements is returned otherwise an Element is
returned.
STAHP. Please don't make the type of the return value dependent on runtime state. This is exactly why jQuery created its own array-like wrapper (which subclasses Array, fwiw).Well, partly. Code is actually a piece of writing intended for two very different audiences - one human, one machine. The machine doesn't actually care how long your lines are - this is an optimization for humans.
And I hear you about fixing the tools. Wouldn't it be easy if everyone used the same editor. But alas, this isn't a problem with the tools. It's an inherent limitation of text. That "figuring out visual structure" bit only works if your editor deeply understands your language. And different editors understand languages to different degrees and in different ways.
They say parsing is a solved problem, but I dare you to parse Ruby or Python correctly.
function Tuple(/* args... */) {
var args = arguments;
this.unpack = function(fn) {
return fn.apply(null, args);
}
}The js and coffeescript ways of handling this seem both to come down to the assignment operator being used for both creating bindings and mutating them, which gets confusing, and causes the failure modes you described.
The built-in features usually try to solve the general case, rather than focusing on specific use-cases. For example, in python you have iterators, which make it easy to have a block of code that is run multiple times with different bindings. In Ruby, you have block syntax, which solves the more general problem of "let me pass this anonymous block of code to this function", and they built iterators on top of that.
Basically we created a mortgage system that only works as long as property values continue to rise, which created a lot of political will behind "improvement" measures like eliminating public housing, like we did in the early 80s.
(see http://www.wraphome.org/downloads/without_housing.pdf [pdf] for a fascinating study on the origins of modern homelessness)
I'm doing some experiments with cooperative housing and income-sharing right now, which slightly mitigates my contribution to gentrification, but something else is needed, and I'm not sure what.