HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
moritz
json
Perl 62012–2025
moritz / json

json

A tiny JSON parser and emitter for Perl 6 on Rakudo

6Distinct people
15Mentions
0Explicit recommenders
80GitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

A tiny JSON parser and emitter for Perl 6 on Rakudo

GitHub

Where it is used

No documented product use has been verified yet.

What people are saying

No recommendation phrase was found in the indexed comments.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

No other repository is repeatedly linked in the same discussions.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 1:49:46 PM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year15 dated mentions

Observed mentions: 2012-10-08 11:10:51 UTC to 2025-06-28 21:22:52 UTC.

01232012-01-01 00:00:00 UTC to 2013-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments20122013-01-01 00:00:00 UTC to 2014-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2014-01-01 00:00:00 UTC to 2015-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2015-01-01 00:00:00 UTC to 2016-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments2016-01-01 00:00:00 UTC to 2017-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments20182019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 0 mentions; 0 submissions, 0 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 2 mentions; 0 submissions, 2 comments2025

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20122012-01-01 00:00:00 UTC2013-01-01 00:00:00 UTC101
20132013-01-01 00:00:00 UTC2014-01-01 00:00:00 UTC000
20142014-01-01 00:00:00 UTC2015-01-01 00:00:00 UTC000
20152015-01-01 00:00:00 UTC2016-01-01 00:00:00 UTC303
20162016-01-01 00:00:00 UTC2017-01-01 00:00:00 UTC101
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC202
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC303
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC000
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC101
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC101
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC000
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC000
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC101
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC202

What Hacker News says

