Skip to content

Instantly share code, notes, and snippets.

/**
* This library extends standard "Object.create" method
* with ability to create object with specified class.
*
* Also it defines concept of a meta-constructor which
* creates other construcotrs, which in turn create
* object with specified class.
*
* Currently, non-standard __proto__ extension
* is used to inject the needed prototype for arrays.
/**
* This library defines a new style ES objects
* which support delegation based mixins. A mixin
* chain is stored in the internal [[Mixin]] property.
*
* Used features: Harmony (ES6) proxies.
*
* Tested in FF4 beta.
*
* @author Dmitry A. Soshnikov <dmitry.soshnikov@gmail.com>
/**
* This library defines magic properties and methods
* for objects. Generic hooks are: __get__, __set__,
* __delete__, __count__, __call__, __construct__,
* __noSuchProperty__ and __noSuchMethod__.
*
* Used features: Harmony (ES6) proxies.
*
* Tested in FF4 beta.
*
/**
* Console object for BESEN
* @author Dmitry A. Soshnikov <dmitry.soshnikov@gmail.com>
*/
(function initConsole(global) {
// helpers
var getClass = Object.prototype.toString;
var timeMap = {};
// 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 / static-dynamic-scope.pl
Created November 12, 2010 22:05
Static and dynamic scope in Perl
# Lexical and dynamic scopes in Perl;
# Static (lexical) scope uses model of
# environments with frames; dynamic scope
# uses single global var frame.
$a = 0;
sub foo {
return $a;
}
sub staticScope {
@DmitrySoshnikov
DmitrySoshnikov / python-closures.py
Created November 15, 2010 12:03
Understanding Python's closures
# "Understanding Python's closures".
#
# Tested in Python 3.1.2
#
# General points:
#
# 1. Closured lexical environments are stored
# in the property __closure__ of a function
#
# 2. If a function does not use free variables
@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