Module: Trxl::HelpFunction0

Defined in:
lib/trxl/trxl_grammar.rb

Instance Method Summary collapse

Instance Method Details

#eval(env = Environment.new) ⇒ Object



4910
4911
4912
# File 'lib/trxl/trxl_grammar.rb', line 4910

def eval(env = Environment.new)
  to_s(env)
end

#to_s(env = Environment.new) ⇒ Object



4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
# File 'lib/trxl/trxl_grammar.rb', line 4914

def to_s(env = Environment.new)
  help =  "-----------------------------------------\n"
  help =  "           TRXL Language HELP            \n"
  help =  "-----------------------------------------\n"
  help << "1)  Built in operators:\n"
  help << "    +,-,*,/,%,==,!=,<=,>=,<,>,;\n"
  help << "-----------------------------------------\n"
  help << "2)  Integers and floats in arithmetics:\n"
  help << "    1 or 2.33333 or 0.34 or .34\n"
  help << "-----------------------------------------\n"
  help << "3)  Arbitrary nesting of parentheses:\n"
  help << "    (1+2*(5+((3+4)*3)-6/2)+7*2)\n"
  help << "    => 61\n"
  help << "-----------------------------------------\n"
  help << "4)  Comments:\n"
  help << "    # A comment until the end of the line\n"
  help << "    /* A longer comment that\n"
  help << "       spans multiple lines\n"
  help << "     */\n"
  help << "-----------------------------------------\n"
  help << "5)  Built in keywords:\n"
  help << "    TRUE,FALSE,NULL,IF,ELSE,END\n"
  help << "-----------------------------------------\n"
  help << "6)  Built in functions:\n"
  help << "    HELP,ENV,SIZE,SPLIT,ROUND,MIN,MAX\n"
  help << "    SUM, MULT, AVG, PRINT, PRINT_LINE\n"
  help << "    TO_INT, TO_FLOAT, TO_ARRAY, AVG_SUM\n"
  help << "    MATCHING_IDS, VALUES_OF_TYPE, COMPACT\n"
  help << "    IS_EMPTY, COMPACT_AVG\n"
  help << "-----------------------------------------\n"
  help << "7)  Standard library functions:\n"
  help << "    foreach_in, inject, map, select\n"
  help << "    reject, in_groups_of, sum_of_type\n"
  help << "    avg_sum_of_type, avg_range_sum_of_type\n"
  help << "    total_range_sum_of_type, ratio\n"
  help << "    year_from_date, month_from_date\n"
  help << "    hash_values, hash_value_sum\n"
  help << "    avg_hash_value_sum, hash_range_values\n"
  help << "    hash_range_value_sum\n"
  help << "    avg_hash_range_value_sum\n"
  help << "-----------------------------------------\n"
  help << "8)  Access the current environment:\n"
  help << "    ENV; (your output may differ)\n"
  help << "    => { :a => 3, :foo => 5 }\n"
  help << "    Given the following environment:\n"
  help << "    { :a => 1, :b => 2, :c => 3 }\n"
  help << "    ENV['a']\n"
  help << "    => 1\n"
  help << "    ENV['a'..'b']\n"
  help << "    => { :a => 1, :b => 2 }\n"
  help << "-----------------------------------------\n"
  help << "9)  Numeric variables and literals\n"
  help << "    3;\n"
  help << "    => 3\n"
  help << "    a = 3;\n"
  help << "    => 3\n"
  help << "    a;\n"
  help << "    => 3\n"
  help << "-----------------------------------------\n"
  help << "10) String variables and literals\n"
  help << "    \"This is a string\";\n"
  help << "    => \"This is a string\";\n"
  help << "    'This is a string';\n"
  help << "    => \"This is a string\";\n"
  help << "    s1 = \"This is a string\"; s1;\n"
  help << "    => \"This is a string\"\n"
  help << "    s2 = 'This is a string'; s2;\n"
  help << "    => \"This is a string\"\n"
  help << "    SIZE(s1);\n"
  help << "    => 16\n"
  help << "    SIZE(\"foo\");\n"
  help << "    => 3\n"
  help << "-----------------------------------------\n"
  help << "11) Variables and closure applications\n"
  help << "    a = 3; foo = 5;\n"
  help << "    calc = fun(x,y) { (x + y) * a + foo };\n"
  help << "    calc(2,2);\n"
  help << "    => 17\n"
  help << "-----------------------------------------\n"
  help << "12) Array variables and literals\n"
  help << "    arr = [1, [fun(){2}()], fun(x){x}(3)]\n"
  help << "    SIZE(arr);\n"
  help << "    => 3\n"
  help << "    SIZE([1,2,3]);\n"
  help << "    => 3\n"
  help << "    [1,2,3] + [4,[5,6]];\n"
  help << "    => [1,2,3,4,[5,6]]\n"
  help << "    [1,2,3] - [[1],2,3];\n"
  help << "    => [1]\n"
  help << "-----------------------------------------\n"
  help << "13) Hash variables and literals\n"
  help << "    h = { 1 => fun(){2}(), 'a' => 'foo' }\n"
  help << "    SIZE(h);\n"
  help << "    => 2\n"
  help << "    h[1];\n"
  help << "    => 'fun(){2}()'\n"
  help << "    h['a'];\n"
  help << "    => 'foo'\n"
  help << "    SIZE({ 1 => 2});\n"
  help << "    => 1\n"
  help << "-----------------------------------------\n"
  help << "14) Range variables and literals\n"
  help << "    range_including_upper = 1..5\n"
  help << "    => [ 1, 2, 3, 4, 5 ]\n"
  help << "    SIZE(range_including_upper);\n"
  help << "    => 5\n"
  help << "    range_excluding_upper = 1...5\n"
  help << "    => [ 1, 2, 3, 4 ]\n"
  help << "    SIZE(range_excluding_upper);\n"
  help << "    => 4\n"
  help << "    SIZE([1..5);\n"
  help << "    => 5\n"
  help << "-----------------------------------------\n"
  help << "15) Conditional branching and recursion:\n"
  help << "    factorial = fun(x) {\n"
  help << "      if(x == 0)\n"
  help << "        1\n"
  help << "      else\n"
  help << "        x * factorial(x - 1)\n"
  help << "      end\n"
  help << "    }\n"
  help << "    factorial(5);\n"
  help << "    => 120\n"
  help << "-----------------------------------------\n"
  help << "16) Conditional branching:\n"
  help << "    foo = fun(x) {\n"
  help << "      if(x == 0)\n"
  help << "        0\n"
  help << "      elsif(x == 1)\n"
  help << "        1\n"
  help << "      else\n"
  help << "        2\n"
  help << "      end\n"
  help << "    }\n"
  help << "    foo(0);\n"
  help << "    => 0\n"
  help << "    foo(1);\n"
  help << "    => 1\n"
  help << "    foo(2);\n"
  help << "    => 2\n"
  help << "-----------------------------------------\n"
  help << "17) case expressions:\n"
  help << "    foo = fun(x) {\n"
  help << "      case x\n"
  help << "        when NULL then NULL\n"
  help << "        when 0 then 0\n"
  help << "        when 1 then 1\n"
  help << "        when 2 then 2\n"
  help << "        else 3\n"
  help << "      end\n"
  help << "    }\n"
  help << "    foo(1);\n"
  help << "    => 1\n"
  help << "    foo(3);\n"
  help << "    => 3\n"
  help << "-----------------------------------------\n"
  help
end