develooper Front page | perl.perl6.language | Postings from April 2005

Re: Inline code (was: Closure/block/sub multiplier)

Thread Previous | Thread Next
April 20, 2005 15:12
Re: Inline code (was: Closure/block/sub multiplier)
Message ID:
Autrijus Tang skribis 2005-04-21  5:31 (+0800):
> Bringing the topic back to perl6-language, I'd like to inquire
> how eval and inlining other languages works.  Here's some thoughts:
>     eval('printf("Hello!")', :language<C>);

Is that comma needed?

>     eval(:C('printf("Hello!")'));

Strange use of a pair - feels to me like you can provide alternatives:

        C    => 'printf("Hello!")',
        Ruby => 'print "Hello!"',
        sh   => 'echo Hello\!'

>     inline C => '...';
>     inline C => =<foo.c>;

Syntactic sugar that was nice for Perl 5, but is probably better to be
left alone.

eval(Str $code, +$lang) has my preference, syntax-wise, but that can
perhaps only work with Parroty languages, of which I think C isn't

Sometimes you want to add a word in between terms for documentation. For
this reason, I've always wanted the arguments for index to be the other
way around, so I could think "index $needle, (in) $haystack".

It'd be fun to have a different spelling for comma (here I assume that
leading comma is ignored and that because of the special new leading
keyword, non-slurpy can come after slurpy), for example:

    multi eval ($code, "using" ?$lang) { eval($code, :lang($lang)) }
    eval 'printf("Hello!")' using "C";

    multi index ("of" $needle, "in" $haystack, +$offset) { index(...) }
    my $pos = index of "," in "Hello, world!";

    multi join (*@strings, "on" $separator) { ... }
    my $joined = join @fields on ":";
The same thing can almost be done with pairs, but these words don't make
good identifier names.
Can something like this be done without resorting to macros with hard to
construct regexes?


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About