This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From JavaScript The Good Parts | |
String.prototype.deentityify = (function () { | |
var entity = { | |
quot: '"', | |
lt: '<', | |
gt: '>' | |
}; | |
return function ( ) { | |
return this.replace(/&([^&;]+);/g, function (a, b) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From underscorejs.org documentation | |
var stooges = [ | |
{ | |
name : 'curly', | |
age : 25 | |
}, | |
{ | |
name : 'moe', | |
age : 21 | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
father(zeb, john_boy_sr). | |
father(john_boy_sr, john_boy_jr). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Multiple rules with the same signature: | |
ancestor(X, Y) :- father(X, Y). % base case first | |
ancestor(X, Y) :- father(X, Z), ancestor(Z, Y). % we recursively call ancestor | |
% Alternatively, we can write it this way using a logical OR: | |
ancestor(X, Y) :- father(X, Y); % we use a semicolon to distinguish between clauses | |
father(X, Z), ancestor(Z, Y). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% testing the first clause | |
ancestor(zeb, john_boy_sr). % yes | |
ancestor(john_boy_sr, zeb). % no | |
% testing the second clause | |
ancestor(zeb, john_boy_jr). % yes | |
% let's ask, "Who is an ancestor of zeb" | |
ancestor(zeb, Who). % john_boy_sr ; john_boy_jr | |
% "Who is john_boy_jr an ancestor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Let's define a member function to tell if x is a member of ary | |
* | |
* def member(x, ary) | |
* return false if ary == [] | |
* return true if ary.first == x | |
* member(x, ary[1...ary.size]) | |
* end | |
* | |
* In Prolog: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************* | |
Inverter | |
_______ | |
| | | |
A-| NOT |-OUT | |
|_____| | |
*************/ | |
% A OUT | |
not(0, 1 ). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var prop, x; | |
var animal = { | |
type: 'Missing No.', | |
say: function (phrase) { | |
return this.type + ' says hello.'; | |
} | |
}; | |
var dog = Object.create(animal); | |
dog.type = 'Dog'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> 1 + 1 | |
res0: Int = 2 | |
scala> (1).+(1) | |
res1: Int = 2 | |
scala> 2 + 5 * 8 | |
res2: Int = 42 | |
scala> (2).+((5).*(8)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> "foo" + 4 | |
res0: String = foo4 | |
scala> 4 + "foo" | |
res1: String = 4foo | |
scala> 4 + "2.0" | |
res2: String = 42.0 | |
scala> 2 * "21" |
OlderNewer