diff --git a/rocks/computers/software/langs/raku.md b/rocks/computers/software/langs/raku.md index 08d1ac2..722e783 100644 --- a/rocks/computers/software/langs/raku.md +++ b/rocks/computers/software/langs/raku.md @@ -11,14 +11,14 @@ promises, lazy evaluation, and grammars. Sigils in Raku make sense unlike in Perl, for example: - +
 # Perl:
 my %hash = (key1 => "value", key2 => "value2");
 $hash{key1} # value;
 # Raku:
 my %hash = (key1 => "value", key2 => "value2");
 %hash{"key1"} # Value
-
+
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. @@ -28,10 +28,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: - +
 my Int $n = 3;
 my Str $s = "hello world";
-
+
There is a type hierarchy, which means types are based on other types. All types are based on the type `Mu`[^1]. @@ -42,7 +42,7 @@ from `Mu`. All roads lead to Rome and all types lead to `Mu`. Raku also has a decent Object Oriented interface: - +
 Class Socket {
      has Int $.sockfd;
      
@@ -59,7 +59,7 @@ Class Socket {
 
 my $sock = Socket.new("path/to/socket");
 $sock.write("hello from raku!");
-
+
Calling C functions from Raku is stupidly easy, to do this only use the [NativeCall](https://docs.raku.org/language/nativecall) module @@ -67,7 +67,7 @@ which is included in the standard library, consider the following: file.c: - +
 #include 
 
 int
@@ -76,7 +76,7 @@ print_string(const char *s)
      puts(s);
      return 0;
 }
-
+
You have to compile it so it's a shared library: @@ -84,7 +84,7 @@ You have to compile it so it's a shared library: file.raku: - +
 use NativeCall;
 
 # Libpath, raku will add the lib and the .so automatically so you don't 
@@ -97,7 +97,7 @@ sub print_string(Str --> int32) is native(LIBPATH) { * }
 
 print_string("C function running in raku");
 
-
+
It will output: @@ -116,13 +116,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: - +
 start { sleep 1.5; print "hi" }
-await Supply.from-list().throttle: 2, {
+await Supply.from-list(<A B C D E F>).throttle: 2, {
     sleep 0.5;
     .print
 }
-
+
Output is "ABCDhiEF" @@ -134,7 +134,7 @@ print the "hi" form the `start {}` block. Raku also has promises: - +
 
 sub counter(Int $n) {
 	for 0..$n -> $i {
@@ -153,7 +153,7 @@ $promise.then({say .result}); # Will print "There" after finishing.
 say "I'm doing other stuff";
 say "Blah, blah";
 sleep(1000); # Simulate stuff-doing
-
+
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)`