Skip to content

Instantly share code, notes, and snippets.

@DmitrySoshnikov
DmitrySoshnikov / new-languages.md
Created February 3, 2011 09:21
Why do we need new languages?

"In our study of program design, we have seen that expert programmers control the complexity of their designs with the same general techniques used by designers of all complex systems. They combine primitive elements to form compound objects, they abstract compound objects to form higher-level building blocks, and they preserve modularity by adopting appropriate large-scale views of system structure. In illustrating these techniques, we have used Lisp as a language for describing processes and for constructing computational data objects and processes to model complex phenomena in the real world.

However, as we confront increasingly complex problems, we will find that Lisp, or indeed any fixed programming language, is not sufficient for our needs. *We must constantly turn

@DmitrySoshnikov
DmitrySoshnikov / nonlocal.py
Created February 8, 2011 11:43
Modification of external vars in Python
# for closured vars
# we may use `nonlocal` keyword
def foo():
a = 10
b = 20
def bar():
nonlocal b # use parent "b"
@DmitrySoshnikov
DmitrySoshnikov / map-parseInt.js
Created February 10, 2011 20:01
Harmful mapping (extra args for parseInt)
var a = ["1", "2", "3"];
// try to get mapped array
// containing numbers
console.log(a.map(parseInt)); // but get [1, NaN, NaN] !
// Explanation:
// per step 8.c.ii of the 15.4.4.9
@DmitrySoshnikov
DmitrySoshnikov / harmony-modules.js
Created February 11, 2011 14:44
Quick test on Windows of Harmony Modules from Narcissus
var exports = this;
function require(module) {
load("lib/" + module.substr(2) + ".js");
}
require("./definitions");
require("./lexer");
require("./parser");
require("./decompiler");
@DmitrySoshnikov
DmitrySoshnikov / harmony-iterator.js
Created March 11, 2011 08:38
harmony-iterators.js
//
// by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
// MIT Style License
// see also: http://wiki.ecmascript.org/doku.php?id=strawman:iterators
//
// ---------------------------------------
// 1. Iteration via for-in loop
// ---------------------------------------
@DmitrySoshnikov
DmitrySoshnikov / infinite-objects-generator.js
Created March 13, 2011 14:32
Infinite objects generator
/**
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*/
// infinite objects generator
let g = new function () {
while (true) {
yield;
}
};
@DmitrySoshnikov
DmitrySoshnikov / harmony-modules-import.js
Created March 24, 2011 18:00
Harmony modules import
/**
* Test for module imports
* Tested in Narcissus
* by Dmitry Soshnikov
*/
module M {
export var x = 10;
export var y = 20;
}
main(_Arg) ->
HTML = {p, [{text, "test"}, {class, "bold"}], [
{span, [{text, "value"}, {class, "bold"}], [
{span, [{text, "hi"}, {class, "bold"}], []}
]}
]},
Texts = get_text(HTML, []),
% ["value","test"]
main([]) ->
%% Given the parsed HTML tree in the following format:
%%
%% Types HTML = [Element]
%% Element = {Tag, [Attribute], [Element | Text]}
%% Tag = atom() % e.g. 'a', 'pre', 'p'
%% Attribute = {Name, Value}
%% Name = atom()
%% Value = string()
$coroutine = (func) -> ->
gen = func(arguments...)
gen.next()
gen
grep = $coroutine (pattern) ->
console.log "Looking for #{pattern}"
while true
line = yield
if line.indexOf pattern != -1