chaiscript_prelude_docs.hpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /// This file is not technically part of the ChaiScript API. It is used solely for generating Doxygen docs
  2. /// regarding the ChaiScript standard runtime library.
  3. /// \brief Items in this namespace exist in the ChaiScript language runtime. They are not part of the C++ API
  4. namespace ChaiScript_Language
  5. {
  6. /// \page LangStandardLibraryRef ChaiScript Language Standard Library Reference
  7. ///
  8. /// ChaiScript, at its core, has some very functional programming-inspired habits. Few places show this off as clearly
  9. /// as the prelude, itself a name taken as a nod to the popular functional language Haskell. This prelude is available
  10. /// to all standard ChaiScript applications, and provides a simple foundation for using numbers, strings, and ranges
  11. /// (the general category of Range cs and their iteration).
  12. ///
  13. /// \brief Generic concept of a value in ChaiScript.
  14. ///
  15. /// The Object type exists merely as a concept. All objects in ChaiScript support this concept
  16. /// and have the following methods available to them. All objects are stored internally as chaiscript::Boxed_Value types.
  17. ///
  18. /// \sa chaiscript::Boxed_Value
  19. class Object
  20. {
  21. public:
  22. /// \brief Returns the Type_Info value for this Object
  23. Type_Info get_type_info() const;
  24. /// \brief Returns true if the Object is of the named type
  25. bool is_type(string) const;
  26. /// \brief Returns true if the Object is of the Type_Info passed in
  27. bool is_type(Type_Info) const;
  28. /// \brief Returns true if the Object is immutable
  29. bool is_var_const() const;
  30. /// \brief Returns true if the Object is a pointer and the pointer is null
  31. bool is_var_null() const;
  32. /// \brief Returns true if the Object is stored as a pointer
  33. bool is_var_pointer() const;
  34. /// \brief Returns true if the Object is stored as a reference
  35. bool is_var_reference() const;
  36. /// \brief Returns true if the Object does not contain a value is is undefined.
  37. bool is_var_undef() const;
  38. /// \brief Returns the registered name of the type of the object.
  39. ///
  40. /// \sa Type_Info::name();
  41. string type_name() const;
  42. };
  43. /// \brief Item returned from a Range object from a Map
  44. class Map_Pair
  45. {
  46. public:
  47. /// \brief Returns the key of the Map entry
  48. const string first();
  49. /// \brief Returns the value Object of the Map entry
  50. Object second();
  51. };
  52. /// \brief Maps strings to Objects
  53. ///
  54. /// ChaiScript has a built in shortcut for generating Map objects:
  55. ///
  56. /// Example:
  57. /// \code
  58. /// eval> var m = ["a":1, "b":2];
  59. /// [<a,1>, <b,2>]
  60. /// eval> m.count("a");
  61. /// 1
  62. /// eval> m.count("c");
  63. /// 0
  64. /// eval> m.size();
  65. /// 2
  66. /// \endcode
  67. ///
  68. /// Implemented as std::map<Boxed_Value>
  69. ///
  70. /// \sa Map_Pair
  71. /// \sa chaiscript::bootstrap::standard_library::map_type
  72. class Map
  73. {
  74. public:
  75. /// \brief Returns an object that implements the Range concept for the Map_Pair's in this Map
  76. Range range();
  77. /// \brief Returns an object that implements the Const_Range concept for the Map_Pair's in this Map
  78. Const_Range range() const;
  79. /// \brief Returns the number of elements in the Map
  80. int size() const;
  81. /// \brief Returns the item at the given key, creating an undefined Object if the key does not yet exist in the map
  82. Object operator[](string);
  83. /// \brief Clears the map of all items
  84. void clear();
  85. /// \brief Returns the number of items in the Map with the given key. Returns 0 or 1 since this is not an std::multimap.
  86. int count(string) const;
  87. /// \brief Returns true if the map contains no items
  88. bool empty() const;
  89. };
  90. /// \brief A concept implemented by string, Vector and Map. It is convertible to Range, default constructable and back_insertable
  91. class Container
  92. {
  93. public:
  94. void push_back(Object);
  95. Range range();
  96. Const_Range range() const;
  97. };
  98. /// \brief Converts o into a string.
  99. ///
  100. /// \code
  101. /// eval> to_string(3).is_type("string") <br>
  102. /// true<br>
  103. /// \endcode
  104. string to_string(Object o);
  105. /// \brief Prints o to the terminal, without a trailing carriage return. Applies conversions to string automatically.
  106. /// \code
  107. /// eval> puts("hi, "); puts("there")
  108. /// hi, thereeval>
  109. /// \endcode
  110. /// \sa to_string
  111. /// \sa print
  112. void puts(Object o);
  113. /// \brief Prints o to the terminal, with a trailing carriage return. Applies conversions to string automatically
  114. /// \code
  115. /// eval> print("hello")
  116. /// hello
  117. /// eval>
  118. /// \endcode
  119. /// \sa to_string
  120. /// \sa puts
  121. void print(Object o);
  122. /// \brief ChaiScript representation of std::string. It is an std::string but only some member are exposed to ChaiScript.
  123. ///
  124. /// Because the ChaiScript string object is an std::string, it is directly convertible to and from std::string
  125. /// using the chaiscript::boxed_cast and chaiscript::var functions.
  126. ///
  127. /// With the exception of string::trim, string::rtrim, string::ltrim, all members are direct pass-throughs to the
  128. /// std::string of the same name.
  129. ///
  130. /// \note Object and function notations are equivalent in ChaiScript. This means that
  131. /// \c "bob".find("b") and \c find("bob", "b") are exactly the same. Most examples below follow the
  132. /// second formation of the function calls.
  133. /// \sa \ref keyworddef for extending existing C++ classes in ChaiScript
  134. /// \sa chaiscript::bootstrap::standard_library::string_type
  135. class string
  136. {
  137. public:
  138. /// \brief Finds the first instance of substr.
  139. /// \code
  140. /// eval> find("abab", "ab")
  141. /// 0
  142. /// \endcode
  143. int find(string s) const;
  144. /// \brief Finds the last instance of substr.
  145. /// \code
  146. /// eval> rfind("abab", "ab")
  147. /// 2
  148. /// \endcode
  149. int rfind(string s) const;
  150. /// \brief Finds the first of characters in list in the string.
  151. ///
  152. /// \code
  153. /// eval> find_first_of("abab", "bec")
  154. /// 1
  155. /// \endcode
  156. int find_first_of(string list) const;
  157. /// \brief Finds the last of characters in list in the string.
  158. ///
  159. /// \code
  160. /// eval> find_last_of("abab", "bec")
  161. /// 3
  162. /// \endcode
  163. int find_last_of(string list) const;
  164. /// \brief Finds the first non-matching character to list in the str string.
  165. ///
  166. /// \code
  167. /// eval> find_first_not_of("abcd", "fec")
  168. /// 0
  169. /// \endcode
  170. int find_first_not_of(string list) const;
  171. /// \brief Finds the last non-matching character to list in the list string.
  172. ///
  173. /// \code
  174. /// eval> find_last_not_of("abcd", "fec")
  175. /// 3
  176. /// \endcode
  177. int find_last_not_of(string list) const;
  178. /// \brief Removes whitespace from the front of the string, returning a new string
  179. ///
  180. /// \note This function is implemented as a ChaiScript function using the def member function notation.
  181. ///
  182. /// \code
  183. /// eval> ltrim(" bob")
  184. /// bob
  185. /// \endcode
  186. ///
  187. /// \sa \ref keyworddef
  188. string lstrim() const;
  189. /// \brief Removes whitespace from the back of the string, returning a new string
  190. ///
  191. /// \note This function is implemented as a ChaiScript function using the def member function notation.
  192. ///
  193. /// \code
  194. /// eval> rtrim("bob ") + "|"
  195. /// bob|
  196. /// \endcode
  197. ///
  198. /// \sa \ref keyworddef
  199. string rtrim() const;
  200. /// \brief Removes whitespace from the front and back of the string, returning a new string
  201. ///
  202. /// \note This function is implemented as a ChaiScript function using the def member function notation.
  203. ///
  204. /// \code
  205. /// eval> trim(" bob ") + "|"
  206. /// bob|
  207. /// \endcode
  208. ///
  209. /// Equivalent to rtrim(ltrim(" bob "));
  210. ///
  211. /// \sa \ref keyworddef
  212. string trim() const;
  213. /// \brief Returns the character at the given index in the string, const version
  214. const char &operator[](int t_index) const;
  215. /// \brief Returns the character at the given index in the string
  216. char &operator[](int t_index);
  217. /// \brief Returns underlying const char * for C api compatibility
  218. const char *c_str() const;
  219. /// \brief Returns a pointer to the raw data in the string
  220. const char *data() const;
  221. /// \brief Resets the string to empty
  222. void clear();
  223. /// \brief Returns true if the string is empty
  224. bool empty() const;
  225. /// \brief Returns the size of the string in bytes.
  226. ///
  227. /// This function normally returns size_t in C++. In ChaiScript the return value is cast to int
  228. /// for ease of use.
  229. int size() const;
  230. /// \brief Returns an object that implements the Range concept for the characters of this string
  231. Range range();
  232. /// \brief Returns an object that implements the Const_Range concept for the characters of this string
  233. Const_Range range() const;
  234. };
  235. /// \brief A concept in ChaiScript that is implemented by \ref string, Vector and Map. It provides
  236. /// easy iteration over the elements in a container.
  237. ///
  238. /// Implemented by the template chaiscript::bootstrap::standard_library::Bidir_Range
  239. ///
  240. /// \sa Const_Range
  241. class Range
  242. {
  243. public:
  244. /// \brief Returns the last item of the range
  245. Object back();
  246. /// \brief Returns true if the front and back pointers have passed each other, if no items
  247. /// are left in the Range
  248. bool empty() const;
  249. /// \brief Returns the first item of the range
  250. Object front();
  251. /// \brief Moves the back pointer back one.
  252. ///
  253. /// \post back() returns the element at back() - 1;
  254. void pop_back();
  255. /// \brief Moves the front pointer forward one
  256. ///
  257. /// \post front() returns the element at front() + 1;
  258. void pop_front();
  259. };
  260. /// \brief A concept in ChaiScript that is implemented by \ref string, Vector and Map. It provides
  261. /// easy iteration over the elements in a container. Contained values are const.
  262. ///
  263. /// Implemented by the template chaiscript::bootstrap::standard_library::Const_Bidir_Range
  264. ///
  265. /// \sa Range
  266. class Const_Range
  267. {
  268. public:
  269. /// \brief Returns the last item of the range
  270. const Object back();
  271. /// \brief Returns true if the front and back pointers have passed each other, if no items
  272. /// are left in the Range
  273. bool empty() const;
  274. /// \brief Returns the first item of the range
  275. const Object front();
  276. /// \brief Moves the back pointer back one.
  277. ///
  278. /// \post back() returns the element at back() - 1;
  279. void pop_back();
  280. /// \brief Moves the front pointer forward one
  281. ///
  282. /// \post front() returns the element at front() + 1;
  283. void pop_front();
  284. };
  285. /// \brief A vector of Objects
  286. ///
  287. /// ChaiScript includes a shortcut for creating a Vector of Objects
  288. ///
  289. /// Example:
  290. /// \code
  291. /// eval> var v = [1,2,3,4]
  292. /// [1, 2, 3, 4]
  293. /// eval> v[0];
  294. /// 1
  295. /// eval> v.size();
  296. /// 4
  297. /// \endcode
  298. ///
  299. /// Implemented with std::vector<chaiscript::Boxed_Value>
  300. ///
  301. /// \sa chaiscript::bootstrap::standard_library::vector_type
  302. class Vector
  303. {
  304. public:
  305. /// \brief returns the Object at the given index. Throws an exception if the index does not exist
  306. Object operator[](int t_index);
  307. /// \brief returns a const Object at the given index. Throws an exception if the index does not exist.
  308. const Object operator[](int t_index) const;
  309. /// \brief returns the last item in the Vector
  310. Object back();
  311. /// \brief Clears the Vector of all items
  312. void clear();
  313. /// \brief Returns true if the Vector is contains 0 items
  314. bool empty();
  315. /// \brief Erases the element at the given index
  316. void erase_at(int t_index);
  317. /// \brief Returns the first item in the Vector
  318. Object front();
  319. /// \brief Inserts a new item in the Vector at the given index. The item is not cloned on insert
  320. ///
  321. /// \sa insert_ref
  322. void insert_ref_at(int, Object);
  323. /// \brief Inserts a new item in the Vector at the given index. The item is cloned on insert
  324. ///
  325. /// \sa insert_ref
  326. void insert_at(int, Object);
  327. /// \brief Removes the last item from the Vector
  328. void pop_back();
  329. /// \brief Adds an item to the end of the Vector. The item is not cloned.
  330. ///
  331. /// \sa push_back
  332. void push_back_ref(Object);
  333. /// \brief Adds an item to the end of the Vector. The item is cloned.
  334. ///
  335. /// \sa push_back_ref
  336. void push_back(Object);
  337. /// \brief Returns a Range object for the entire vector
  338. Range range();
  339. /// \brief Returns a Const_Range object for the entire vector
  340. Const_Range range() const;
  341. /// \brief Returns the number of elements in the Vector
  342. int size() const;
  343. };
  344. class Type_Info
  345. {
  346. public:
  347. /// \brief Compares this Type_Info object with another one and returns true if the two types are the same
  348. /// after const, pointer, reference are removed.
  349. bool bare_equal(Type_Info t_ti) const;
  350. /// \brief Returns the mangled C++ name for the type given by the compiler after const, pointer, reference is removed.
  351. string cpp_bare_name() const;
  352. /// \brief Returns the mangled C++ name for the type given by the compiler.
  353. string cpp_name() const;
  354. /// \brief Returns true if the type is const
  355. bool is_type_const() const;
  356. /// \brief Returns true if the type is a pointer
  357. bool is_type_pointer() const;
  358. /// \brief Returns true if the type is a reference
  359. bool is_type_reference() const;
  360. /// \brief Returns true if the type is undefined
  361. bool is_type_undef() const;
  362. /// \brief Returns true if the type is "void"
  363. bool is_type_void() const;
  364. /// \brief Returns the ChaiScript registered name for the type if one exists.
  365. string name() const;
  366. };
  367. /// \brief Represents a function object in ChaiScript
  368. ///
  369. /// A function object may be one function, such as:
  370. /// \code
  371. /// var f = fun(x) { return x; }
  372. /// \endcode
  373. ///
  374. /// Or it may represent multiple functions
  375. /// \code
  376. /// var f2 = `-`; // represents the unary - as well as the set of binary - operators
  377. /// \endcode
  378. ///
  379. /// Guarded function example
  380. /// \code
  381. /// def f3(x) : x > 2 {
  382. /// return x;
  383. /// }
  384. /// \endcode
  385. ///
  386. /// Examples in the function definitions below will reference these examples
  387. class Function
  388. {
  389. public:
  390. /// \brief Returns the annotation description of the function
  391. string get_annotation() const;
  392. /// \brief Returns the arity of the function, -1 if the function takes a variable number of parameters
  393. ///
  394. /// Example:
  395. /// \code
  396. /// eval> f.get_arity()
  397. /// 1
  398. /// eval> f2.get_arity()
  399. /// -1
  400. /// \endcode
  401. int get_arity() const;
  402. /// \brief Returns a vector of the contained functions
  403. ///
  404. /// Example:
  405. /// \code
  406. /// eval> f.get_contained_functions().size()
  407. /// 0
  408. /// eval> f2.get_contained_functions().size()
  409. /// 11
  410. /// eval> var v = f2.get_contained_functions();
  411. /// v[0].get_arity()
  412. /// 2
  413. /// \endcode
  414. Vector get_contained_functions() const;
  415. /// \brief Returns a function guard as function
  416. ///
  417. /// Example:
  418. /// \code
  419. /// eval> f.get_guard() // Throws exception
  420. /// Function does not have a guard
  421. /// eval> f3.get_guard().get_arity()
  422. /// 1
  423. /// \endcode
  424. Function get_guard() const;
  425. /// \brief Returns a vector of Type_Info objects that represent the param types for this function.
  426. /// The first value in the list is the return type.
  427. ///
  428. /// If this function is a conglomerate of several functions (get_contained_values().size() > 0)
  429. /// then the function returns as many Type_Info objects as it can. If the functions contained all have
  430. /// the same arity, then it represents the arity. If they have different arities, it returns only
  431. /// one value - the return type.
  432. ///
  433. /// For each parameter that is the same type, the type is returned. If the types are different
  434. /// then a Type_Info for Object is returned.
  435. ///
  436. /// Example:
  437. /// \code
  438. /// eval> f2.get_param_types().size(); // Returns a Type_Info for Object for the return type
  439. /// 1
  440. /// \endcode
  441. Vector get_param_types() const;
  442. /// \brief Returns true if the function has a guard to it. Always returns false for a conglomerate function
  443. bool has_guard() const;
  444. /// \brief Calls the function with the given set of parameters and returns the value;
  445. ///
  446. /// Example:
  447. /// \code
  448. /// eval> `-`.call([2,1]);
  449. /// 1
  450. /// \endcode
  451. Object call(Vector t_params) const;
  452. }
  453. /// \brief Returns the max of a or b. Requires that operator>(a, b) exists
  454. /// Equivalent to
  455. /// \code
  456. /// return a>b?a:b;
  457. /// \endcode
  458. ///
  459. /// Example:
  460. /// \code
  461. /// eval> max(4, 10)
  462. /// 10
  463. /// \endcode
  464. Object max(Object a, Object b);
  465. /// \brief Returns the min of a or b. Requires that operator<(a, b) exists
  466. ///
  467. /// Equivalent to
  468. /// \code
  469. /// return a<b?a:b;
  470. /// \endcode
  471. ///
  472. /// Example:
  473. /// \code
  474. /// eval> min(4, 10)
  475. /// 4
  476. /// \endcode
  477. Object min(Object a, Object b);
  478. /// \brief Returns true if x is an even integer.
  479. ///
  480. /// Will also work on any non-integer type for which an operator%(x, int) exists
  481. ///
  482. /// Example:
  483. /// \code
  484. /// eval> even(4)
  485. /// true
  486. /// \endcode
  487. bool even(Object x);
  488. /// \brief Returns true if x is an odd integer.
  489. ///
  490. /// Will also work on any non-integer type for which an operator%(x, int) exists
  491. ///
  492. /// Example:
  493. /// \code
  494. /// eval> odd(4)
  495. /// false
  496. /// \endcode
  497. bool even(Object x);
  498. /// \brief Applies the function f over each element in the Range c.
  499. ///
  500. /// Example:
  501. /// \code
  502. /// eval> for_each([1, 2, 3], print)
  503. /// 1
  504. /// 2
  505. /// 3
  506. /// \endcode
  507. void for_each(Range c, Function f);
  508. /// \brief Applies f over each element in the Range c, joining all the results.
  509. ///
  510. /// Example:
  511. /// \code
  512. /// eval> map([1, 2, 3], odd)
  513. /// [true, false, true]
  514. /// \endcode
  515. Object map(Range c, Function f);
  516. /// \brief Starts with the initial value and applies the function f to it and the first element of the Range c.
  517. /// The result is then applied to the second element, and so on until the elements are exhausted.
  518. ///
  519. /// Example:
  520. /// \code
  521. /// eval> foldl([1, 2, 3, 4], `+`, 0)
  522. /// 10
  523. /// \endcode
  524. Object foldl(Range c, Function f, Object initial);
  525. /// \brief Returns the sum total of the values in the Range c.
  526. ///
  527. /// Example:
  528. /// \code
  529. /// eval> sum([1, 2, 3, 4])
  530. /// 10
  531. /// \endcode
  532. ///
  533. /// Equivalent to:
  534. /// \code
  535. /// foldl(c, `+`, 0.0);
  536. /// \endcode
  537. Numeric sum(Range c);
  538. /// \brief Returns the product of the value in the Range c.
  539. ///
  540. /// Example:
  541. /// \code
  542. /// eval> product([1, 2, 3, 4])
  543. /// 24
  544. /// \endcode
  545. ///
  546. /// Equivalent to:
  547. /// \code
  548. /// foldl(c, `*`, 1.0);
  549. /// \endcode
  550. Numeric product(Range c);
  551. /// \brief Takes num elements from the Range c, returning them.
  552. ///
  553. /// Example:
  554. /// \code
  555. /// eval> take([1, 2, 3, 4], 2)
  556. /// [1, 2]
  557. /// \endcode
  558. ///
  559. /// \returns A container of the same type that was passed in
  560. Object take(Range c, int num);
  561. /// \brief Takes elements from the Range c that match function f, stopping at the first non-match, returning them as a new Vector.
  562. ///
  563. /// Example:
  564. /// \code
  565. /// eval> take_while([1, 2, 3], odd)
  566. /// [1]
  567. /// \endcode
  568. ///
  569. /// \returns A container of the same type that was passed in
  570. Object take_while(Range c, Function f);
  571. /// \brief Drops num elements from the Range c, returning the remainder.
  572. ///
  573. /// Example:
  574. /// \code
  575. /// eval> drop([1, 2, 3, 4], 2)
  576. /// [3, 4]
  577. /// \endcode
  578. ///
  579. /// \returns A container of the same type that was passed in
  580. Object drop(Range c, int num);
  581. /// \brief Drops elements from the Range c that match f, stopping at the first non-match, returning the remainder.
  582. ///
  583. /// Example:
  584. /// \code
  585. /// eval> drop_while([1, 2, 3], odd)
  586. /// [2, 3]
  587. /// \endcode
  588. Object drop_while(Range c, Function f);
  589. /// \brief Similar to foldl, this takes the first two elements as its starting values for f. This assumes Range c has at least 2 elements.
  590. ///
  591. /// Example:
  592. /// \code
  593. /// eval> reduce([1, 2, 3, 4], `+`)
  594. /// 10
  595. /// \endcode
  596. Object reduce(Range c, Function f);
  597. /// \brief Takes elements from Container c that match function f, return them.
  598. ///
  599. /// Example:
  600. /// \code
  601. /// eval> filter([1, 2, 3, 4], odd)
  602. /// [1, 3]
  603. /// \endcode
  604. Object filter(Container c, Function f);
  605. /// \brief Joins the elements of the Range c into a string, delimiting each with the delim string.
  606. ///
  607. /// Example:
  608. /// \code
  609. /// eval> join([1, 2, 3], "*")
  610. /// 1*2*3
  611. /// \endcode
  612. string join(Range c, string delim);
  613. /// \brief Returns the contents of the Container c in reversed order.
  614. ///
  615. /// Example:
  616. /// \code
  617. /// eval> reverse([1, 2, 3, 4, 5, 6, 7])
  618. /// [7, 6, 5, 4, 3, 2, 1]
  619. /// \endcode
  620. Container reverse(Container c);
  621. /// \brief Generates a new Vector filled with values starting at x and ending with y.
  622. ///
  623. /// Works on types supporting operator<=(x, y) and operator++(x)
  624. ///
  625. /// Example:
  626. /// \code
  627. /// eval> generate_range(1, 10)
  628. /// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  629. /// \endcode
  630. Vector generate_range(Object x, Object y);
  631. /// \brief Returns a new Range with x and y concatenated.
  632. ///
  633. /// Example:
  634. /// \code
  635. /// eval> concat([1, 2, 3], [4, 5, 6])
  636. /// [1, 2, 3, 4, 5, 6]
  637. /// \endcode
  638. Object concat(Range x, Range y);
  639. /// \brief Returns a new Vector with x and y as its values.
  640. ///
  641. /// Example:
  642. /// \code
  643. /// eval> collate(1, 2)
  644. /// [1, 2]
  645. /// \endcode
  646. Vector collate(Object x, Object y);
  647. /// \brief Applies f to elements of x and y, returning a new Vector with the result of each application.
  648. ///
  649. /// Example:
  650. /// \code
  651. /// eval> zip_with(`+`, [1, 2, 3], [4, 5, 6])
  652. /// [5, 7, 9]
  653. /// \endcode
  654. Vector zip_with(Function f, Range x, Range y);
  655. /// \brief Collates elements of x and y, returning a new Vector with the result.
  656. ///
  657. /// Example:
  658. /// \code
  659. /// eval> zip([1, 2, 3], [4, 5, 6])
  660. /// [[1, 4], [2, 5], [3, 6]]
  661. /// \endcode
  662. Vector zip(Range x, Range y);
  663. /// \brief returns true if there exists a call to the Function f that takes the given parameters
  664. ///
  665. /// Example:
  666. /// \code
  667. /// eval> call_exists(`+`, 1, 2)
  668. /// true
  669. /// \endcode
  670. bool call_exists(Function f, ...);
  671. /// \brief Reverses a Range object so that the elements are accessed in reverse
  672. Range retro(Range);
  673. /// \brief Reverses a Const_Range object so that the elements are accessed in reverse
  674. Const_Range retro(Const_Range);
  675. /// \brief Raises the given object as an exception. Any type of object can be thrown.
  676. ///
  677. /// Example:
  678. /// \code
  679. /// eval> try { throw(1); } catch (e) { print("Exception caught: " + to_string(e)); }
  680. /// Exception caught: 1
  681. /// \endcode
  682. ///
  683. /// \sa \ref keywordtry
  684. void throw(Object);
  685. }