Last active
August 29, 2015 14:06
-
-
Save marcoonroad/6a8d0306bbff68e6762e to your computer and use it in GitHub Desktop.
Just another Lisp/Prolog-like lists test.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/home/user/localperl/bin/perl | |
use v5.20; | |
use strict; | |
use warnings; | |
# linked lists test | |
use feature qw| say signatures |; | |
use Data::Dumper; | |
sub dumper (@data) { say Dumper @data } | |
sub linked (@args) { | |
my $list = [ ]; | |
if (@args) { | |
$list -> [0] = shift @args; | |
$list -> [1] = [ linked (@args) ]; | |
} | |
else { | |
$list -> [0] = [ ]; | |
} | |
return @{ $list }; | |
} | |
dumper [ linked 'A' .. 'D', qw| W Z Y K | ]; # array-like | |
dumper [ linked map { [$_, $_ + $_] } 1 .. 5 ]; # matrix-like | |
dumper [ linked [[1, 2], [3, 4]], [[5, 6], [7, 8]] ]; # rank 3-like | |
# end of script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment