Skip to content

Instantly share code, notes, and snippets.

@marcoonroad
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoonroad/6a8d0306bbff68e6762e to your computer and use it in GitHub Desktop.
Save marcoonroad/6a8d0306bbff68e6762e to your computer and use it in GitHub Desktop.
Just another Lisp/Prolog-like lists test.
#!/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