use strict;
use Inline 'SLang';
use PDL;

# ensure that we convert numeric S-Lang arrays to piddles
Inline::SLang::sl_array2perl(2);

# NOTE:
#   in S-Lang we have a [2,3] array but
#      in PDL this is a [3,2] array!
#
my $a1 = send_and_get( sequence(5)/2.0 );
print "\nPerl sent:\n", $a1->info, "\n";
print $a1, "\n";

__END__
__SLang__

define send_and_get (in) {
  if ( typeof(in) != Array_Type ) error( "Error!" );
  variable adims, ndims, atype;
  ( adims, ndims, atype ) = array_info(in);
  vmessage( "S-Lang sent a %d dim array of %S variables", ndims, atype );
  variable elem;
  foreach ( in ) {
    elem = ();
    vmessage( "  element = '%S'", elem );
  }

  % create the output array
  variable out = [2:7];
  reshape( out, [2,3] );
  return out;
}