Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Turner lefticus

View GitHub Profile
View chaiscript_fp.chai
// ChaiScript supports normal functional programming paradigms, with automatic overload resolution
var plus = `+` // get a reference to the function object representing all known `+` functions
print(plus("a", "b")) // prints "ab"
print(plus(1 , 3)) // prints "4"
// print(plus("a" , 3)) // generates a runtime error, no string + int operator available
// Back ticks are only necessary for capturing operator functions
@lefticus
lefticus / function_types.cpp
Last active Aug 29, 2015
function param deduction
View function_types.cpp
#include <tuple>
#include <iostream>
#include <typeinfo>
template<typename Ret>
struct function_type
{
};
template<typename Ret>
View iife.cpp
#include <chrono>
#include <string>
#include <sstream>
#include <vector>
#include <iostream>
std::vector<std::vector<std::string>> classic(const int num_vecs, const int vec_size)
{
std::vector<std::vector<std::string>> retval;
View chaiscript_future.chai
var func = fun(){
var ret = 0;
for (var i = 0; i < 1000000; ++i) {
ret += i;
}
return ret;
}
// async takes a 0 parameter function object which is run asynchronously and
// returns a Boxed_Value (ie, any value, including void, should work)
@lefticus
lefticus / generator.chai
Last active Aug 29, 2015
chaiscript generator proposal
View generator.chai
// Generator class
class Generator
{
var has_value;
var value_holder;
var params;
var func;
// empty Generator - no value contained
View system_config.yaml
repositories:
- "ChaiScript/ChaiScript"
View initialize_vector.cpp
#include <vector>
int main()
{
// initialize a vector of integers. For the purposes of this example let's assume we *need* a vector
std::vector<int> v {1, 2, 3, 4, 5, 6, 1012, 1094};
}
View convert_list_of_values_to_vector_of_strings.cpp
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
template<typename ... T>
std::vector<std::string> to_strings(const T& ... t)
{
std::stringstream ss;
return { (ss.str(""), ss << t, ss.str())... };
View chaiscript_overview.chai
// ChaiScript supports the normal kind of control blocks you've come to expect from
// C++ and JavaScript
if (5 > 2) {
print("Yup, 5 > 2");
} else if (2 > 5) {
// never gonna happen
} else {
// really not going to happen
You can’t perform that action at this time.