15 sources
A use case is when a sub or method needs to do different things based on the data type of the argument. Example: turning a data structure into a JSON string, solved with multi dispatch: https://github.com/moritz/json/blob/master/lib/JSON/Tiny.pm#... Another common useful example is constructors. A Date class might have constructors that accept Date(Int, Int where 1..12, Int where 1..31) # Y, M, D Date(Str where /^\d4-\d2-\d2$/) # YYYY-MM-DD Date(DateTime) # extract the date of a DateTime object etc. to make it very intuitive to use.
In Ovld – Efficient and featureful multiple dispatch for Python
"Actual parsers" aren't powerful enough to be used to parse Raku. Raku regular expressions combined with grammars are far more powerful, and if written well, easier to understand than any "actual parser". In order to parse Raku with an "actual parser" it would have to allow you to add and remove things from it as it is parsing. Raku's "parser" does this by subclassing the current grammar adding or removing them in the subclass, and then reverting back to the previous grammar at the end of the current lexical scope. In Raku, a regular expression is another syntax for writing code. It just has a slightly different default syntax and behavior. It can have both parameters and variables. If the regular expression syntax isn't a good fit for what you are trying to do, you can embed regular Raku syntax to do whatever you need to do and return ri
Read the rest
ght back to regular expression syntax. It also has a much better syntax for doing advanced things, as it was completely redesigned from first principles. The following is an example of how to match at least one `A` followed by exactly that number of `B`s and exactly that number of `C`s. (Note that bare square brackets [] are for grouping, not for character classes.) my $string = 'AAABBBCCC'; say $string ~~ / ^ # match at least one A # store the result in a named sub-entry $<A> = [ A+ ] {} # update result object # create a lexical var named $repetition :my $repetition = $<A>.chars(); # <- embedded Raku syntax # match B and then C exactly $repetition times $<B> = [ B ** {$repetition} ] $<C> = [ C ** {$repetition} ] $ /; Result: 「AAABBBCCC」 A => 「AAA」 B => 「BBB」 C => 「CCC」 The result is actually a very extensive object that has many ways to interrogate it. What you see above is just a built-in human readable view of it. In most regular expression syntaxes to match equal amounts of `A`s and `B`s you would need to recurse in-between `A` and `B`. That of course wouldn't allow you to also do that for `C`. That also wouldn't be anywhere as easy to follow as the above. The above should run fairly fast because it never has to backtrack, or recurse. When you combine them into a grammar, you will get a full parse-tree. (Actually you can do that without a grammar, it is just easier with one.) To see an actual parser I often recommend people look at JSON::TINY::Grammar https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra... Frankly from my perspective much of the design of "actual parsers" are a byproduct of limited RAM on early computers. The reason there is a separate tokenization stage was to reduce the amount of RAM used for the source code so that further stages had enough RAM to do any of the semantic analysis, and eventual compiling of the code. It doesn't really do that much to simplify any of the further stages in my view. The JSON::Tiny module from above creates the native Raku data structure using an actions class, as the grammar is parsing. Meaning it is parsing and compiling as it goes.
In Unusual Raku Features
I'm not sure of the need to do that. Not for parsing anyway. A well designed regex system is enough without tokenization. The parser for the Raku language, for example, is a collection of regexes composed into grammars. (A grammar is a type of class where the methods are regexes.) We could probably do the token thing with multi functions, if we had to. multi parse ( 'if', $ where /\s+/, …, '{', *@_ ) {…} multi parse ( 'for', $ where /\s+/, …, '{', *@_ ) {…} … Or something like that anyway. (Note that `if` and `for` etc are keywords only when they are followed immediately by whitespace.) I'm not sure how well that would work in practice; as hypothetically Raku doesn't start with any keywords or operators. They are supposed to seem like they are added the same way keywords and operators are added by module authors. (In order
Read the rest
to bootstrap it we of course need to actually have keywords and operators there to build upon.) Since modules can add new things, we would need to update the list of known tokens as we are parsing. Which means that even if Raku did the tokenization thing, it would have to happen at the same time as the other steps. Tokenization seems like an antiquated way to create compilers. It was needed as there wasn't enough memory to have all of the stages loaded at the same time. --- Here is an example parser for JSON files using regexes in a grammar to show the simplicity and power of parsing things this way. grammar JSON::Parser::Example { token TOP { \s* <value> \s* } rule object { '{' ~ '}' <pairlist> } rule pairlist { <pair> * % ',' } rule pair { <string> ':' <value> } rule array { '[' ~ ']' <arraylist> } rule arraylist { <value> * % ',' } proto token value {*} token value:sym<number> { '-'? # optional negation [ 0 | <[1..9]> <[0..9]>* ] # no leading 0 allowed [ '.' <[0..9]>+ ]? # optional decimal point [ <[eE]> <[+-]>? <[0..9]>+ ]? # optional exponent } token value:sym<true> { <sym> } token value:sym<false> { <sym> } token value:sym<null> { <sym> } token value:sym<object> { <object> } token value:sym<array> { <array> } token value:sym<string> { <string> } token string { 「"」 ~ 「"」 [ <str> | 「\」 <str=.str_escape> ]* } token str { <-["\\\t\x[0A]]>+ } token str_escape { <["\\/bfnrt]> } } A `token` is a `regex` with `:ratchet` mode enabled (no backtracking). A `rule` is a `token` with `:sigspace` also enabled (whitespace becomes the same as a call to `<.ws>`). The only one of those that really looks anything like traditional regexes is the `value:sym<number>` token. (Raku replaced non capturing grouping `(?:…)` with `[…]`, and character classes `[eE]` with `<[eE]>`) This code was copied from https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra... but some parts were simplified to be slightly easier to understand. Mainly I removed the Unicode handling capabilities. It will generate a tree based structure when you use it. my $json = Q:to/END/; { "foo": ["bar", "baz"], "ultimate-answer": 42 } END my $result = JSON::Parser::Example.parse($json); say $result; The above will display the resultant tree structure like this: 「{ "foo": ["bar", "baz"], "ultimate-answer": 42 } 」 value => 「{ "foo": ["bar", "baz"], "ultimate-answer": 42 } 」 object => 「{ "foo": ["bar", "baz"], "ultimate-answer": 42 } 」 pairlist => 「"foo": ["bar", "baz"], "ultimate-answer": 42 」 pair => 「"foo": ["bar", "baz"]」 string => 「"foo"」 str => 「foo」 value => 「["bar", "baz"]」 array => 「["bar", "baz"]」 arraylist => 「"bar", "baz"」 value => 「"bar"」 string => 「"bar"」 str => 「bar」 value => 「"baz"」 string => 「"baz"」 str => 「baz」 pair => 「"ultimate-answer": 42 」 string => 「"ultimate-answer"」 str => 「ultimate-answer」 value => 「42」 You can access parts of the data using array and hash accesses. my @pairs = $result<value><object><pairlist><pair>; my @keys = @pairs.map( *.<string>.substr(1,*-1) ); my @values = @pairs.map( *.<value> ); say @pairs.first( *.<string><str> eq 'ultimate-answer' )<value>; # 「42」 You can also pass in an actions class to do your processing at the same time. It is also a lot less fragile. See https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Act... for an example of an actions class. --- Note that things which you would historically talk about as a token such as `true`, `false`, and `null` are written using `token`. This is a useful association as it will naturally cause you to write shorter, more composable regexes. Since they are composable, we could do things like extend the grammar to add the ability to have non string keys. Or perhaps add `Inf`, `-Inf`, and `NaN` as values. grammar Extended::JSON::Example is JSON::Parser::Example { rule pair { <key=.value> ':' <value> } # replaces existing rule # adds to the existing set of value tokens. token value:sym<Inf> { <sym> } token value:sym<-Inf> { <sym> } token value:sym<NaN> { <sym> } } This is basically how Raku handles adding new keywords and operators under the hood.
In Try APL
Roles take the place of all of these: - Java interfaces - abstract classes - C++ templates - Python mixins - Smalltalk traits So are you telling me that you haven't used any of those? --- Roles combine all of those features very simply. role Interface { method hello-world ( --> Str ) {...} # the ... means it needs to be implemented by consuming class } role Abstract { has Str $.name is required; # adds an accessor method of the same name method greet ( --> Str ) {...} } role Template[ Real ::Type, Type \initial-value ] { has Type $!value = initial-value; method get ( --> Type ) { $!value } method set ( Type \new-value ) { $!value = new-value } } my $value = 42 but anon role Mixin { method Str (
Read the rest
--> 'Life, the Universe and Everything' ){ } } Roles were heavily influenced by Smalltalk traits. Rather than being limited to those uses, Roles were expanded to include all of those other use-cases as well. --- Really Roles are a better method of code-reuse than inheritance. role Animal { method species ( --> Str ){...} method produces-egg ( --> Bool ){...} } role Mammal does Animal { method produces-egg ( --> False ){ # most mammals do not produce eggs. } } role Can-Fly { method flap-wings ( --> 'flap flap' ){ } } class Bat does Mammal does Can-Fly { method species ( --> 'Bat' ){ } } class Bird does Animal does Can-Fly { method species ( --> 'Bird' ){ } method produces-egg ( --> True ) { } } class Platypus does Mammal { method species ( --> 'Platypus' ){ } method produces-egg ( --> True ) { # override Mammal.produces-egg() } } Of course a simple example doesn't do this ability justice. It really shines on large code-bases. For a better example see: “Curtis Poe (Ovid) - Roles versus Inheritance” https://www.youtube.com/watch?v=cjoWu4eq1Tw That is of course about roles in Perl, which doesn't have all the same features. All of the points do apply to Raku roles though. --- Raku has so many good ideas it would be a waste if other languages didn't copy at least some of them. I of course can understand if a single language doesn't want to copy all of them at the same time. It would definitely be a waste if no other language tries to combine regular expressions, parsers, and objects like Raku grammars have done. At the very least Raku regular expressions are easier to understand than Perl compatible regular expressions. (Note that I very much DO understand PCRE syntax, having used it heavily in Perl for many years.) Compare the Raku grammar for JSON https://modules.raku.org/dist/JSON::Tiny:cpan:MORITZ/lib/JSO... to the Perl version https://metacpan.org/release/JSON-Decode-Regexp/source/lib/J... I would like to point out that when JSON started allowing any value as a top-level result, it actually made the Raku code simpler. https://github.com/moritz/json/commit/9888329771730574967197...
In Was Knuth Really Framed?
The way Perl 6 makes this more manageable is with grammars. (See previous post for an example) Since a grammar is just a special type of class you can put regexes into roles and compose them together. You can even inherit from another grammar if you only need to change parts of it. Also if there is something that is difficult to do regularly in the regex sub-language, it allows you to use regular Perl 6 code inline. (A regex is just a special type of method with a domain specific sub-language.) Also if there is a bug you can use Grammar::Debugger or Grammar::Tracer to help find it. (I had a bug in the earlier post and used Grammar::Tracer to find and fix it within seconds.) A Perl 6 grammar can look remarkably similar in structure to BNF. https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra... https://trac.ietf.org/trac/json/brows
Read the rest
In Designing a Good DSL
In Perl 6 regexes are a type of method, and you can use them in grammars which are a type of class. (You can use them on their own as well) Which means you can subclass grammars, compose in regexes with roles, and have parameterized regexes. The syntax has also had an overhaul to make it more consistent with itself as well as the rest of Perl 6. Since you can embed Perl 6 code, some features of other regular expression engines haven't been implemented as they aren't needed. The result of using a regex or grammar is also now a parse tree rather than True/False or the matched substring. I generally recommend reading the code for JSON::Tiny::Grammar as a quick example of what it is like. https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra...
In Exploring the Linguistics Behind Regular Expressions
> while for "parse an apache log line" you'd probably use a grammar instead of a very nasty regex. That's actually a fairly easy endeavor with perl regex capabilities, especially named captures. Parsing HTML, or a programming language, or other much more complex structures is much easier with a grammar. For example, JSON parsing[1]. That said, there are ways to approximate some features of grammars with Perl5 regexes[2]. 1: https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra... 2: http://blogs.perl.org/users/brian_d_foy/2013/10/parsing-json...
In Why I’m Learning Perl 6
I've always loved that post but the truth is that while you can not parse [X]HTML with what I'll call a "regular expression", by which I mean the formal CS definition [1], you can with a suitable "regex", by which I mean what most folk mean by the term "regex".[2] [1] https://en.wikipedia.org/wiki/Regular_expression#Formal_defi... [2] PCRE engines support recursive matching etc. but perhaps the most illuminating example is regex in Perl 6 such as this JSON grammar (a Perl 6 grammar is a class containing Perl 6 named regexes): https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra...
In You can't parse [X]HTML with regex
Your comment actually made me scroll back to the top to double check this thread was actually about Perl 6, not Perl 5! Part of the point of Perl 6 was to address problems in the language and Larry (and/or those who wrote the original Perl 6 RFCs) considered several of the things you named to be problems. > wide range of special operators, variables and default arguments In Perl 6: * The only special op I'm aware of is assignment. * The only variables considered special are the "it" and "them" variables ($_, @_ and %_), the current match object ($/), and the current exception list ($!). * There are still predefined variables, such as a DISTRO variable which contains an object representing the OS etc. on which Perl 6 is running, but I haven't found those problematic. * Almost all use of default arguments in built-ins has been eliminated. T
Read the rest
he main exception I'm aware of is that subs and ops related to matching still default to operating on "it". The Perl 5 <> op is gone. > Or, perhaps the syntax for dealing with elements in a somewhat deep data structure, like: push(@{$TV{$family}{kids}},"anotherkid"); This would be something like this in Perl 6: my %TV; my $family = 'foo'; push %TV{$family}<kids>, 'another'; > Sometimes, people are just griping about regex syntax though, which seems disingenuous, since many languages use the exact same pcre expressions. This is talked of in Perl 6 circles as being ironic because regex syntax has been thoroughly cleaned up (and massively powered up too) in Perl 6.[1] > I like perl, but if it's been a while, there's definitely some back and forth with books to decipher something I wrote some time ago. One of the many downsides to Perl 6, imo, is that this back-to-the-book-oh-yeah aspect is still there -- but there's only incomplete doc and no books yet written by the likes of Larry. [1] See, for example, https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra...
In Why Perl 6 is Different (2010)
> [lang X] doesn't handle [basic math] correctly among other things. From a recent talk[1], what are x, y, z in the following? x = 7 ÷ 2; y = -7 ÷ 2; z = .1 + .2 - .3 x y z 3.5 -3.5 0 # human 3 ? tiny number # c89; ? depends on compiler 3 -4 tiny number # ruby 3 -4 tiny number # python 2/3 3 -3 0 # bc 3.5 -3.5 tiny number # perl5 3.5 -3.5 0 # perl6 ---- It isn't just basic math. How "long" is the following string? ปฏิบัติจริง 7 characters # human len("ปฏิบัติจริง") = 33 # python 2 len("ปฏิบัติจริง") = 11 # python 3 "ปฏิบัติจริง".length = ? # ruby (For Ruby, I've found "the core language does not provide a way to count [human percei
Read the rest
ved characters]". [3] Is that still correct or out of date?) ---- > Perl suffers from having too many magical operators that makes it hard to reason about a snippet of code. I feel Python strikes the right balance. To quote Larry Wall, "Perl 6 ... has been rethought and rebalanced on every level".[4] It might be interesting for you to pick a couple Perl 5 operators that you consider too magical; then we could look at the merits and demerits of those ops in Perl 5 and their equivalents in Python and Perl 6. > It's very easy to express ideas I have in mind without worrying about the details [of Python, now, and Perl, back in the day] This, of course, has explicitly been a deliberate focus of all the Perls. Part of the point of Perl 6 was to remove the bits in Perl 5 that were problematic (including some "too cute/weird" stuff) and to introduce much nicer higher level abstractions (eg grammars instead of just regexes[5]). ---- I've long encountered vocal folk who underestimate or misunderstand Larry Wall and Perl to an absurd degree. Perl has been focused for over two decades on making it easy to get the right results when doing basic practical things (like integer division and counting characters) and, imo, that ought to be obvious to anyone who looks at the matter carefully. ---- [1] http://www.slideshare.net/Ovid/perl-6-for-mere-mortals and https://www.youtube.com/watch?v=lpu-3UF_b48 [2] http://www.reddit.com/r/perl/comments/2szv7m/beginner_progra... [3] http://unicode-programming.readthedocs.org/en/latest/count-c... [4] http://www.infoworld.com/article/2882300/perl/perl-creator-l... [5] https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra...
In The Three Great Virtues of a Programmer: Laziness, Impatience, and Hubris
= About Python regexes = Aiui "The Future of Python Regexes" SO answer at http://stackoverflow.com/a/7066413/1077672 written by regex (and Perl) expert Tom Christiansen (and last updated by him in 2012) is still good info. In brief, https://pypi.python.org/pypi/regex appears to be the path forward for Python. This engine is much closer to the power and Unicode compatibility of Perl 5's default regex engine. = About Perl 5 regexes = Aiui the default Perl 5 regex engine is significantly faster than the 're' regex feature included with Python 2. I don't know how it compares to the new 'regex' module. Regexes in Perl have the advantage/disadvantage that they are syntactically integrated in to the language (a disadvantage if you don't like it being integrated). Since Perl 5.10, a different regex engine can be plugged in and used without requir
Read the rest
ing any change in code that uses regexes (unless an engine uses a different syntax of course). (But it takes a lot of effort to package a regex engine up for use with Perl 5.) A given regex engine can be extended using the overload module. Extending is relatively easy. = About Perl 6 regexes = A whole new ball game, two decades ahead of Perl 5 regexes. http://en.wikipedia.org/wiki/Perl_6_rules http://doc.perl6.org/language/grammars https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra... Generally matches Perl 5 regexes feature-for-feature but with a much cleaner syntax. More importantly, unifies regexes and grammars. Currently way slower than Python or Perl 5 regexes. Supposedly will eventually (5 years? 10?) incorporate all the key optimizations in the Perl 5 engine and become faster than Perl 5 regexes.
In Why is perl losing its touch?
One feature which I believe is distinctly available only in Perl 6 is it's grammar feature. ( think class/method based regular expressions that look similar to BNF ) As an example look at this Perl 6 grammar for JSON: https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra... Perl 6's best feature is that it combines many features from many languages in a way that allows combining them cleanly, and without any of them feeling like they were glommed on. (unlike Perl 5's object system which was inspired by Python's object system) If you can get past the syntax differences from other languages, and program in it for a while, you may never want to go back to any other language. If you can't get past the syntax, please say that you "don't like the syntax" instead of "it's unreadable" or "it's a write-only language" or "it's difficult to l
Read the rest
earn". ( I for one found it quite easy to learn, and can read it quickly. ) --- Really can you make all of the following examples clearer in any other single language? constant powers-of-two = 2,4,8 ... *; # an infinite deductive list # perhaps that would be more clear as: constant powers-of-two = 2, 4, 8, 16, 32, 64 ... *; # list of pairs using the zip meta-operator (Z) # combined with the pair constructor operator (=>) my @a = 'a'..'z' Z=> 0..*; # ( a => 0, b => 1, etc ) my $new-password = ('a'..'z','A'..'Z',0..9).roll(12).join; # 'ygHIHbi4XgUV' # the zero in the following is to prevent an off-by-one error # when accessing by index # * + * creates a code ref that takes two inputs and numerically adds them together constant fibonacci-list = 0, 1, 1, * + * ... *; # takes about a second the first time it's accessed currently say fibonacci-list[10000].chars == 2090; # if you wanted it to look more like haskell you could write it like this: constant fibonacci-list = 0, 1, 1, &[+] ... *; my @dice-rolls := ('⚀'..'⚅').roll(*); # infinite list of dice rolls # deck of cards using the cross meta-operator (X) # and the string concatenation operator (~) my @deck = 2..10,<J Q K A> X~ <♡ ♢ ♣ ♠>; my @shuffled = @deck.pick(*); # ( .say ) is short for ( $_.say ) # prints the first 6 numbers (0..5) each on it's own line for ^6 { .say } # prints the numbers 0..5 each on it's own line, # possibly randomized, # possibly each in it's own thread ( texas version ) (0..^6)>>.say; (^6)».say; # ditto ( french version ) # ( those were purposefully misusing an auto-threading list operator >> ) # says a random number (1..5), 5 times out of 6 if (0..5).pick -> $number { say $number } if (0..5).pick { say $^number } # ditto --- That was just a sampling of the bread-and-butter constructs (some of which were used in a way that most people wouldn't use them). There are also operators for dealing with Sets for example. ( ⋃ and (elem) being two of them ) see: http://doc.perl6.org/ You can even create new operators the same way you define a subroutine ( That's all they are in the Rakudo implementation, for most of them. ) # common factorial example sub postfix:<!> ( Int \n where * >= 0 ) is tighter(&infix:<*>) { [*] 1..n } say 5!; # 120
In A little thing to love about Perl 6 and COBOL

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.