Skip to content
Draft
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions doc/Language/py-nutshell.rakudoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Raku
put "Hello, world!"

There is also the L<say|/routine/say> keyword, which behaves similarly, but will
call the L<gist|/routine/gist> method of its argument.
call the L<.gist|/routine/gist> method of its argument instead of the C<.Str|/routine/Str> method.

Raku

Expand Down Expand Up @@ -64,8 +64,9 @@ matching curly braces are closed.

In Raku, a semicolon signifies the end of a statement.
The semicolon may be omitted if it is the last statement
of a block. The semicolon may also be omitted if there
is a closing curly brace followed by a newline.
of a block (i.e. of a list of statements enclosed in curly braces).
The semicolon may also be omitted after a closing curly brace
followed by a newline.

Python

Expand All @@ -81,6 +82,7 @@ Raku
3 + 4;
say 1 +
2;
if True { say 42 }

=head2 Blocks

Expand Down Expand Up @@ -123,7 +125,7 @@ initialized or declared and initialized at once.
$foo = 12; # initialize
my $bar = 19; # both at once

Also, as you may have noticed, variables in Raku usually start with sigils --
Also, as you may have noticed, variables in Raku usually start with sigils
Copy link
Collaborator Author

@schultzdavid schultzdavid Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here I replaced two dashes (rendered as two dashes) by an en dash

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't an em-dash be more appropriate here?

Copy link
Collaborator Author

@schultzdavid schultzdavid Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure.

Current factual usage in the docs is about evenly split between spaced en dashes and unspaced em dashes. (For the convenience of anyone wanting to check with a ripgrep: – and — )

The Wikipedia style says both are fine, just keep it consistent within a given article.

The Chicago Manual of Style and also a guide on technical writing do agree that unspaced em dashes should be used.

However, the text of the Raku docs is not being rendered via LaTeX or any other print-focused typesetting system, but instead (for most people) on the website and (for some people) in the rakudoc CLI tool.

  • On the website, unspaced em dashes don't work so well with padded inline code, of which we have a lot. For example, take a look at the bottom of this section.
  • In a CLI tool, with a monospace font, unspaced dashes are also problematic.

How others do it:

  • The Python docs seem to consistently use spaced em dashes.
  • The Ruby docs use em dashes, but very sparingly and not consistenly with regard to spacing
  • The git man pages use em dashes. It seems like they prefer spaced ones (e.g. man git, man gitcli, man gitcore-tutorial, man git-blame), but some unspaced ones occur here and there (man gittutorial).

Personally I now tend toward using spaced em dashes, especially because of all the padded inline code on docs.raku.org, and because of the CLI. However, it's probably best if there's a consensus, which one can then put into the styleguide.

Copy link
Collaborator

@arkiuat arkiuat Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that the en dash has three particular use cases that call for it, and that this context isn't one of those.

https://en.wikipedia.org/wiki/Dash#En_dash says

The three main uses of the en dash are:

  1. to connect symmetric items, such as the two ends of a range or two competitors or alternatives
  2. to contrast values or illustrate a relationship between two things
  3. to compound attributes, where one of the connected items is itself a compound

To offset a parenthetical remark, as here, an em dash is called for. I have no opinions about the whitespace; from what you say, it sounds as if it would work better with spaces around it.

If any of those en dashes that you found in the current docs are not examples of one of the three use cases mentioned above, they probably ought to be changed to em dashes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since wikipedia says either, and the Tribune picks one, I’m happy to make that one the recommendation, add a style test for it, and then make sure we pass the test (and also add it to the styleguide) - Let’s move that into a new ticket and whatever we end up with for this PR is fine, we’ll fix it in post if we have to.

symbols indicating the type of their container. Variables starting with a C<$>
hold scalars. Variables starting with an C<@> hold arrays, and variables
starting with a C<%> hold a hash (dict). Sigilless variables, declared with a
Expand Down Expand Up @@ -398,20 +400,23 @@ I<Raku>
say "Symbol '$symbol' stands for $element";
}

=head2 Lambdas, functions and subroutines>
=head2 Functions, subroutines and lambdas

Declaring a function (subroutine) with C<def> in Python is accomplished
with C<sub> in Raku.

=begin code :lang<python>
def add(a, b):
return a + b
=end code

=begin code
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why split this code up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention was to have Python code and Raku code apart like elsewhere in the document to emphasize the shift in language (and to not have Raku code in a block marked as "Python highlighting"). But the example does work well the way it is, perhaps even better, so yes I think I'll revert it (and probably add comments # Python and # Raku to the right of each signature).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I hadn’t even noticed they were not the same language - in that case, sorry, please separate them AND tag each with the right language attribute - the more raku code we can verify the better

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see – I've done that now

sub add(\a, \b) {
return a + b
}
=end code


The C<return> is optional; the value of the last expression is used as
the return value:

Expand All @@ -431,8 +436,8 @@ sub add($a, $b) {
Python 2 functions can be called with positional arguments
or keyword arguments. These are determined by the caller.
In Python 3, some arguments may be "keyword only".
In Raku, positional and named arguments are determined
by the signature of the routine.
In Raku, each argument is either positional or named,
as determined by the signature of the routine.

Python

Expand Down Expand Up @@ -827,4 +832,23 @@ Raku using the List type, or from an external module.
my $list4 = (|$list1, |$list2); # equivalent to previous line
say $list3; # OUTPUT: «(1, two, 3, hat, 5, 6, seven)␤»

=head1 Ecosystem

Where Python has pip, anaconda or uv, Raku has zef as its preferred tool for module management.

Where Python has PyPi, Raku has <raku.land|https://raku.land/>
as the central index of third-party L<modules|/language/modules>.
There are modules from three different ecosystems –
please stick to the I<zef> ecosystem.
(The others, I<p6c> and I<CPAN>, are deprecated when it comes to Raku.)
See L<here|https://deathbyperl6.com/faq-zef-ecosystem/> for additional information,
including guidance on how to publish your own modules.

=head2 Web development

The Raku module L<Cro|https://raku.land/zef:cro/cro> serves a similar job as Python's L<Django|https://djangoproject.com/>.

The Raku module L<Red|https://raku.land/zef:FCO/Red> is an object–relational mapper, similar to Django's ORM capabilities or to SQLAlchemy.

=end pod

Loading