__NoSuchMethod__
Because I always forget what it's called. Surely 'method_missing' is more obvious. (__NoSuchMethod__ is the javascript function that does the same thing as method_missing in Ruby)
Stuff I (Tiest Vilee) am interested in. I have moved my holiday offerings over to http://toastsholiday.blogspot.com/ for now. And here's my home page
{ my_alert: alert_string | alert(alert_string); }
[map: my_alert onto: \["a","b","c"]]
[node addEvent("click", {event| alert('whatever'); }) ]
function my_alert(alertString) { alert(alertString); }
map$onto(alertString, ["a","b","c"]);
node.addEvent("click", function(event){ alert('whatever'); });
lisp(
reduce(
if$(true, add, sub),
map( add_one, [1,2,3])
)
);
// prints 9
function add_one(a_value) {
return add(1, a_value);
}
function LispExpression(originalExpression, expression_arguments) {
this.originalExpression = originalExpression;
this.expression_arguments = expression_arguments;
}
LispExpression.prototype.evaluate = function evaluate(){
return this.originalExpression.apply(null, this.expression_arguments);
}
function lisp(lispExpression){
if( lispExpression instanceof LispExpression) {
return lispExpression.evaluate();
}
return lispExpression;
}
function lisp_function(the_function, arguments) {
return new LispExpression(
the_function,
arguments
);
}
function reduce(reducer, argument_list) {
return lisp_function(
function reduce() {
if(arguments.length > 0) {
var total = null;
reducer = lisp(reducer);
argument_list = lisp(argument_list);
for( var i=0; i<argument_list.length; i++) {
total = lisp(reducer(total, argument_list[i]));
}
return total;
}
return null;
},
arguments
);
}
function map(mapper, argument_list) {
return lisp_function(
function map() {
if(arguments.length > 1) {
var result = [];
for( var i=0; i<argument_list.length; i++) {
result.push( lisp(mapper(argument_list[i])) );
}
return result;
}
return null;
},
arguments
);
}
function if$() {
return lisp_function(
function(condition, trueExpression, falseExpression) {
if( lisp(condition) ) {
return lisp( trueExpression );
} else if(falseExpression) {
return lisp( falseExpression );
}
return null;
},
arguments);
}
function seq() {
return lisp_function(
function () {
var last_argument = arguments.length-1;
for( var i=0; i<last_argument; i++) {
lisp(arguments[i]);
}
return lisp(arguments[last_argument]);
},
arguments
);
}
function add() {
return reduce(
function add(running_total, value){
return running_total == null ? lisp(value) : running_total + lisp(value);
},
arguments);
}
function sub() {
return reduce(
function add(running_total, value){
return running_total == null ? lisp(value) : running_total - lisp(value);
},
arguments);
}
function print() {
return reduce(
function print(running_total, value){
out.println(lisp(value));
return null;
},
arguments);
}
function printAndReturn(aString, aValue) {
return seq(print(aString), aValue);
}
lisp(if$(false, print("got true"), print("got false")));
// got false
// null
function additup() {
return add(
1,
if$(
false,
printAndReturn("two", 2),
printAndReturn("three",3)),
4);
}
lisp(print(1,2,"fkfkfk"));
// 1
// 2
// fkfkfk
lisp( additup() );
// three
// 8
function add_one(a_value) {
return add(1, a_value);
}
lisp( map(add_one, [1,2,3]) );
// 2,3,4
lisp(
reduce(
if$(true, add, sub),
map( add_one, [1,2,3])
)
);
// 9