A new version of the Frost Programming Language interpreter is now available! Now it is possible to create function pointers (or function references), call a function referenced by a variable or an array, and it is possible to create Blocks (just like Objective-C Blocks but with a different syntax)!
Example:
This generic bubble-sort can receive an array of any type of data to sort, as long as you provide it with a "compare" function capable of comparing these types of data.
How to create a function pointer?
var printPointer = @print;
// OR
var someFunctions = {@print, @scanInt};
// OR
var someFunctions = {@print, @scanInt};
How to create a block?
var a = ^ { [print string:"I am a Block!\n" format:{}]; };
// OR
const b = ^:a {
[print string:"I am another Block... \'a\' equals %v\n" format:{a}];
}
// OR
var arrayOfBlocks = {
^{ [print string:"First!\n" format:{}]; },
^{ [print string:"Second!\n" format:{}]; },
^{ [print string:"Third!\n" format:{}]; }
};
// OR
const b = ^:a {
[print string:"I am another Block... \'a\' equals %v\n" format:{a}];
}
// OR
var arrayOfBlocks = {
^{ [print string:"First!\n" format:{}]; },
^{ [print string:"Second!\n" format:{}]; },
^{ [print string:"Third!\n" format:{}]; }
};
How to call a block or a function referenced by a variable?
[~printPointer string:"Hello!\n" format:{}];
[~someFunctions[0] string:"Hello again!\n" format:{}];
[~someFunctions[1]];
[~a];
[~b a:5];
var i;
for(i = 0; i < arrayOfBlocks.length; i = i + 1) {
[~arrayOfBlocks[i]];
}
[~someFunctions[0] string:"Hello again!\n" format:{}];
[~someFunctions[1]];
[~a];
[~b a:5];
var i;
for(i = 0; i < arrayOfBlocks.length; i = i + 1) {
[~arrayOfBlocks[i]];
}
No comments:
Post a Comment