Skip to content

Instantly share code, notes, and snippets.

// lambda lifting (http://en.wikipedia.org/wiki/Lambda_lifting)
// in GNU C; use inner functions which are not closures
// of course, but have access to free variables
//
// by Dmitry A. Soshnikov
#include <stdio.h>
// a pointer to a function type
typedef int (*funcPtr)(int);
@DmitrySoshnikov
DmitrySoshnikov / short-lambda.js
Created November 22, 2010 15:17
Short lambda
/**
* Short notation for expression funargs - λ
* (not for production use, but just for fun,
* since closures are not supported -> only
* operations on passed argument "x")
*
* by Dmitry A. Soshnikov
*/
function λ(code) {
@DmitrySoshnikov
DmitrySoshnikov / no-closure-eval.py
Created December 9, 2010 08:32
No closure for unused vars, even with eval
# Python does not save not used bindings in
# the closured environment. However, even
# `eval` doesn't help to save them.
#
# In contrast, ECMAScript having environments
# frames, normaly find variable "x", see
# the same ES example here: https://gist.github.com/734485
#
# by Dmitry A. Soshnikov
#
@DmitrySoshnikov
DmitrySoshnikov / closure-with-eval.js
Created December 9, 2010 08:33
ECMAScript closures all environment frames
/**
* ECMAScript closures all environment frames
* (by the spec), so closured "x" variable is
* available in the dynamic `eval`.
*
* This example is made to show the difference
* of the Python's closures implementation,
* see it here: https://gist.github.com/734482
*
* by Dmitry A. Soshnikov
@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;
}