Testing some pandoc thing

This commit is contained in:
qorg11 2021-12-19 13:09:12 +01:00
parent 0813ea67bd
commit 2d9125d7da
No known key found for this signature in database
GPG Key ID: 343FC20A4ACA62B9
1 changed files with 14 additions and 14 deletions

View File

@ -12,14 +12,14 @@ promises, lazy evaluation, and grammars.
Sigils in Raku make sense unlike in Perl, for example:
<pre class="prettyprint">
~~~{.raku .numberLines}
# Perl:
my %hash = (key1 => "value", key2 => "value2");
$hash{key1} # value;
# Raku:
my %hash = (key1 => "value", key2 => "value2");
%hash{"key1"} # Value
</pre>
~~~
If a hash is a hash, it is a hash, it won't be converted to a scalar
when you want to retrieve data from that hash. Unlike in Perl.
@ -29,10 +29,10 @@ variables you declare are of the type "Any", which means that variable
can have any time and can be converted to other type. Nevertheless you
can specify which type you want the variable to be:
<pre class="prettyprint">
~~~{.raku .numberLines}
my Int $n = 3;
my Str $s = "hello world";
</pre>
~~~
There is a type hierarchy, which means types are based on other
types. All types are based on the type `Mu`[^1].
@ -43,7 +43,7 @@ from `Mu`. All roads lead to Rome and all types lead to `Mu`.
Raku also has a decent Object Oriented interface:
<pre class="prettyprint">
~~~{.raku .numberLines}
Class Socket {
has Int $.sockfd;
@ -60,7 +60,7 @@ Class Socket {
my $sock = Socket.new("path/to/socket");
$sock.send("hello from raku!");
</pre>
~~~
Calling C functions from Raku is stupidly easy, to do this only use
the [NativeCall](https://docs.raku.org/language/nativecall) module
@ -68,7 +68,7 @@ which is included in the standard library, consider the following:
file.c:
<pre class="prettyprint">
~~~{.raku .numberLines}
#include <stdio.h>
int
@ -77,7 +77,7 @@ print_string(const char *s)
puts(s);
return 0;
}
</pre>
~~~
You have to compile it so it's a shared library:
@ -85,7 +85,7 @@ You have to compile it so it's a shared library:
file.raku:
<pre class="prettyprint">
~~~{.raku .numberLines}
use NativeCall;
# Libpath, raku will add the lib and the .so automatically so you don't
@ -98,7 +98,7 @@ sub print_string(Str --> int32) is native(LIBPATH) { * }
print_string("C function running in raku");
</pre>
~~~
It will output:
@ -117,13 +117,13 @@ really easily, but if you *really* want to call `fork()` you can call
Async functions in raku are something very easy. The [language
website](https://raku.org) give us this example:
<pre class="prettyprint">
~~~{.raku .numberLines}
start { sleep 1.5; print "hi" }
await Supply.from-list(&lt;A B C D E F&gt;).throttle: 2, {
sleep 0.5;
.print
}
</pre>
~~~
Output is "ABCDhiEF"
@ -135,7 +135,7 @@ print the "hi" form the `start {}` block.
Raku also has promises:
<pre class="prettyprint">
~~~{.raku .numberLines}
sub counter(Int $n) {
for 0..$n -> $i {
@ -154,7 +154,7 @@ $promise.then({say .result}); # Will print "There" after finishing.
say "I'm doing other stuff";
say "Blah, blah";
sleep(1000); # Simulate stuff-doing
</pre>
~~~
the `.then` method takes as parameter a block of code, which will be
executed after finishing the process. In that code I use `sleep(1000)`