July 10, 2020 D and Raku | ||||
---|---|---|---|---|
| ||||
Hello! I was on my way to post an new topic when I did a search and found this one. https://forum.dlang.org/post/ozubrkqquguyplwonjgp@forum.dlang.org On Thursday, 22 November 2018 at 09:03:19 UTC, Gary Willoughby wrote: > On Monday, 19 November 2018 at 06:46:55 UTC, dangbinghoo wrote: >> So, can you experts give a more comprehensive compare with perl6 and D? > > Sure! > > 1). You can actually read and understand D code. I disagree with this dismissive line of reasoning. I've noticed some interesting parallels between D and Raku (formerly Perl 6), specifically regarding the modeling power of the two. For example, here is a script to create a `|`-delimited CSV to import into Google Sheets. This is my D implementation: void main() { import std.stdio, std.range, std.algorithm; auto numbers = "formatted_numbers.txt".File.byLine; auto texts = "formatted_text.txt".File.byLine; auto types = "formatted_types.txt".File.byLine; auto output = File("final_conversion.csv", "a"); scope(exit) output.close; zip(numbers, texts, types) .each!(line => output.writefln("%s|%s|%s", line.expand)); } This is my Raku implementation: use v6; sub MAIN() { my @numbers = "formatted_numbers.txt".IO.lines; my @text = "formatted_text.txt".IO.lines; my @types = "formatted_types.txt".IO.lines; my $fileHandle = open "final_conversion.csv", :a; for @numbers Z @text Z @types -> [$number, $text, $type] { $fileHandle.sprintf("%s|%s|%s", $number, $text, $type); } $fileHandle.close; } Both approaches are quite similar with the main difference of the Raku version being `Z` as the zip operator and the destructuring assignment instead of `Tuple.expand`. Unfortunately, this example is a bit too small to really see all of the parallels. To the people who have used both for less-contrived applications, what is your experience with the two? What features have you liked from both? |
Copyright © 1999-2021 by the D Language Foundation