ChaiScript
Classes | Functions
ChaiScript_Language Namespace Reference

This file is not technically part of the ChaiScript API. More...

Classes

class  Const_Range
 A concept in ChaiScript that is implemented by string, Vector and Map. More...
 
class  Container
 A concept implemented by string, Vector and Map. It is convertible to Range, default constructable and back_insertable. More...
 
class  Function
 Represents a function object in ChaiScript. More...
 
class  Map
 Maps strings to Objects. More...
 
class  Map_Pair
 Item returned from a Range object from a Map. More...
 
class  Object
 Generic concept of a value in ChaiScript. More...
 
class  Range
 A concept in ChaiScript that is implemented by string, Vector and Map. More...
 
class  string
 ChaiScript representation of std::string. More...
 
class  Type_Info
 
class  Vector
 A vector of Objects. More...
 

Functions

string to_string (Object o)
 Converts o into a string. More...
 
void puts (Object o)
 Prints o to the terminal, without a trailing carriage return. More...
 
void print (Object o)
 Prints o to the terminal, with a trailing carriage return. More...
 
class ChaiScript_Language::Function max (Object a, Object b)
 Returns the max of a or b. More...
 
Object min (Object a, Object b)
 Returns the min of a or b. More...
 
bool even (Object x)
 Returns true if x is an even integer. More...
 
void for_each (Range c, Function f)
 Applies the function f over each element in the Range c. More...
 
Object map (Range c, Function f)
 Applies f over each element in the Range c, joining all the results. More...
 
Object foldl (Range c, Function f, Object initial)
 Starts with the initial value and applies the function f to it and the first element of the Range c. More...
 
Numeric sum (Range c)
 Returns the sum total of the values in the Range c. More...
 
Numeric product (Range c)
 Returns the product of the value in the Range c. More...
 
Object take (Range c, int num)
 Takes num elements from the Range c, returning them. More...
 
Object take_while (Range c, Function f)
 Takes elements from the Range c that match function f, stopping at the first non-match, returning them as a new Vector. More...
 
Object drop (Range c, int num)
 Drops num elements from the Range c, returning the remainder. More...
 
Object drop_while (Range c, Function f)
 Drops elements from the Range c that match f, stopping at the first non-match, returning the remainder. More...
 
Object reduce (Range c, Function f)
 Similar to foldl, this takes the first two elements as its starting values for f. More...
 
Object filter (Container c, Function f)
 Takes elements from Container c that match function f, return them. More...
 
string join (Range c, string delim)
 Joins the elements of the Range c into a string, delimiting each with the delim string. More...
 
Container reverse (Container c)
 Returns the contents of the Container c in reversed order. More...
 
Vector generate_range (Object x, Object y)
 Generates a new Vector filled with values starting at x and ending with y. More...
 
Object concat (Range x, Range y)
 Returns a new Range with x and y concatenated. More...
 
Vector collate (Object x, Object y)
 Returns a new Vector with x and y as its values. More...
 
Vector zip_with (Function f, Range x, Range y)
 Applies f to elements of x and y, returning a new Vector with the result of each application. More...
 
Vector zip (Range x, Range y)
 Collates elements of x and y, returning a new Vector with the result. More...
 
bool call_exists (Function f,...)
 returns true if there exists a call to the Function f that takes the given parameters More...
 
Range retro (Range)
 Reverses a Range object so that the elements are accessed in reverse.
 
Const_Range retro (Const_Range)
 Reverses a Const_Range object so that the elements are accessed in reverse.
 
void throw (Object)
 Raises the given object as an exception. More...
 

Detailed Description

This file is not technically part of the ChaiScript API.

It is used solely for generating Doxygen docs regarding the ChaiScript standard runtime library. Items in this namespace exist in the ChaiScript language runtime. They are not part of the C++ API

Function Documentation

§ call_exists()

bool ChaiScript_Language::call_exists ( Function  f,
  ... 
)

returns true if there exists a call to the Function f that takes the given parameters

Example:

eval> call_exists(`+`, 1, 2)
true

§ collate()

Vector ChaiScript_Language::collate ( Object  x,
Object  y 
)

Returns a new Vector with x and y as its values.

Example:

eval> collate(1, 2)
[1, 2]

§ concat()

Object ChaiScript_Language::concat ( Range  x,
Range  y 
)

Returns a new Range with x and y concatenated.

Example:

eval> concat([1, 2, 3], [4, 5, 6])
[1, 2, 3, 4, 5, 6]

§ drop()

Object ChaiScript_Language::drop ( Range  c,
int  num 
)

Drops num elements from the Range c, returning the remainder.

Example:

eval> drop([1, 2, 3, 4], 2)
[3, 4]
Returns
A container of the same type that was passed in

§ drop_while()

Object ChaiScript_Language::drop_while ( Range  c,
Function  f 
)

Drops elements from the Range c that match f, stopping at the first non-match, returning the remainder.

Example:

eval> drop_while([1, 2, 3], odd)
[2, 3]

§ even()

bool ChaiScript_Language::even ( Object  x)

Returns true if x is an even integer.

Returns true if x is an odd integer.

