{"id":24605869,"url":"https://github.com/flofriday/moose","last_synced_at":"2025-05-05T18:33:54.646Z","repository":{"id":37434211,"uuid":"493232315","full_name":"flofriday/Moose","owner":"flofriday","description":"🐐 A new fun programming language","archived":false,"fork":false,"pushed_at":"2022-10-12T15:06:26.000Z","size":641,"stargazers_count":5,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-30T22:51:13.559Z","etag":null,"topics":["programming-language"],"latest_commit_sha":null,"homepage":"","language":"Swift","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/flofriday.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}},"created_at":"2022-05-17T12:02:04.000Z","updated_at":"2024-10-24T15:10:40.000Z","dependencies_parsed_at":"2023-01-19T12:18:26.886Z","dependency_job_id":null,"html_url":"https://github.com/flofriday/Moose","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flofriday%2FMoose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flofriday%2FMoose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flofriday%2FMoose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flofriday%2FMoose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flofriday","download_url":"https://codeload.github.com/flofriday/Moose/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252553421,"owners_count":21766885,"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":["programming-language"],"created_at":"2025-01-24T16:32:46.914Z","updated_at":"2025-05-05T18:33:54.629Z","avatar_url":"https://github.com/flofriday.png","language":"Swift","readme":"# 🐐 Moose\n\u003cp\u003e    \n    \u003ca href=\"https://github.com/flofriday/Moose/actions/workflows/moose-tests.yml\" alt=\"Moose Tests\"\u003e\n        \u003cimg src=\"https://github.com/flofriday/Moose/actions/workflows/moose-tests.yml/badge.svg?branch=main\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://codecov.io/gh/flofriday/moose\" alt=\"Codecov\"\u003e\n        \u003cimg src=\"https://codecov.io/gh/flofriday/moose/branch/main/graph/badge.svg\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n**Moose** is a new programming language. This repo also includes an interpreter\nwritten in [Swift](https://www.swift.org/).\n\n## Try it out\n\n**Note:** We only support macOS, iOS and Linux. On Windows you can use WSL.\n\nYou need to [install swift](https://www.swift.org/download/), after which you can run:\n\n```bash\nswift run Moose\n```\n\nOr if you want to have an optimized build you can build and run with:\n\n```bash\nswift build -c release\n./.build/release/Moose\n```\n\nThe interpreter also accepts a single file:\n\n```bash\n./.build/release/Moose Examples/ticktacktoe.moose\n```\n\n## Status\n\nAt the moment we have already implemented all features we wanted. However,\nplease consider that this was mainly a learning experience. We might continue\nworking on it and playing with things that are interesting to us.\n\n## Getting Started\n\nThe rest of this file is and introduction to the language which tries to\nintroduce the core ideas.\n\nFurthermore, there are some examples in the\n[Examples](https://github.com/flofriday/Moose/tree/main/Examples) folder and\nthere is a full documentation of the quite small standard library in\n[Stdlib.md](https://github.com/flofriday/Moose/blob/main/Stdlib.md)\n\n## Types\n\nThere are only 4 built in types in Moose: `Int, Float, String, Bool`\n\n## Variables\n\nMoose provides two types of variables: immutable and mutable variables.\n\n### Mutable Variables\n\nMutable variables are variables that can be reassigned over and over again. To declare a mutable variable, the keyword `mut` must be used.\n\n```dart\nmut a = 2\na = 4\na +: 1\n\nmut b: Int\nb = 2\n```\n\n### Immutable Variables\n\nWhile mutable variables need to be declared using the `mut` keyword, immutable variables don’t have such a keyword. They also have to be assigned directly on the declaration, since the declaration without explicit initialisation is initialised with `nil`.\n\n```dart\na = 3;\na = 2; // Error, cannot reassign immutable variable\n```\n\n```dart\nb: Int;\nb; // nil\nb = 3; // Error, cannot reassign immutable variable\n```\n\n```dart\nb: Int = 3;\nb; // 3\n```\n\n## Nil\n\nEvery object can be `nil`, and since even basic types are objects they can be `nil` too.\n\n```dart\ncookie: Int = nil; // Basic types can be nil\nstrudel: Int; // Implizitly without assigning a value a variable is automatically nil.\n```\n\nTo make working with null more ergonomic, we introduced the double questionmark operator `??`\n\n```dart\nbreakfast: String = nil;\nprintln(breakfast ?? \"Melage and semmel\");\n\n// This code is just syntactic sugar and is equivalent to\nprintln(breakfast != nil ? breakfast : \"Melage and semmel\");\n```\n\n## Lists\n\nLists are arrays that can grow and shrink dynamically. Moreover there is a special syntax to create them, with square brackets. Lists also only contain objects of a single type.\n\n```dart\nwishlist: [String] = [\"Computer\", \"Bicycle\", \"Teddybear\"];\n\nprintln(wishlist[0]); // \"Computer\"\nprintln(wishlist[-1]); // \"Teddybear\"\n\nwishlist.append(\"car\");\nwishlist.append([\"Aircraftcarrier\", \"Worlddomination\"]);\n```\n\n## Dicts\n\nDictionaries (aka Hashtables or Hashmaps) are also build in.\n\n```dart\nages: {String:Int} = {\n    \"Flo\": 23,\n    \"Paul\": 24,\n    \"Clemens\": 7,\n}\n\nprintln(ages[\"Paul\"]) // 24\n\nprintln(ages.contains(\"Paul\")) // true\nages.remove(\"Paul\")\nprintln(ages.contains(\"Paul\")) // false\n```\n\n## If Else\n\nLike go and rust we don’t require Parenteses around the condition but do require braces around the body.\n\n```dart\nage = 23\nif age \u003e 18 {\n    println(\"Please enter\")\n} else if age == 18 {\n    println(\"Finally you can enter\")\n} else {\n    println(\"I am sorry come back in a year\")\n}\n\n// Sometimes you need to discriminate against Pauls\nname = \"Paul\"\nif (age \u003e 12) \u0026\u0026 (name != \"Paul\") {\n    println(\"Welcome to the waterpark\")\n}\n\n```\n\n## For\n\n`for` is the only loop in the language and is used as a foreach, C-Style for loop or like a while loop.\n\n```dart\n// For-each style\nfor i in range(10) {\n    println(\"I was here\")\n}\n\n// C-style loop\nfor i = 0; i \u003c 100; i +: 3 {\n    println(i)\n}\n\n// while style loop\nfor true {\n    println(\"I will never terminate\")\n}\n```\n\n## Comments\n\nComments are written with `//`, which comments out the rest of the line.\n\n```dart\na = 3; // this is a comment\n```\n\n## Functions and Operators\n\n### Classic Functions\n\n```dart\nfunc myFunction(age: Int, name: String) \u003e String {\n    return \"Hi I am \" + name + age.toString()\n}\n\nprintln(myFunction(42, \"Alan Turing\"))\n```\n\n### Operator Functions\n\nBeside classic functions, Moose provides the possibility to write own operators for own types. In fact, all operators have a function implementation. There are 3 types of operator functions: `prefix`, `infix` and `postfix`\n\n```dart\n// What if JS was right with adding numbers to strings?\ninfix + (a: String, b: Int) \u003e String {\n    return a + b.toString()\n}\n\n// A prefix + makes numbers positive\nprefix + (a: Int) \u003e Int {\n    if a \u003c 0 {\n        return a * -1\n    }\n    return a\n}\n\na = \"4\"\nb = 12\n\nc = a + b\nprintln(c) // 412\n\nmut d = -2\nprintln(+d) // 2\n```\n\n### Print Objects\n\nEach object has a default implementation of `represent()` that returns a string with all the fields and their values of the object. By assigning the object to a `String` variable or a parameter, the `represent()` function is called internally.\n\n```dart\np = Person(\"Alan Turing\", 41)\n\nprintln(p)\n// equivalent to\nprintln(p.represent())\n// Person: {name: \"Alan Turing\", age: 41}\n```\n\n## Classes and Objects\n\n```dart\nclass Person {\n    name: String\n    age: Int\n\n    func hello() {\n        // Instead of this, Moose uses me\n        println(\"Hey I am \" + me.name)\n    }\n}\n\n// Classes have a default constructor in which all all fields have to be filled out\nanna = Person(\"Anna\", 74)\nanna.hello()\n```\n\n## Inheritance\n\nMoose supports single class inheritance.\n\n```dart\nclass Employee \u003c Person {\n    work: String\n\n    func hello() \u003e String {\n        print(\"Hi I am \" + me.name + \" and I work at \" + me.work)\n    }\n}\n\ncatrin = Employee(\"Google\", \"Catrin\", 56 )\ncatrin.hello()\n```\n\n## Extending Classes\n\nYou extend existing classes by using the `extend` construct.\n\n```dart\nextend Person {\n    func wasBorn() \u003e Int {\n        return 2022 - me.age\n    }\n}\n\nj = Person(\"Johannes\", 23)\nprintln(j.wasBorn())\n```\n\n## Tuple\n\nIn Moose, tuples are a standard data type, like Int, String and others. It also allows programmers to return multiple values from a function and offers the possibility of unpacking.\n\n```dart\nperson = (\"luis\", 17, false)\n\n// Without unpacking\nname1 = person.0\nage1 = person.1\nmarried1 = person.2\n\n// With unpacking\n(name2, age2, married2) = person\n\nprintln(name1 == name2)\n```\n\n### Unpacking Objects\n\nUnpacking is not only possible for tuples themselves, but also for objects, where the tuple contains the first n object fields.\n\n```dart\np = Person(\"Alan Turing\", 41)\n(name, age) = p\n```\n\n## Indexing\n\nAccessing data of an object is not only possible for `List` s, but for all datatypes that implement the `getItem(Int)` method. Similarly the `setItem(Int, Any)` allows to write at an index.\n\n```dart\nclass Person {\n    name: String\n\n    func getItem(i: Int) \u003e (String) {\n        return name[i]\n    }\n}\n\np = Person(\"Alan Turing\")\n\nprintln(p[0]) // \"A\"\n```\n\n## Error handling and Panics\n\nMoose has two types of error handling. Unlike exceptions panics are unrecoverable\nerrors, which will cause the interpreter stop execution and exit with a\nnon-zero exit code.\n\n```dart\na: Int = nil\nb = a + 3       // NIlUsagePanic\n\nl = [1, 2, 3]\nx = l[9000]     // OutOfBoundsPanic\n```\n\nFor recoverable errors the convention is to return a tuple, where the last\nelement is a string with an error message. If the error is nil everything\nsucceeded, whereas if an error occurred it will be a message describing the\nreason.\n\n```dart\n(mail, err) = open(\"mail.txt\")\nif err != nil {\n    println(\"Oh no I cannot read the mail because: \" + err)\n    exit(1)\n}\n\nprintln(mail)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflofriday%2Fmoose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflofriday%2Fmoose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflofriday%2Fmoose/lists"}