{"id":22777731,"url":"https://github.com/a1exwang/wtf-interp","last_synced_at":"2025-08-01T14:02:36.730Z","repository":{"id":95285447,"uuid":"64835432","full_name":"a1exwang/wtf-interp","owner":"a1exwang","description":"An functional scripting language inspired by Ruby, Elixir, CoffeeScript, Python, etc","archived":false,"fork":false,"pushed_at":"2017-06-05T08:46:19.000Z","size":123,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-13T13:43:20.215Z","etag":null,"topics":["functional-programming","interpreted-programming-language","language","ruby","wtf"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/a1exwang.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-08-03T09:59:29.000Z","updated_at":"2021-05-28T09:49:32.000Z","dependencies_parsed_at":"2023-04-28T14:02:12.067Z","dependency_job_id":null,"html_url":"https://github.com/a1exwang/wtf-interp","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/a1exwang/wtf-interp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a1exwang%2Fwtf-interp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a1exwang%2Fwtf-interp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a1exwang%2Fwtf-interp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a1exwang%2Fwtf-interp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a1exwang","download_url":"https://codeload.github.com/a1exwang/wtf-interp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a1exwang%2Fwtf-interp/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268240277,"owners_count":24218355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functional-programming","interpreted-programming-language","language","ruby","wtf"],"created_at":"2024-12-11T19:17:12.684Z","updated_at":"2025-08-01T14:02:36.628Z","avatar_url":"https://github.com/a1exwang.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"### An interpreted language inspired by Ruby, Elixir, CoffeeScript, Python, etc\n\n##### Learn from Examples\n\n- Basic Data Types\n\n```\n  # Integers\n  a = 1;\n  \n  # Strings\n  b = \"abc\";\n  \n  # Lists\n  lst = [1, 2, 5, \"hello world\"];\n  each(lst, -\u003e (item) { puts(item); });\n  puts(lst[3]);\n\n  # 2D list\n  lst1 = [[1, 3, 5],\n          [2, 4, 6],\n          [3, 5, 7]];\n  puts(to_s(lst1[0][0]));\n\n  # Booleans and Nil\n  puts([True, False, Nil]);\n  \n  # Hash Map\n  map = {a: 2 + 3};\n  puts(map[\"a\"]);\n  \n  # Functions\n  puts(Type::is_a(1, Type::Int));\n  puts(Type::is_a(1, Type::Float));\n  puts(Type::is_a(Type::is_a, Type::Function));\n```\n\n- Operators\n\n```\n  puts(-1);\n  puts(1 + 2);\n  puts(1 - 2);\n  puts(1 * 2);\n  puts((3 + 4) * 5);\n  puts(\"abc\" == \"abc\");\n  puts(\"abc\" != \"abcd\");\n  puts(\"abc\" != 1);\n  puts(Nil == Nil);\n  puts(1 \u003e 2);\n  puts(1 \u003e= 1);\n```\n\n- Basic Statements\n```\n  puts(\n    if (True) {\n      \"true\";\n    } else {\n      \"false\";\n    }\n  );\n```\n\n- Functions as First Citizens\n\n```\n  fn = -\u003e() { -\u003e () { \"fn\"; }; };\n  fn1 = -\u003e(x, *args) {\n    x + args[0] + args[1] + args[2] + 1;\n  };\n  puts(whats(fn));\n  puts(whats(fn()));\n  puts(fn()());\n  puts(fn1(1, 2, 3, 4));\n  \n```\n\n- Modules\n\n```\n  C = module {\n    B = module {\n      A = 1;\n    };\n  };\n  puts(C::B::A);\n  \n  include(C::B);\n  puts(A);\n```\n\n- require() v.s. import()\n```\n  # a.wtf\n  A = 1\n  \n  # b.wtf\n  B = 2\n  \n  # \"require\" is like Ruby's require\n  # It defines all vars of the required file in current bindings\n  \n  # require.wtf\n  a = require(\"./a\");\n  puts(A); # =\u003e 1\n  puts(a); # =\u003e 1\n  \n  # \"import\" is like Python's import\n  # It does not affect current bindings,\n  #   but returns a module object containing \n  #   all vars defined in the imported file\n  \n  # import.wtf\n  b = import(\"./b\");\n  puts(b);      # =\u003e \u003cmodule ./b.wtf\u003e\n  puts(b::B);   # =\u003e 1\n```\n\n- Pattern Matching\n\n```\n  let {a: a} = {a: 1};\n  let {b: [b, c]} = {b: [2, 3]};\n  puts(a);\n  puts(b);\n  puts(c);\n  \n  let d = 4;\n  let {} = {};\n  let [] = [];\n  let [{e: e}] = [{e: 5}];\n  puts(d);\n  puts(e);\n  \n  let [f, g, _] = [1, 2, 3];\n  let [h, i, *j] = [1, 2, 3, 4, 5];\n  puts(j);\n  \n  let k, l, m = [4, 5, 6];\n  puts(k);\n\n  let n: {p: p}, o: o = {n: {p: 5}, o: 8};\n  puts(p);\n  \n  # case-when statments supports pattern matching\n  fn = -\u003e(a) {\n    case (a) {\n      when (1) {\n        \"a\";\n      }\n      when ({x: x}) {\n        x;\n      }\n      else {\n        Nil;\n      }\n    };\n};\n\nputs(fn(1));\nputs(fn({x: \"x\"}));\nputs(fn(\"abc\"));\n```\n\n- Exceptions\n```\n  secure {\n    let [a, b, c, d] = [1, 2, 3];\n  } rescue {type: type, message: message} {\n    puts(\"rescue\");\n    puts(to_s(type));\n  };\n```\n\n- Misc\n```\n  # \"eval\" is not so \"evil\"\n  puts(eval(\"-\u003e { puts(2+3); }\")());\n  \n  # Command Line Arguements\n  puts(ARGV);\n```\n\n### TODOs\n- syntax\n  - regex\n  - map pattern matching on fn_def\n  - if no-else, if elsif else\n\n- stdlib\n  - math\n  - io\n  - promise\n  \n### Language Design \n\n1. Main Goals\n    1. Make the programmers happy.\n    1. Functional.\n    1. What-you-see-is-what-you-get syntax.\n    1. Simple basic syntax plus syntax sugars.\n    1. Code fast, cod short.\n    1. Do not refactor, rewrite it.\n    1. Ruby inter-ops.\n    1. Threads are shit.\n    \n### Design Details\n\n- wtf.rb\n    - Interpret executable\n    \n- lexer.rb\n    - Lexer\n    \n- parse.y\n    - yacc-like parser\n    \n- eval.rb\n    - Implement \"eval\"-like functions in Ruby\n    - e.g. eval(str), require(file), import(file)\n \n- vm.rb\n    - Interpreter virtual machine\n    - The virtual machine executes AST nodes\n    \n- api.rb\n    - Ruby inter-ops\n    \n- ast/nodes.rb\n    - AST Node definitions \n\n- stdlib/kernel.rb\n    - Basic wtf data types and kernel functions in Ruby\n    \n- How the interpreter runs your code\n    1. Parser runs, and drives the lexer. Generate an AST.\n        - Each node knows its children\n    1. AST traversal 1\n        - Each node knows its parent, and the interpreter knows the entry point\n    1. Evaluate the AST node of the \"main\" function\n    \n- Ruby and wtf objects\n    1. Each wtf object type is a WtfType objects\n    1. wtf exception is Ruby Wtf::Lang::Exception::WtfError\n\n- Bindings\n    1. Bindings change only at function or module definitions or ensure..rescue block\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa1exwang%2Fwtf-interp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa1exwang%2Fwtf-interp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa1exwang%2Fwtf-interp/lists"}