{"id":15692298,"url":"https://github.com/healeycodes/hoot-language","last_synced_at":"2025-06-12T14:09:16.526Z","repository":{"id":112378143,"uuid":"347496061","full_name":"healeycodes/hoot-language","owner":"healeycodes","description":"🦉 A general-purpose interpreted scripting language with an event loop.","archived":false,"fork":false,"pushed_at":"2021-03-14T22:23:44.000Z","size":661,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T02:39:35.829Z","etag":null,"topics":["crafting-interpreters","lox","lox-language","programming-language","tree-walk-interpreter"],"latest_commit_sha":null,"homepage":"","language":"Python","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/healeycodes.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2021-03-13T22:49:52.000Z","updated_at":"2025-01-10T20:44:39.000Z","dependencies_parsed_at":"2023-05-14T04:00:09.626Z","dependency_job_id":null,"html_url":"https://github.com/healeycodes/hoot-language","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/healeycodes/hoot-language","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fhoot-language","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fhoot-language/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fhoot-language/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fhoot-language/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/healeycodes","download_url":"https://codeload.github.com/healeycodes/hoot-language/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/healeycodes%2Fhoot-language/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259479617,"owners_count":22864363,"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","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":["crafting-interpreters","lox","lox-language","programming-language","tree-walk-interpreter"],"created_at":"2024-10-03T18:31:06.760Z","updated_at":"2025-06-12T14:09:16.498Z","avatar_url":"https://github.com/healeycodes.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hoot Lang 🦉\n\nHoot is a general-purpose interpreted scripting language with an event loop. It's dynamically typed, with classes, inheritance, and closures. It's an implementation and extension of the [Lox](https://github.com/munificent/craftinginterpreters) Programming language.\n\nHoot extends Lox by introducing an event loop for non-blocking I/O, more complex types (string, list, map), and a tiny standard library (web requests, file reading/writing, delay functions).\n\nWhy? I wrote it to learn more about interpreters! [Crafting Interpreters](https://craftinginterpreters.com/contents.html) is a useful handbook and I strongly recommend it.\n\n\u003cbr\u003e\n\nHoot uses (mostly-typed) Python 3.8 and no additional libraries.\n\nRun the integration tests with `python test_hoot.py`. It should also pass `mypy .` with no issues.\n\nRun a program with `python hoot.py ./file.hoot`.\n\nOpen the REPL with `python hoot.py`.\n\n\u003cbr\u003e\n\n* [Example programs](#example-programs)\n* [Language reference](#language-reference)\n* [Standard library](#standard-library)\n* [License](#license)\n\n\u003cbr\u003e\n\n## Example programs\n\nPrint the headers from a HTTP response.\n\n```\nfun print_headers(response) {\n    print response.headers; // This is a map()\n}\n\nrequest(\"https://google.com\", nil, nil, \"GET\", print_headers);\n\nprint \"This message will print before print_headers is called.\";\n```\n\n\u003cbr\u003e\n\nDelay a function.\n\n```\nfun make_logger(time) {\n    fun logger () {\n        print string(time) + \"ms\";\n    }\n    return logger;\n}\n\ndelay(make_logger(0), 0); // 0ms delay\n\nprint \"This message prints first because each task 'Runs-to-completion' a la JavaScript\";\n\ndelay(make_logger(50), 50);\ndelay(make_logger(100), 100);\n```\n\n\u003cbr\u003e\n\nEveryone's favorite inefficient sorting algorithm.\n\n```\nfun bubble_sort(numbers) {\n    for (let i = 0; i \u003c numbers.length() - 1; i = i + 1) {\n        for (let j = 0; j \u003c numbers.length() - 1; j = j + 1) {\n            if (numbers.at(j) \u003e numbers.at(j + 1)) {\n                let tmp = numbers.at(j);\n                numbers.alter(j, numbers.at(j + 1));\n                numbers.alter(j + 1, tmp);\n            }\n        }\n    }\n    return numbers;\n}\n\n\nlet unordered_numbers = list(1, -1, 0.5, 12, 2);\nprint bubble_sort(unordered_numbers);\n```\n\n\u003cbr\u003e\n\nRead a file, print the length, append to it, then print the new length.\n\n```\nfun show_length(text) {\n    print \"File length: \" + string(text.length());\n}\n\nfun show_original_length(text) {\n    print \"File length: \" + string(text.length());\n    \n    fun callback() {\n        read(\"examples/test_file.txt\", show_length);\n    }\n    write(\"examples/test_file.txt\", \"a\", \"More text\", callback);\n}\n\nread(\"examples/test_file.txt\", show_original_length);\n```\n\n\u003cbr\u003e\n\n## Language reference\n\nVariables\n\n```\nlet bool = true; // or `false`\nlet num = 0; // All numbers are floats and support `+`, `-`, `*`, `/`\nlet raw = \"raw string\"; // Strings support `+`\n\n// Compare with `==`\n```\n\n\u003cbr\u003e\n\nTypes\n\n```\n// string has `at(index)`, `alter(index, element)`, `length()`\nlet some_text = string(\"Hello, World!\");\nsome_text.alter(12, \"?\");\nprint some_text; // \"Hello, World?\"\n\n// list has `at(index)`, `alter(index, element)`, `length()`, `push(element)`, and `pop()`\nlet some_numbers = list(1, -1, 0.5, 12, 2);\nprint some_numbers.at(1); // -1\n\n// map has `get(key)` and `set(key, element)`\nlet food_store = map();\nfood_store.set(\"burgers\", 20);\n```\n\n\u003cbr\u003e\n\nLoops\n\n```\nfor (let i = 0; i \u003c 5; i = i + 1) {\n    print i;\n}\n\nwhile (true) {\n    print \"Um.. let's quit this infinite loop.;\n    break;\n}\n```\n\n\u003cbr\u003e\n\nFunctions/closures\n\n```\nfun make_adder(y) {\n   fun adder(x) {\n       return x + y;\n   }\n   return adder;\n}\n\nlet my_adder = make_adder(10);\nadder(5); // 15\n```\n\n\u003cbr\u003e\n\nClasses\n\n```\n// Lifted this example straight from chapter 13 of Crafting Interpreters\nclass Doughnut {\n  init() {\n    this.ending_mark = \"!\";\n  }\n  cook() {\n    print \"Fry until golden brown.\";\n  }\n}\n\nclass BostonCream \u003c Doughnut {\n  cook() {\n    super.cook();\n    print \"Pipe full of custard and coat with chocolate\" + this.ending_mark;\n  }\n}\n\nBostonCream().cook();\n```\n\n\u003cbr\u003e\n\n## Standard library\n\nSee `native.py` for implementation details.\n\n\u003cbr\u003e\n\n`input(prompt)` — Returns standard input.\n\n`read(file_path, callback)` — reads a UTF-8 compatible file and passes it as the first argument to _callback_.\n\n`write(file_path, mode, data, callback)` — writes _data_ to a file. _mode_ is the same as Python's `open`. Calls _callback_ without passing any arguments.\n\n`clock()` — UNIX seconds.\n\n`delay(milliseconds, callback)` — like setTimeout in JavaScript.\n\n`request(url, data, headers, http_method, callback)` — _callback_ is passed a response instance with the fields `body` and `header` which can be accessed via `.` dot.\n\n\u003cbr\u003e\n\n## License\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhealeycodes%2Fhoot-language","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhealeycodes%2Fhoot-language","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhealeycodes%2Fhoot-language/lists"}