Will also work on any non-integer type for which an operator%(x, int) exists

Example:

eval> even(4)
true

Will also work on any non-integer type for which an operator%(x, int) exists

Example:

eval> odd(4)
false

§ filter()

Object ChaiScript_Language::filter ( Container  c,
Function  f 
)

Takes elements from Container c that match function f, return them.

Example:

eval> filter([1, 2, 3, 4], odd)
[1, 3]

§ foldl()

Object ChaiScript_Language::foldl ( Range  c,
Function  f,
Object  initial 
)

Starts with the initial value and applies the function f to it and the first element of the Range c.

The result is then applied to the second element, and so on until the elements are exhausted.

Example:

eval> foldl([1, 2, 3, 4], `+`, 0)
10

§ for_each()

void ChaiScript_Language::for_each ( Range  c,
Function  f 
)

Applies the function f over each element in the Range c.

Example:

eval> for_each([1, 2, 3], print)
1
2
3

§ generate_range()

Vector ChaiScript_Language::generate_range ( Object  x,
Object  y 
)

Generates a new Vector filled with values starting at x and ending with y.

Works on types supporting operator<=(x, y) and operator++(x)

Example:

eval> generate_range(1, 10)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

§ join()

string ChaiScript_Language::join ( Range  c,
string  delim 
)

Joins the elements of the Range c into a string, delimiting each with the delim string.

Example:

eval> join([1, 2, 3], "*")
1*2*3

§ map()

Object ChaiScript_Language::map ( Range  c,
Function  f 
)

Applies f over each element in the Range c, joining all the results.

Example:

eval> map([1, 2, 3], odd)
[true, false, true]

§ max()

class ChaiScript_Language::Function ChaiScript_Language::max ( Object  a,
Object  b 
)

Returns the max of a or b.

Requires that operator>(a, b) exists Equivalent to

return a>b?a:b;

Example:

eval> max(4, 10)
10

§ min()

Object ChaiScript_Language::min ( Object  a,
Object  b 
)

Returns the min of a or b.

Requires that operator<(a, b) exists

Equivalent to

return a<b?a:b;

Example:

eval> min(4, 10)
4

§ print()

void ChaiScript_Language::print ( Object  o)

Prints o to the terminal, with a trailing carriage return.

Applies conversions to string automatically

eval> print("hello")
hello
eval>
See also
to_string
puts

§ product()

Numeric ChaiScript_Language::product ( Range  c)

Returns the product of the value in the Range c.

Example:

eval> product([1, 2, 3, 4])
24

Equivalent to:

foldl(c, `*`, 1.0);

§ puts()

void ChaiScript_Language::puts ( Object  o)

Prints o to the terminal, without a trailing carriage return.

Applies conversions to string automatically.

eval> puts("hi, "); puts("there")
hi, thereeval>
See also
to_string
print

§ reduce()

Object ChaiScript_Language::reduce ( Range  c,
Function  f 
)

Similar to foldl, this takes the first two elements as its starting values for f.

This assumes Range c has at least 2 elements.

Example:

eval> reduce([1, 2, 3, 4], `+`)
10

§ reverse()

Container ChaiScript_Language::reverse ( Container  c)

Returns the contents of the Container c in reversed order.

Example:

eval> reverse([1, 2, 3, 4, 5, 6, 7])
[7, 6, 5, 4, 3, 2, 1]

§ sum()

Numeric ChaiScript_Language::sum ( Range  c)

Returns the sum total of the values in the Range c.

Example:

eval> sum([1, 2, 3, 4])
10

Equivalent to:

foldl(c, `+`, 0.0);

§ take()

Object ChaiScript_Language::take ( Range  c,
int  num 
)

Takes num elements from the Range c, returning them.

Example:

eval> take([1, 2, 3, 4], 2)
[1, 2]
Returns
A container of the same type that was passed in

§ take_while()

Object ChaiScript_Language::take_while ( Range  c,
Function  f 
)

Takes elements from the Range c that match function f, stopping at the first non-match, returning them as a new Vector.

Example:

eval> take_while([1, 2, 3], odd)
[1]
Returns
A container of the same type that was passed in

§ throw()

void ChaiScript_Language::throw ( Object  )

Raises the given object as an exception.

Any type of object can be thrown.

Example:

eval> try { throw(1); } catch (e) { print("Exception caught: " + to_string(e)); }
Exception caught: 1
See also
try

§ to_string()

string ChaiScript_Language::to_string ( Object  o)

Converts o into a string.

eval> to_string(3).is_type("string") <br>
true<br>

§ zip()

Vector ChaiScript_Language::zip ( Range  x,
Range  y 
)

Collates elements of x and y, returning a new Vector with the result.

Example:

eval> zip([1, 2, 3], [4, 5, 6])
[[1, 4], [2, 5], [3, 6]]

§ zip_with()

Vector ChaiScript_Language::zip_with ( Function  f,
Range  x,
Range  y 
)

Applies f to elements of x and y, returning a new Vector with the result of each application.

Example:

eval> zip_with(`+`, [1, 2, 3], [4, 5, 6])
[5, 7, 9]