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 variable = unify.variable;
var validRectangle = unify.box({
  topLeft:[0,0],
  topRight:[1,0],
  bottomLeft:[0,1],
  bottomRight:[1,1]
});
var invalidRectangle = unify.box({
  topLeft:[0], //This is invalid there are not two coordinates!
  topRight:[1,0],
  bottomLeft:[0,1],
  bottomRight:[1,1]
});
var rectangleValidator = unify.box({
  topLeft:[variable("_",unify.isNum),variable("_",unify.isNum)],
  topRight:[variable("_",unify.isNum),variable("_",unify.isNum)],
  bottomLeft:[variable("_",unify.isNum),variable("_",unify.isNum)],
  bottomRight:[variable("_",unify.isNum),variable("_",unify.isNum)]
});
//Validate validRectangle
if (rectangleValidator.unify(validRectangle)) {
  console.log("validRectangle is valid!");
}
else {
  console.log("validRectangle is invalid!");
}
//We need to rollback the unification before we can validate agian
rectangleValidator.rollback();
//Validate invalidRectangle
if (rectangleValidator.unify(invalidRectangle)) {
  console.log("invalidRectangle is valid!");
}
else {
  console.log("invalidRectangle is invalid!");
}
rectangleValidator.rollback();
//The above code will print the following to the console
//validRectangle is valid!
//invalidRectangle is invalid!
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers