juan_gandhi: (Default)
2020-05-29 03:04 pm
Entry tags:

the code I teach now

const iterate = f => z => pair(z, () => iterate(f)(f(z)));

const integers = iterate(n => n+1)(0);
juan_gandhi: (Default)
2020-01-29 10:58 pm
Entry tags:

More SICP wisdoms

 

70 Observe that, for any two streams, there is in general more than one acceptable order of interleaving. Thus, technically, ‘merge’ is a relation rather than a function—the answer is not a deterministic function of the inputs. We already mentioned (footnote 38 ) that nondeterminism is essential when dealing with concurrency. The merge relation illustrates the same essential nondeterminism, from the functional perspective.
 

71 The object model approximates the world by dividing it into separate pieces. The functional model does not modularize along object boundaries. The object model is useful when the unshared state of the ‘objects’ is much larger than the state that they share. An example of a place where the object viewpoint fails is quantum mechanics, where thinking of things as individual particles leads to paradoxes and confusions. Unifying the object view with the functional view may have little to do with programming, but rather with fundamental epistemological issues.

juan_gandhi: (Default)
2020-01-28 08:28 am
Entry tags:

еще бага в sicp js

См определение merge на схеме; но в джаваскриптовом тексте ошибка.

Если мержируем стрим с самим собой, то просто зависает программа.

Я, короче, предложил им пофиксить эту функцию в джаваскриптовой версии.

Вот тут вот, например.

Бага в том, что если два потока выдали одно и то же значение, то мы его вообще игнорируем и бежим дальше. Соответственно, если делаем merge(integers, integers), и берем его хотя бы второй элемент, то зависнет.

НУ ФИГНЯ ЖЕ. 

Сейчас протестировал на их же упражнении, чуточку модифицировав ответ. Фигня получается.

У основоположников не фигня.

Посмотрим.

https://github.com/source-academy/sicp/pull/194