{"id":20372863,"url":"https://github.com/sidmishraw/fjava","last_synced_at":"2026-05-29T06:31:36.358Z","repository":{"id":86400563,"uuid":"93109938","full_name":"sidmishraw/fjava","owner":"sidmishraw","description":"FJava, Java for functional programming","archived":false,"fork":false,"pushed_at":"2017-06-06T04:29:25.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-15T06:48:38.951Z","etag":null,"topics":["fjava","functional-programming","java8"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sidmishraw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2017-06-02T00:09:57.000Z","updated_at":"2017-06-02T02:12:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"c5ff4e2a-6748-4dfc-965d-270646027165","html_url":"https://github.com/sidmishraw/fjava","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/sidmishraw%2Ffjava","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidmishraw%2Ffjava/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidmishraw%2Ffjava/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sidmishraw%2Ffjava/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sidmishraw","download_url":"https://codeload.github.com/sidmishraw/fjava/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241921836,"owners_count":20042763,"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":["fjava","functional-programming","java8"],"created_at":"2024-11-15T01:15:17.592Z","updated_at":"2026-05-29T06:31:36.349Z","avatar_url":"https://github.com/sidmishraw.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FJava\n\n-----------------------------------------------------\n*****************************************************\n\nAuthor - Sidharth Mishra\n\nAdvisor - Dr. Jon Pearce\n\n*****************************************************\n-----------------------------------------------------\n\n**FJava** is a functional take on Java.\n\n\nTo summarize it is:\n ```\n    JAVA - {assignment, iteration, mutable datastructures}\n ```\n\nAn example program using **FJava** would look like:\n```java\n\npackage io.github.sidmishraw.fjava;\n\nimport io.github.sidmishraw.fjava.core.Variable;\n\n/**\n * Created by sidmishraw on 6/1/17.\n * \u003cp\u003e\n * This is the test driver for FJava, just to test out the language features\n */\npublic class TestDriver {\n\n\tpublic static void main(String[] args) {\n\n\t\tVariable\u003cString\u003e variable = new Variable\u003c\u003e(\"Hello\");\n\n\t\tvariable.print();\n\n\t\tSystem.out.println(String.format(\"The value of the variable: %s\", variable.get()));\n\n\t\tvariable.set(\"bye\");\n\n\t\tvariable.print();\n\n\t\tSystem.out.println(String.format(\"The value of the variable: %s\", variable.get()));\n\n\t\tvariable.delete();\n\n\t\tSystem.out.println(\"Done testing\");\n\t}\n}\n```\n\nConsole output:\n```\nHello\nThe value of the variable: Hello\nvariable = bye\nThe value of the variable: bye\nFetching val\nThe value of the variable: null\nDone testing\n```\n\n### Variable\nThe `variable(s)` in FJava are **active**. \n\nThey have their own thread of control. The operations on them are simple messages with opcode and a value. \nThese messages are executed inside the `controlLoop`. \n\nThe `controlLoop` is an **infinite tail-recursive \nfunction** that maintains the state of the variable and also executes the operations \nasked of the variable.\n\nFor the toy implementation, we have 4 basic operations on the Variable:\n\n* **GET** - It gets the current state value of the Variable.\n* **SET** - It updates the state of the Variable. This is used instead of normal \nassignment operator to update the state.\n* **DELETE** - It stops the Variable's thread of control stopping the variable\n* **PRINT** - It prints the current state of the Variable to the standard output \n(console).\n\nThe operations are messages that are dumped into the message queue of the Variable when\n the corressponding operations are invoked. \n \n For eg: When the `variable.get()` method is\n  invoked on the Variable, a message containing `GET` opcode is pushed into the message\n   queue. The controlLoop finds this message and executes it to give the value desired.\n\n#### Assignment:\n\nWhen I say `assignment`, I mean situations where we are modifying the state of \nthe variable.\n\nFor eg:\n```\nString variable = \"Hello\";          // This is not assignment but initialization\n\nvariable = \"Bye\";                   // Now this is assignment since I'm trying to\n                                    // modify the value of the variable that is already\n                                    // initialized.\nvariable = variable + \"and bye!\";   // is also considered as assignment \n```\n\n#### Iteration:\n\nBy `iteration` I refer to all the loop constructs in Java(`for`, `while`, `do-while` etc.)\nThere is no room for these loop constructs in **FJava**.\n\n**Iteration** is acheived by `tail-recursion`.\n\n##### What is tail-recursion?\n[The accepted answer of this stackexchange question is pretty good](https://cs.stackexchange.com/questions/6230/what-is-tail-recursion)\n\n\nTail recursion is a special case of recursion where the calling function does no more computation after making a recursive call.\nWhen we make a normal recursive call, we have to push the return address onto the call stack then jump to the called function.\nWhen we have tail recursion we know that as soon as we return from the recursive call we're going to immediately return as well, so we can skip the entire chain of recursive functions returning and return straight to the original caller. \nThat means we don't need a call stack at all for all of the recursive calls, and can implement the final call as a simple jump, which saves us space.\n\nFor eg:\n\n```\n// decrementByOne() is tail-recursive\nint decrementByOne(int nbr, int times) {\n\t\n\tif (times == 0) {\n\t\t\n\t\treturn nbr;\n\t}\n\t\n\treturn decrementByOne(nbr - 1, --times); \n}\n\n// g is not tail recursive\n// It requires extra stack space to hold values for the computations and the recursion \n// chain.\nint g(int x) {\n\t\n  if (x == 1) {\n  \t\n    return 1;\n  }\n\n  int y = g(x-1);\n\n  return x*y;\n}\n```\n\n#### Mutable Datastructures:\n\n`Mutable data-structures` are not allowed in FJava. \nBut, message queues are allowed since these are used for holding the messages that \nallow the variables to execute the operations asked of it.\n\n\n#### Toy project/examples using FJava:\n* [Bank account manager application](https://github.com/sidmishraw/accmgrfjava)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidmishraw%2Ffjava","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsidmishraw%2Ffjava","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidmishraw%2Ffjava/lists"}