{"id":16301940,"url":"https://github.com/scmorrison/perl6-fp-notes","last_synced_at":"2025-07-03T20:33:27.223Z","repository":{"id":77431120,"uuid":"89774521","full_name":"scmorrison/perl6-fp-notes","owner":"scmorrison","description":"Notes on functional programing techniques with Perl 6","archived":false,"fork":false,"pushed_at":"2017-04-30T08:44:01.000Z","size":3,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T01:18:58.414Z","etag":null,"topics":["functional-programming","perl6"],"latest_commit_sha":null,"homepage":null,"language":null,"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/scmorrison.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-04-29T09:01:33.000Z","updated_at":"2017-04-29T09:06:58.000Z","dependencies_parsed_at":"2023-10-26T21:32:49.461Z","dependency_job_id":null,"html_url":"https://github.com/scmorrison/perl6-fp-notes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/scmorrison/perl6-fp-notes","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scmorrison%2Fperl6-fp-notes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scmorrison%2Fperl6-fp-notes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scmorrison%2Fperl6-fp-notes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scmorrison%2Fperl6-fp-notes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scmorrison","download_url":"https://codeload.github.com/scmorrison/perl6-fp-notes/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scmorrison%2Fperl6-fp-notes/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263400182,"owners_count":23460839,"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":["functional-programming","perl6"],"created_at":"2024-10-10T20:56:04.218Z","updated_at":"2025-07-03T20:33:27.200Z","avatar_url":"https://github.com/scmorrison.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Notes on functional programming with Perl 6\n\n### Table of Contents\n\n* __[Prelude](#prelude)__\n* __[Notes](#notes)__\n    * [Immutability](#immutability)\n* __[Getting Involved](#getting-involved)__\n* __[Copying](#copying)__\n    * [License](#license)\n    * [Attribution](#attribution)\n\n## Prelude\n\n[Perl 6] is a multi-paradigm programming language that offers several features that make writing in a functional style simple, most of the time. Perl 6 is not a _*pure*_ functional programming language and shouldn't be treated as such. This repository was created to document various FP solutions and approaches using Perl 6.\n\n**Note**: This is not to be considered the **one_true_way_to_write_perl_6** in any paradigm.\n\n## Notes\n\n### Immutability\n\n* See the following articles regarding Immutability in Perl 6:\n  * [Perl 6 Information Model]\n  * [Rosetta Code - Enforced immutability#Perl 6]\n\n* The following built-in types are considered immutable: \n\n| Type          | Description                                                  |\n|---------------|--------------------------------------------------------------|\n|**Str**        | Perl string (finite sequence of Unicode characters)          |\n|**Int**        | Perl integer (allows Inf/NaN, arbitrary precision, etc.)     |\n|**Num**        | Perl number (approximate Real, generally via floating point) |\n|**Rat**        | Perl rational (exact Real, limited denominator)              |\n|**FatRat**     | Perl rational (unlimited precision in both parts)            |\n|**Complex**    | Perl complex number                                          |\n|**Bool**       | Perl boolean                                                 |\n|**Exception**  | Perl exception                                               |\n|**Block**      | Executable objects that have lexical scopes                  |\n|**Seq**        | A list of values (can be generated lazily)                   |\n|**Range**      | A pair of Ordered endpoints                                  |\n|**Set**        | Unordered collection of values that allows no duplicates     |\n|**Bag**        | Unordered collection of values that allows duplicates        |\n|**Enum**       | An immutable Pair                                            |\n|**Map**        | A mapping of Enums with no duplicate keys                    |\n|**Signature**  | Function parameters (left-hand side of a binding)            |\n|**Capture**    | Function call arguments (right-hand side of a binding)       |\n|**Blob**       | An undifferentiated mass of ints, an immutable Buf           |\n|**Instant**    | A point on the continuous atomic timeline                    |\n|**Duration**   | The difference between two Instants                          |\n\n* Use the bind `:=` infix for scalars, which defaults to 'ro':\n\n  ```perl6\n  my $name := \"Camelia\";\n  $name = \"Elaine\";\n  \n  Cannot assign to an immutable value\n    in block \u003cunit\u003e at \u003cunknown file\u003e line 1\n  ```\n  \n  Keep in mind, you can still re-bind using `:=`:\n\n  ```perl6\n  my $name := \"Camelia\";\n  $name := \"Elaine\";\n  Elaine\n  ```\n\n* Lists without containers are `ro` immutable, use Lists instead of Arrays (@) for listy things:\n\n  ```perl6\n  my $list = (1, 2, 3);\n  push $list, 4;\n  Cannot call 'push' on an immutable 'List'\n    in block \u003cunit\u003e at \u003cunknown file\u003e line 1\n  ```\n\n  \u003e A list is immutable, which means you cannot change the number of elements in a list. But if one of the elements happens to be a scalar container, you can still assign to it. [[1]]\n\n  In this example `$list[0]` is a `rw` container, `$x`, with a value of `42`. This will allow replacing the value inside the `$x` scalar container:\n\n  ```perl6\n  my $x = 42;\n  my $list = ($x, 1, 2);\n  $list[0] = 23;\n  say $x;                 # 23\n  ```\n\n  Instead, bind the `Int` value to `$x` which which creates a `ro` container:\n\n  ```perl6\n  my $x := 42;\n  my $list = ($x, 1, 2);\n  $list[0] = 23;     # Error\n  Cannot modify an immutable Int\n    in block \u003cunit\u003e at \u003cunknown file\u003e line 1\n  ```\n\n  This example tries replacing the value of `$list[1]`, which is an immutable `Int`:\n\n  ```perl6\n  my $x = 42;\n  my $list = ($x, 1, 2);\n  $list[1] = 23;     # Error\n  Cannot modify an immutable Int\n    in block \u003cunit\u003e at \u003cunknown file\u003e line 1\n  ```\n\n  Use Array (@) in subroutine signatures for FP-style list processing of slurpy subparams. Lists will not work here. The new `@` Array is `ro` immutable within the scope of the subroutine:\n\n  ```perl6\n  multi sub do-sum([$head, *@tail] ) { do-sum( $head, @tail ); };\n  multi sub do-sum($total, [$head, *@tail] ) { do-sum( $total + $head, @tail ); };\n  multi sub do-sum($total, [] ) { $total; };\n\n  my List $list = (1,2,3,4);\n  do-sum($list);\n\n  # Attempting to modify an subparameter Array inside its subrouting\n  sub edit-param(($head, *@tail)) {\n    @tail[2] = 30;  # Error\n    return ($head, @tail).flat;\n  };\n\n  say edit-param((1,2,3,4));\n    Cannot modify an immutable Int\n  ```\n\n  Use Map for associative Arrays / Hash like behavior:\n\n  ```perl6\n  my Map $list = (name =\u003e \"Camelia\", email =\u003e \"camelia@perl6.tld\").Map\n  Map.new((:email(\"camelia\\@perl6.tld\"),:name(\"Camelia\")))\n  say $list\u003cname\u003e;\n  Camelia\n\n  # Try modifying $list\u003cname\u003e\n  $list\u003cname\u003e = \"Steve\";\n  Cannot modify an immutable Str\n    in block \u003cunit\u003e at \u003cunknown file\u003e line 1\n\n  # Try adding a new key-value pair\n  $list\u003cemail\u003e = \"camelia@perl6.tld\";\n  Cannot modify an immutable Mu\n    in block \u003cunit\u003e at \u003cunknown file\u003e line 1\n  ```\n\n## Getting Involved\n\nWhen you submit a PR and it gets merged, you will be automatically added as a collaborator, but if you wouldn't like to be added, please mention it in your submission.\n\nThe larger Perl 6 community is very approachable and does a great job of answering questions and helping those new to Perl 6. If you're looking for other projects to contribute to please see the [Perl 6 Most Wanted Modules][Perl 6 Most Wanted].\n\n## Copying\n\n### License\n\n![Creative Commons License](http://i.creativecommons.org/l/by/3.0/88x31.png)\nThis work is licensed under a\n[Creative Commons Attribution 3.0 Unported License][license]\n\n### Attribution\n\nhttps://github.com/scmorrison/perl6-fp-notes/graphs/contributors\n\n\u003c!-- Links --\u003e\n[FP Notes on Perl 6 (this repo)]: https://github.com/scmorrison/perl6-fp-notes\n[Perl 6]: http://perl6.org\n[Perl 6 Most Wanted]: https://github.com/perl6/perl6-most-wanted\n[Perl 6 Information Model]: http://www.dlugosz.com/Perl6/web/info-model-1.html\n[Rosetta Code - Enforced immutability#Perl 6]: https://rosettacode.org/wiki/Enforced_immutability#Perl_6\n[1]: https://docs.perl6.org/language/containers.html#Scalar_containers_and_listy_things\n[license]: http://creativecommons.org/licenses/by/3.0/deed.en_US\n[Elixir Style Guide]: https://github.com/levionessa/elixir_style_guide\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscmorrison%2Fperl6-fp-notes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscmorrison%2Fperl6-fp-notes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscmorrison%2Fperl6-fp-notes/lists"}