raku / examples Goto Github PK
View Code? Open in Web Editor NEWMany examples of Raku code
Home Page: https://examples.raku.org/
License: Artistic License 2.0
Many examples of Raku code
Home Page: https://examples.raku.org/
License: Artistic License 2.0
https://examples.raku.org/categories/cookbook.html
has a bulleted/numbered combo list. Should probably be bullets only
https://examples.raku.org/categories/euler.html shows this footer:
Generated on 2019-05-23T23:12:47.115161+02:00
Some are still .pl, some have been converted to .p6
solution to project euler problem 99 does not compile
$ perl6 --version
This is perl6 version 2015.06 built on MoarVM version 2015.06
perl6 prob099-andreoss.pl
Dynamic variable $*PROGRAM-NAME not found
in sub MAIN at prob099-andreoss.pl:45
in block <unit> at prob099-andreoss.pl:45
htmlify.p6 in documentation is deprecated, and theoretically Documentable should be able to work with all kind of directories with the correct configuration.
However, this program is totally different, although it's got the same name. So simply revise and maybe refactor.
Also find an infrastructure for it. I'm not sure where it is now, or who's in charge.
matthew@0xB1uE7:~/tmp/perl6-examples/categories/games$ perl6 -v
This is perl6 version 2015.09-383-gf0d4820 built on MoarVM version 2015.09-79-gee9fc2b
matthew@0xB1uE7:~/tmp/perl6-examples/categories/games$ perl6 tictactoe.p6
Index out of range. Is: 1, should be in 0..0
in block at tictactoe.p6:28
Actually thrown at:
in sub tictactoe-masak at tictactoe.p6:21
in block at tictactoe.p6:31
Fix https for examples.perl6.org
It works everywhere else.
See also @Altai-man's comment: #57 (comment)
The examples directory requires attention. I am in the process of bringing file extensions (see also #72) and shebangs inline with current Raku conventions. But further attention is required to tidy up these examples, and repair publishing.
At a high level, my view is the Raku/examples
directory should:
Commencing with the cookbook:
I propose further cookbook style recipes that offer typical programming activities and how they might be solved in Raku. Including multi paradigm examples, and alternative approaches to achieve the same result to ensure the TIMTOWTDI mindset can continue to prosper.
Currently, the Raku/examples/cookbook
is a "tip of the hat" back to the excellent Perl Cookbook.
This is fantastic for Perl 5's posterity and certainly something we should continue maintain, however it fails to showcase Raku's capabilities that make it a more modern language. For one example, concurrency. One area among others that most certainly should have multiple cookbook recipes.
TODO:
Continue to maintain and enhance the existing cookbook examples:
Running make html
fails with:
[...]
Creating category index files
Cannot resolve caller handle(Pod::To::HTML.new(de...: (Pod::Block::Table
..., 0, None, :!defn); none of these signatures matches:
(GenericPod: Nil, *%_)
(GenericPod: Str $node, Int $in-level, Context $context, *%_ --> Str)
(GenericPod: Pod::Block::Code $node, Int $in-level, Context $context = Context::InPodCode, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Comment $node, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Declarator $node, Int $in-level, Context $context, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Named $node, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Named $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Named $node where { ... }, Int $in-level, Context $context, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Named $node where { ... }, Int $in-level, Context $context, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Named $node where { ... }, Int $in-level, Context $context, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Named $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Named $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Named $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Named $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Para $node, Int $in-level, Context $context where { ... }, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Para $node, Int $in-level, Context $context, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Block::Table $node, Int $in-level, Context $context, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Defn $node, Int $in-level, Context $context, *%_ --> Str)
(GenericPod: Pod::Heading $node, Int $in-level, Context $context, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Item $node, Int $in-level is copy, Context $context, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Raw $node, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::Config $node, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::FormattingCode $node, Int $in-level, Context $context where { ... }, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::FormattingCode $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::FormattingCode $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::FormattingCode $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::FormattingCode $node where { ... }, Int $in-level, $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::FormattingCode $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str) (GenericPod: Pod::FormattingCode $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::FormattingCode $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
(GenericPod: Pod::FormattingCode $node where { ... }, Int $in-level, Context $context = Context::None, Bool :$defn = Bool::False, *%_ --> Str)
in code at /home/examples.raku.org/.raku/sources/901F1025C42CF990CDCEED32B5126CF84EFB01D3 (ProcessedPod) line 689
in method handle at /home/examples.raku.org/.raku/sources/901F1025C42CF990CDCEED32B5126CF84EFB01D3 (ProcessedPod) line 687
in code at /home/examples.raku.org/.raku/sources/901F1025C42CF990CDCEED32B5126CF84EFB01D3 (ProcessedPod) line 331
in method process-pod at /home/examples.raku.org/.raku/sources/901F1025C42CF990CDCEED32B5126CF84EFB01D3 (ProcessedPod) line 331
in method render-tree at /home/examples.raku.org/.raku/sources/901F1025C42CF990CDCEED32B5126CF84EFB01D3 (ProcessedPod) line 348
in sub pod2html at /home/examples.raku.org/.raku/sources/B724BB3B7903E7B04A25FE65B2CA6547625F99D8 (Pod::To::HTML) line 663
in method p2h at /home/examples.raku.org/examples/lib/Pod/Htmlify.pm6 (Pod::Htmlify) line 217
in method write-category-indices at /home/examples.raku.org/examples/lib/Pod/Htmlify.pm6 (Pod::Htmlify) line 136
in method build at /home/examples.raku.org/examples/lib/Pod/Htmlify.pm6 (Pod::Htmlify) line 30
in sub MAIN at htmlify.pl line 79
in block <unit> at htmlify.pl line 5
matthew@0xB1uE7:~/tmp$ perl6 -v
This is perl6 version 2015.09-383-gf0d4820 built on MoarVM version 2015.09-79-gee9fc2b
matthew@0xB1uE7:~/tmp$ perl6 ./wizard.pl
What is your name: BT
Greetings, BT
BTiscurrently in theLobby
18
Army of frogs is attacking you! What will you do?
Use of uninitialized value $choice of type Any in string context
Any of .^name, .perl, .gist, or .say can stringify undefined things, if needed. in method battle at ./wizard.pl:117
Type check failed in assignment to $!param; expected Str but got Weapon
in block at ./wizard.pl:120
in method battle at ./wizard.pl:117
in block at ./wizard.pl:217
Since https://docs.perl6.org uses now: node + atom highlights + atom-language-perl6 for syntax highlighting, it might be a good idea to do the same for http://examples.perl6.org/
I'm just reading through https://examples.p6c.dev/categories/cookbook/01strings/01-00introduction.html and I notice some (most?) of the examples don't show the expected output. Is this something that can be done automagically, or does someone need to go through and add them manually?
Example with expected output:
say '~$scalar is ', (~$scalar).^name; # ~$scalar is Str
Example with no expected output:
say 'The quick brown fox\n\tjumps over the lazy dog\n';
The examples left a strongly negative impression for at least one person expecting doc that's beyond the speculation stage. See http://www.perlmonks.org/?node_id=1163279 for the unfortunate impact of the first example in the first category. I've fixed that particular example but I'm filing this issue with the intent we review and refresh at least the documentation links in all examples (and perhaps review/refresh more as we go? please comment here if you've thought of something worth doing at the same time).
Having a perl site continues the brand confusion. There's only 2 examples, so it's a small loss.
This link in front page README.md yields a 404 error:
https://github.com/perl6/perl6-examples/blob/master/template_pod
When running zef install .
from the examples
directory, an error occurs:
===> Failed to find dependencies: MIME::Types
See also: raku-community-modules/MIME-Types#8
bin/run-examples.pl
is currently broken.
Seems META6.json
needs File::Find
to be added.
Also, as file extensions are being changed to match Raku conventions this runner script will require ongoing updates
On windows this works:
shell 'cls';
website starts up, but main page errors out with:
"Page not found... yet!"
Needs to be updated in any user-facing content.
Examples prob009-gerdr.pl and gerdr-feeds.pl give an incorrect answer.
The object is to find three numbers, a < b < c, such that (1) a ** 2 + b ** 2 = c ** 2; and, (2) a + b + c = 1000. The correct answer is 200 375 and 425, but each of the above mentioned scripts gives 31875000 (which is 200 * 375 * 425).
The attached file (adapted from prob009-gerdr.pl) gives the correct answer (thus indicating that the problem stems from using gather ... take).
find_Pythagorean_Triplet.txt
Edit: Full code in the above link is :
#!/usr/bin/env raku
# raku ex_Pythagorean_Triplet_Say.raku
# -------------------------------------------------------------------
# A Pythagorean triplet is a set of three integers, a < b < c, such
# that a**2 + b**2 = c**2. Find a triplet where a + b + c = 1000.
# -------------------------------------------------------------------
sub triples($N) {
for 1..Int((1 - sqrt(0.5)) * $N) -> $a {
my $u = $N * ($N - 2 * $a);
my $v = 2 * ($N - $a);
# If b = u/v is an integer, report triple
if $u %% $v {
my $b = $u div $v;
my $c = $N - $a - $b;
say "$a $b $c";
}
}
}
triples(1000);
# 200 375 425
bin/ has many files which don't appear to belong in examples, esp. bin/perldoc, which mentions parrot, and has its own entire repo at https://github.com/raku/rakudoc (formerly raku/doc).
Content here is so old, everything is .pm
.pl
.p6
- Update to use latest extensions.
There is no need, IMO, to keep the old URLs working (in an ideal world we would, but having the site follow standard and be navigable is more important IMO)
should run clean, does not.
The categories listed on the home page of examples.perl6.org don't match the category tabs across the topnav. There are some naming inconsistencies, but more importantly there are tabs with no associated description in the category list.
It's the preferred extension today.
https://examples.raku.org/categories/euler.html for example, should have a description of what Project Euler is, a link to the site, and maybe a note about only submitting solutions for the first 100 items.
Basically, add this to all example files that don't have it already:
#!/usr/bin/env perl6
And make sure that they are executable:
chmod +x example-file.p6
See also #57 (comment)
The Project Euler solutions seem to clash with Project Euler's rules, as only solutions from the first 100 problems should be shown. From here:
I learned so much solving problem XXX, so is it okay to publish my solution elsewhere?
It appears that you have answered your own question. There is nothing quite like that "Aha!" moment when you finally beat a problem which you have been working on for some time. It is often through the best of intentions in wishing to share our insights so that others can enjoy that moment too. Sadly, that will rarely be the case for your readers. Real learning is an active process and seeing how it is done is a long way from experiencing that epiphany of discovery. Please do not deny others what you have so richly valued yourself.
However, the rule about sharing solutions outside of Project Euler does not apply to the first one-hundred problems, as long as any discussion clearly aims to instruct methods, not just provide answers, and does not directly threaten to undermine the enjoyment of solving later problems. Problems 1 to 100 provide a wealth of helpful introductory teaching material and if you are able to respect our requirements, then we give permission for those problems and their solutions to be discussed elsewhere.
That being said, this is a great resource, and thank you for your work!
matthew@0xB1uE7:~/tmp/perl6-examples/categories/games$ perl6 -v
This is perl6 version 2015.09-383-gf0d4820 built on MoarVM version 2015.09-79-gee9fc2b
matthew@0xB1uE7:~/tmp/perl6-examples/categories/games$ perl6 blackjack.p6
DEALER:
0 of ten 10 hearts
PLAYER:
0 of nine 9 clubs
0 of six 6 clubs
Cannot call Numeric(Pair: ); none of these signatures match:
(Mu:U \v: *%_)
in block at blackjack.p6:63
See http://examples.perl6.org/categories/interpreters/RPN.html
my token Item { <Value> || <Op> };
on the site shows up as my token Item { || };
All subpages here:
https://examples.raku.org/categories/cookbook.html
For example this one:
https://examples.raku.org/categories/cookbook/03dates-and-times.html
Are just empty
When I`m try to enter the site on https, firefox give me:
Websites prove their identity via certificates. Firefox does not trust this site because it uses a certificate that is not valid for examples.raku.org. The certificate is only valid for the following names: design.raku.org, design.rakulang.site
Error code: SSL_ERROR_BAD_CERT_DOMAIN
Also fix links, specially Raku/doc#3129
It would be nice if the examples have the same design as the main perl6.org website. For consistency.
I think it is not a secret that this repo is outdated, not only that, it lacks a maintainer to take care of broken examples, blatantly old-style perl 6 code (it's ok when we demonstrate various approaches to users, but tooling is very this way too, and it is broken right now).
Anyone is against me working on reviving this project? Saving it for historical reasons or something like this? In case nobody argues against that in 7 days, I'll start tinker on things (in ways I see reasonable from my point of view, of course).
Example here: http://examples.perl6.org/categories/best-of-rosettacode/accumulator-factory.html
Most of the examples seem to work fine, though.
I made a trivial PR to README but the build failed: #91
This repository does not have that many dependencies (or attention, for that matter). If no one minds, I'll (or whoever is in charge by then) be changing everything to Raku and eventually move it to Raku/examples.
And it seems to be simply due to the use of pack
. Should be easy to solve.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.