Skip to content

Instantly share code, notes, and snippets.

def f(x):
def g(y):
def h1(z):
nonlocal x,y
x = z
y = 2*z
print(locals())
def h2(z):
print(locals())
return z+y+x
(define (make-simple-generator iterable transformer)
(define (re-entry return)
(define (iter-action element)
(define (escaper new-re-entry)
(set! re-entry new-re-entry)
(return ( transformer element)))
(call-with-current-continuation escaper))
(for-each iter-action iterable)
(return 'Let-it-end!))
@joseanpg
joseanpg / this_and_generators.js
Created March 13, 2011 18:12
About Mozilla Generators
//script type="application/javascript;version=1.7"
function FactorGenMaker(factor) {
let(j=1){for(;;) yield factor*j++};
}
function NullGenMaker() {
for(;;) yield null;
}
//script type="application/javascript;version=1.7"
function GenMaker() {
let(j=1){for(;;) {yield (yield 'Hola '+j);j++}}
}
var gen = GenMaker();
console.log(gen.next()+', the deep yield give-out Hola and give-in undefined');
console.log(gen.next()+', now shallow yield return that undefined');
console.log(gen.next()+', now the deep yield: Hola out, undefined in');
console.log(gen.next()+', now the shallow yield: undefined');
def GenMaker():
j = 1
while True:
yield (yield 'Hola '+str(j))
j = j + 1
gen = GenMaker()
print( gen.__next__())
print( gen.__next__())
print( gen.__next__())
def GenMaker():
j = 1
while True:
yield (yield 'Hola '+str(j))
j = j + 1
gen = GenMaker()
print( gen.send(None))
print( gen.send('Adios'))
print( gen.send(None))
//script type="application/javascript;version=1.7"
function GenMaker() {
let(j=1){for(;;) {yield (yield 'Hola '+j);j++}}
}
var gen = GenMaker();
console.log(gen.next());
console.log(gen.send('Adios'));
console.log(gen.send(null));
console.log(gen.send('Adios'));
var Ajax = (function (){
function AjaxXMLHTTPRequest(){}
AjaxXMLHTTPRequest.prototype = {...};
function AjaxActiveX(){}
AjaxActiveX.prototype = {};
return (typeof window.ActiveXObject === 'undefined') ?
AjaxXMLHTTPRequest:
@joseanpg
joseanpg / gist:935161
Created April 21, 2011 18:18
Modules ( R7RS-Draft 9 March 2011)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Defining a module
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(module (sillymul)
;;The body
(begin
;;Private
@joseanpg
joseanpg / gist:947190
Created April 28, 2011 20:02
Memoizing Event Register Functions
/***********************************************************************
Initial Version
************************************************************************/
var eventOn = function(type,fn){ win.addEventListener ?
win.addEventListener(type,fn,false) :
win.attachEvent('on'+type,fn)},
eventOff = function(type,fn){ win.removeEventListener ?
win.removeEventListener(type,fn,false) :
win.detachEvent('on'+type,fn)},