Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://rawgithub.com/freethenation/unify.js/master/lib/unify.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  
</body>
</html>
 
//var unify = require('unify');
var arrayToString = function(arr){
  return "[" + arr.join() + "]";
};
var variable = unify.variable;
var rectangle = unify.box({
  topLeft:[0,0],
  topRight:[1,0],
  bottomLeft:[0,1],
  bottomRight:[1,1]
});
var extractor = unify.box({
  topLeft:variable("topLeft",unify.isNum),
  topRight:variable("topRight",unify.isNum),
  bottomLeft:variable("bottomLeft",unify.isNum),
  bottomRight:variable("bottomRight",unify.isNum)
});
//extract the corners of the rectangle
if (extractor.unify(rectangle)) {
  console.log("topLeft: " + arrayToString(extractor.get("topLeft")));
  console.log("topRight: " + arrayToString(extractor.get("topRight")));
  console.log("bottomLeft: " + arrayToString(extractor.get("bottomLeft")));
  console.log("bottomRight: " + arrayToString(extractor.get("bottomRight")));
}
else {
  console.log("Somthing went wrong. Unification failed!");
}
extractor.rollback();
//The above code will print the following to the console
//"topLeft: [0,0]"
//"topRight: [1,0]"
//"bottomLeft: [0,1]"
//"bottomRight: [1,1]"
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers