diff options
| author | Paul Buetow <paul@buetow.org> | 2022-04-23 10:07:45 +0100 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2022-04-23 10:07:45 +0100 |
| commit | 5d29f5fbd0671686d88ae7ba68a997326ae75932 (patch) | |
| tree | bd70d6cd4fe43bb80b540166b8ca97a2b71c8d90 /gemfeed | |
| parent | 531d15e44220bd4235f743616653a65654655966 (diff) | |
Publishing new version
Diffstat (limited to 'gemfeed')
| -rw-r--r-- | gemfeed/2014-03-24-the-fibonacci.pl.c-polyglot.md | 103 | ||||
| -rw-r--r-- | gemfeed/2021-09-12-keep-it-simple-and-stupid.md | 4 | ||||
| -rw-r--r-- | gemfeed/2022-04-10-creative-universe.md | 3 | ||||
| -rw-r--r-- | gemfeed/index.md | 2 |
4 files changed, 74 insertions, 38 deletions
diff --git a/gemfeed/2014-03-24-the-fibonacci.pl.c-polyglot.md b/gemfeed/2014-03-24-the-fibonacci.pl.c-polyglot.md index bad85e9d..96dc6a1d 100644 --- a/gemfeed/2014-03-24-the-fibonacci.pl.c-polyglot.md +++ b/gemfeed/2014-03-24-the-fibonacci.pl.c-polyglot.md @@ -1,6 +1,6 @@ -# The fibonacci.pl.c Polyglot +# The fibonacci.pl.raku.c Polyglot -> Published by Paul at 2014-03-24 +> Published by Paul at 2014-03-24, last updated 2022-04-23 In computing, a polyglot is a computer program or script written in a valid form of multiple programming languages, which performs the same operations or output independent of the programming language used to compile or interpret it. @@ -8,7 +8,7 @@ In computing, a polyglot is a computer program or script written in a valid form ## The Fibonacci numbers -For fun, I programmed my own Polyglot, which is both valid Perl and C code. The exciting part about C is that $ is a valid character to start variable names with: +For fun, I programmed my own Polyglot, which is both valid Perl, Raku, C and C++ code (I have added C++ and Raku support in 2022). The exciting part about C and C++ is that $ is a valid character to start variable names with: ``` #include <stdio.h> @@ -21,37 +21,36 @@ For fun, I programmed my own Polyglot, which is both valid Perl and C code. The my $arg; sub hello() { - printf("Hello, welcome to Perl-C!\n"); - printf("This program is both valid C and Perl code!\n"); - printf("It calculates all fibonacci numbers from 0 to 9!\n\n"); - return 0; + printf("Hello, welcome to the Fibonacci Numbers!\n"); + printf("This program is all, valid C and C++ and Perl and Raku code!\n"); + printf("It calculates all fibonacci numbers from 0 to 9!\n\n"); + return 0; } sub fibonacci() { - my $n = $arg; + my $n = $arg; - if ($n < 2) { - return $n; - } + if ($n < 2) { + return $n; + } - $arg = $n - 1; - my $fib1 = fibonacci(); - $arg = $n - 2; - my $fib2 = fibonacci(); + $arg = $n - 1; + my $fib1 = fibonacci(); + $arg = $n - 2; + my $fib2 = fibonacci(); - return $fib1 + $fib2; + return $fib1 + $fib2; } BEGIN { - hello(); - my $i = 0; - - for ($i = 0; $i <= 10; ++$i) { - $arg = $i; - printf("fib(%d) = %d\n", $i, fibonacci()); - } - - return 0; + hello(); + my $i = 0; + + while ($i <= 10) { + $arg = $i; + printf("fib(%d) = %d\n", $i, fibonacci()); + $i++; + } } ``` @@ -59,12 +58,13 @@ You can find the full source code at GitHub: [https://codeberg.org/snonux/perl-c-fibonacci](https://codeberg.org/snonux/perl-c-fibonacci) -### Let's run it with Perl: +### Let's run it with C and C++ ``` -❯ perl fibonacci.pl.c -Hello, welcome to Perl-C! -This program is both valid C and Perl code! +% gcc fibonacci.pl.raku.c -o fibonacci +% ./fibonacci +Hello, welcome to the Fibonacci Numbers! +This program is all, valid C and C++ and Perl and Raku code! It calculates all fibonacci numbers from 0 to 9! fib(0) = 0 @@ -78,16 +78,49 @@ fib(7) = 13 fib(8) = 21 fib(9) = 34 fib(10) = 55 -``` +% g++ fibonacci.pl.raku.c -o fibonacci +% ./fibonacci +Hello, welcome to the Fibonacci Numbers! +This program is all, valid C and C++ and Perl and Raku code! +It calculates all fibonacci numbers from 0 to 9! -### Let's compile it as C and run the binary: +fib(0) = 0 +fib(1) = 1 +fib(2) = 1 +fib(3) = 2 +fib(4) = 3 +fib(5) = 5 +fib(6) = 8 +fib(7) = 13 +fib(8) = 21 +fib(9) = 34 +fib(10) = 55 +``` + +### Let's run it with Perl and Raku ``` -❯ gcc fibonacci.pl.c -o fibonacci -❯ ./fibonacci -Hello, welcome to Perl-C! -This program is both valid C and Perl code! +% perl fibonacci.pl.raku.c +Hello, welcome to the Fibonacci Numbers! +This program is all, valid C and C++ and Perl and Raku code! +It calculates all fibonacci numbers from 0 to 9! + +fib(0) = 0 +fib(1) = 1 +fib(2) = 1 +fib(3) = 2 +fib(4) = 3 +fib(5) = 5 +fib(6) = 8 +fib(7) = 13 +fib(8) = 21 +fib(9) = 34 +fib(10) = 55 + +% raku fibonacci.pl.raku.c +Hello, welcome to the Fibonacci Numbers! +This program is all, valid C and C++ and Perl and Raku code! It calculates all fibonacci numbers from 0 to 9! fib(0) = 0 diff --git a/gemfeed/2021-09-12-keep-it-simple-and-stupid.md b/gemfeed/2021-09-12-keep-it-simple-and-stupid.md index 9a141a27..ce8deb38 100644 --- a/gemfeed/2021-09-12-keep-it-simple-and-stupid.md +++ b/gemfeed/2021-09-12-keep-it-simple-and-stupid.md @@ -15,7 +15,7 @@ -------------------- -------------------- ``` -> Published by Paul at 2021-09-12, last updated at 2022-01-23 +> Published by Paul at 2021-09-12, last updated at 2022-04-21 A robust computer system must be kept simple and stupid (KISS). The fancier the system is, the more can break. Unfortunately, most systems tend to become complex and challenging to maintain in today's world. In the early days, so I was told, engineers understood every part of the system, but nowadays, we see more of the "lasagna" stack. One layer or framework is built on top of another layer, and in the end, nobody has got a clue what's going on. @@ -93,4 +93,6 @@ There is, however, a trap. The more you spend time with things, the more these t Enough ranted for now :-). E-Mail me your comments to paul at buetow dot org! +> Controversially, a lack of features is a feature. Enjoy your peace an quiet. - Michael W Lucas + [Go back to the main site](../) diff --git a/gemfeed/2022-04-10-creative-universe.md b/gemfeed/2022-04-10-creative-universe.md index 2e649af5..58f04691 100644 --- a/gemfeed/2022-04-10-creative-universe.md +++ b/gemfeed/2022-04-10-creative-universe.md @@ -21,7 +21,7 @@ - the universe ``` -> Published by Paul at 2022-04-10 +> Published by Paul at 2022-04-10, last updated at 2022-04-18 ## Prelude @@ -135,6 +135,7 @@ Relevant books I can recommend are: * Deep Work; Cal Newport; Piatkus * So Good They Can't Ignore You; Cal Newport; Business Plus * The Off Switch; Mark Cropley; Virgin Books +* Ultralearning; Scott Young; Thorsons E-Mail me your comments to paul at buetow dot org! diff --git a/gemfeed/index.md b/gemfeed/index.md index 026d34f6..171b0ab3 100644 --- a/gemfeed/index.md +++ b/gemfeed/index.md @@ -24,7 +24,7 @@ [2016-04-09 - Jails and ZFS with Puppet on FreeBSD](./2016-04-09-jails-and-zfs-on-freebsd-with-puppet.md) [2016-04-03 - Offsite backup with ZFS](./2016-04-03-offsite-backup-with-zfs.md) [2015-12-05 - Run Debian on your phone with Debroid](./2015-12-05-run-debian-on-your-phone-with-debroid.md) -[2014-03-24 - The fibonacci.pl.c Polyglot](./2014-03-24-the-fibonacci.pl.c-polyglot.md) +[2014-03-24 - The fibonacci.pl.raku.c Polyglot](./2014-03-24-the-fibonacci.pl.c-polyglot.md) [2011-05-07 - Perl Daemon (Service Framework)](./2011-05-07-perl-daemon-service-framework.md) [2010-05-09 - The Fype Programming Language](./2010-05-09-the-fype-programming-language.md) [2010-05-07 - Lazy Evaluation with Standard ML](./2010-05-07-lazy-evaluation-with-standarn-ml.md) |
