This is a human-programmed library required by the code generated by the AI.
// --------------- various ---------------------
function smallLetterToNumber(ch)
{
return positionInRange(ch, 'a', 'z');
}
function bigLetterToNumber(ch)
{
return positionInRange(ch, 'A', 'Z');
}
function digitToNumber(ch)
{
return positionInRange(ch, '0', '9')-1;
}
function numberToSmallLetter(number)
{
return elementFromRange(number, 'a', 'z');
}
function numberToBigLetter(number)
{
return elementFromRange(number, 'A', 'Z');
}
function numberToDigit(number)
{
return elementFromRange(number+1, '0', '9');
}
function positionInRange(ch, from, to) {
var ascii = ch.charCodeAt();
if ( ascii < from.charCodeAt() || ascii > to.charCodeAt() )
throw ("Character '" + ch + "' out of range '" + from + "'-'" + to + "'");
return ascii - from.charCodeAt()+1;
}
function elementFromRange(number, from, to) {
if ( number < 1 || number > (to.charCodeAt() - from.charCodeAt()+1) )
throw ("Number '" + number + "' out of range '" + from + "'-'" + to + "'");
return String.fromCharCode (number - 1 + from.charCodeAt());
}
// --------------- arithmetic --------------------
function plus(a, b) {
return a+b;
}
function minus(a, b) {
return a-b;
}
function minusPlus(a, b) {
return -a+b;
}
function multiply(a, b) {
return a*b;
}
function divide(a, b) {
return a/b;
}
function divideMultiply(a, b) {
return 1/a*b;
}
// ---------- built in ------------------------------
function listGen(size, gen, init) {
var result = (init === undefined ? [] : init.slice());
for ( var i=result.length; i<size; i++ )
{
if ( gen.length == 0 )
result[i] = gen();
else if ( gen.length == 1 )
result[i] = gen(i);
else if ( gen.length == 2 )
result[i] = gen(i, result);
}
return result;
}
function evaluate(f)
{
if ( f instanceof Array )
{
var result = [];
for ( var i=0; i<f.length; i++)
result.push( f[i]() );
return result;
}
else
return f();
}
function seqOfStruct(){
var result = [];
var rowsCount = arguments[0].length
for ( var i=0; i<rowsCount; i++)
{
var row = []
for ( var j=0; j<arguments.length; j++)
{
row.push(arguments[j][i]);
}
result.push(row);
}
return result;
}
function curryFunc(func, args)
{
return function() {
return func.apply(this, args);
}
}
function seqOfOperation(args, operation) {
var func = args[0];
var result = [];
var rowsCount = args[0].length;
for ( var i=0; i<rowsCount; i++)
{
var callArgs = []
var lenn = args.length;
for ( var j=1; j<args.length; j++)
{
callArgs.push(args[j][i]);
}
result.push(operation(func[i], callArgs));
}
return result;
}
function evalSeqOfCall() {
return seqOfOperation(arguments, function(func, callArgs) {
return func.apply(this, callArgs);
});
}
function seqOfCall() {
return seqOfOperation(arguments, function(func, callArgs) {
return curryFunc(func, callArgs);
});
}
function seqOfCurry() {
return seqOfOperation(arguments, function(func, callArgs) {
var innerFunc = curryFunc(func, callArgs);
return function() {
return innerFunc;
}
});
}
function seqOfQuote(list) {
var result = [];
for ( var i=0; i<list.length; i++)
{
var f = (function(elem){
return function() {
return elem;
}
})(list[i]);
result.push(f )
};
return result;
}
No comments:
Post a Comment