Skip to content

Instantly share code, notes, and snippets.

View es3-set-environment-test.js
/**
* Apply a function in needed environment.
* Firefox only, educational purpose only.
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
*/
Function.prototype.setEnvironment = function(environment) {
with (environment) {
return eval(uneval(this));
}
View pattern-matching.md

Pattern Matching

In this article we briefly describe the generic topic of pattern matching in programming languages. We'll see that this powerful technique is present in our every day programming, even if we may not notice it.

Matching

A matching is a process of checking whether one thing has the same or similar representation as another thing.

There are two basic matches:

View union-quick-union.js
/**
* "Is connected?"
*
* Dynamic connectivity issue.
*
* 1 2: not connected
* 1--2: connected
* 1--2--3: 1 and 3 are connected through 2
*
* This implements quick union operation, but the find
@DmitrySoshnikov
DmitrySoshnikov / stack-vm-recursion.js
Last active Aug 29, 2015
Educational Stack-based VM with recursion example
View stack-vm-recursion.js
/**
* Educational Stack-based VM.
*
* See also:
* - A simplified example without recursion: https://gist.github.com/DmitrySoshnikov/76e1cfb930df8d36145c
* - Register-based VM example: https://gist.github.com/DmitrySoshnikov/6407781
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* http://dmitrysoshnikov.com
* MIT Stye License (C) 2015
View shadow-hoisting-tdz.md

1. A system without hoisting

An example of Scheme program without hoisting:

(define x 10)     ; global `x`
(print x)         ; 10

((lambda ()
    (print x)     ; still 10, not shadowed yet
View ES7.StringTrim.md

ES7 String trim functions

String.prototype.trim ( )

Return result of StringTrim abstract operation passing this value as thisArg, and TrimBoth as the type.

String.prototype.trimRight ( )

Return result of StringTrim abstract operation passing this value as thisArg, and TrimRight as the type.

@DmitrySoshnikov
DmitrySoshnikov / AST-printer.js
Last active Aug 29, 2015
AST Printer / Code generator
View AST-printer.js
/**
* = AST printer =
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style License
*
* Once we have finished operating on our AST, we need to generate the
* code back from that (possibly transformed) AST.
*
* We choose a very simple AST format here, which we used in the
View es2015-callable.js
/**
* Callable objects in ES2015.
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style License
*/
class Callable extends Function {
constructor() {
super('(' + Callable.prototype.__call__ + ')();');
return this.bind(this);
View evaluation strategy.cpp
/* by Dmitry A. Soshnikov */
#include "stdafx.h"
#include <iostream>
struct Object {
int x;
int y;
};
View object-proto-aliases.js
/**
* Aliases and additional "sugar"
* 2010-04-15
* @author Dmitry A. Soshnikov
*/
(function () {
var
$break = {},
hasOwn = Object.prototype.hasOwnProperty;