Hi, Zeno!

The loss of anonymous method style function calling is a known wart with NiceSlice, unfortunately. It is a language design issue -- Perl leaves very few of the "convenient" constructions unused. Since (as you noticed) the &$ref(@params) syntax is preserved, it has not been a major issue.

Source filters are indeed dangerous, but they remain the only way to affect the syntax of the language itself until Perl 6 becomes commonplace. NiceSlice has been rather thoroughly tested, and I use it in essentially all my PDL code. (Now that I think of it, the C preprocessor is a source filter too...) There are three warts to the source preprocessing that I know of: * Function refs: <<$ref->(@params);>> is overloaded with niceslicing syntax; use "&$ref(@params)" [which you pointed out] * String interpolation: <<print "$a (comment)";>> gets erroneously turned into <<print "$a->nslice(comment)", so you have to break up the quoted string. This has to do with the difficulty of parsing out the Perl quoting structure, which can potentially be fixed -- but nobody has yet felt moved to do so. * Inline functions: if you use Inline::C or Inline::PP, you must say "no PDL::NiceSlice" before the Inline call, else your foreign-language code will get mangled.



On May 26, 2011, at 4:21 AM, Zeno Gantner wrote:

Hi all,

I am still new to PDL, and trying to get more comfortable with it.
So please excuse if my question is somehow naive ...

I found out that PDL::NiceSlice breaks calling function references.
Is this a known bug?

--
#!/usr/bin/perl

use 5.10.1;

use PDL::NiceSlice;
my $fun_ref = sub { say $_[0]; };
&$fun_ref('Hey!');   # works
$fun_ref->('Hey!');  # does not work
--
... gives the output:
--
Hey!
Can't call method "nslice" on unblessed reference at ./pdl- niceslice.pl line 8.
--

By the way, PDL::NiceSlice is implemented as a Perl source filter,
what can be a bit dangerous.
What are the general recommendations towards PDL::NiceSlice? Is its
usage encouraged?

Best regards,
 Zeno
--
MyMediaLite Recommender System Library: http://ismll.de/mymedialite

_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl



_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl

Reply via email to