#+header-args: :cache yes :session power
(import (scheme base))
(import (scheme base) | |
(scheme case-lambda) | |
(scheme file) | |
(scheme lazy) | |
(scheme write)) | |
(define (filter pred lst) | |
(cond ((null? lst) | |
'()) | |
((pred (car lst)) |
// Based on <https://en.wikipedia.org/wiki/MD5> | |
/************/ | |
/* INCLUDES */ | |
/************/ | |
#include <limits.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
Different programming language communities have differing cultures. Some are more pragmatic, others more idealistic. Some place great emphasis on having code be thoroughly readable and understandable for anyone who joins an existing project, and some prefer writing out clear and in-depth documentation.
Raku, inheriting one of the best parts of Perl, has a community that writes great documentation.
Literate Programming is an alternate take on documentation. Instead of having the code be the central element and writing documentation around it, in Literate Programming we write a document that contains the essential parts of our program. In this way we integrate the code into our natural language in such a manner that the idea underlying the design is clear. In this way we also naturally start thinking explicitly about the operations our programs need to perform to fulfill the task we are se
say sub ($f, $x, $y) { | |
return $f($x, $y, $f); | |
}(sub ($x, $y, $f) { | |
if $x < 2 { | |
return $y; | |
} | |
else { | |
return $f($x - 1, $x * $y, $f); | |
} | |
}, |
#!/usr/bin/env raku | |
use v6; | |
sub memoize-walk (Code $calc --> Code) { | |
my Int @cache; | |
return sub (Int $n --> Int) { | |
return @cache[$n] if @cache[$n]; | |
my Int $result = $calc($n); |
Raku is a really nice language. Versatile, expressive, fast, dwimmy. The only problem I sometimes have with it is that it can be a little slow. Fortunately that can easily be solved by the NativeCall interface, which makes it easy to call C code in your Raku program. Now, as nice as C is, it is a rather old language with some limitations. A newer language that can fill its niche is known as Rust. I'll show some examples of having Raku talk to Rust.
Rust code can be called from other languages using the FFI standard. FFI stands for "Foreign Function Interface" and allows you to export a Rust library as a standard shared library (a .so file on Linux or .dll on Windows). This is done by adding the following section in your Cargo.toml:
{ | |
"riddlejs": { | |
"ext": "js", | |
"template": "", | |
"hasInterpreter": true, | |
"entrypoint": "index.js", | |
"hasLanguageServer": true, | |
"icon": "https://repl.it/public/images/languages/nodejs.svg", | |
"category": "Hidden", | |
"hasProjectMode": true, |