in reply to Re: Brainfuck Interpreter
in thread Brainfuck Interpreter

@_[0] is better written as $_[0]

That depends on your definition of "better". If you're writing code to parse a language which is deliberately confusing, it's arguably better to parse it in as confusing a way as possible.

I found this parser really easy to understand - why not write an obfuscated parser for obfuscated code? ;-)

Update: Perhaps I need to make it clear that I'm not being entirely serious. It's certainly a bad idea to use the side effects of an array slice in real code. On the other hand, if you want to do something confusing, do it in the most confused way possible!

Replies are listed 'Best First'.
Re: Re: Re: Brainfuck Interpreter
by Juerd (Abbot) on Mar 13, 2002 at 13:31 UTC

    That depends on your definition of "better".

    2;0 juerd@ouranos:~$ perl -we'@_[0]' Scalar value @_[0] better written as $_[0] at -e line 1.
    That's my definition. @_[0] is an array slice, which happens to have a single value, and just happens to work because of that. For example:
    my @foo = qw(a b c d e f g h i j); my @bar = @foo[1, 5, 6, 4]; # @bar is now qw(b f g e) my $bar = $foo[0];
    When you want a scalar, USE a scalar :)

    If you're writing code to parse a language which is deliberately confusing, it's arguably better to parse it in as confusing a way as possible.

    Perhaps, but I don't agree. And even if you were right, there's no need to use PERL for that. (note: "PERL" ne "Perl").

    U28geW91IGNhbiBhbGwgcm90MTMgY
    W5kIHBhY2soKS4gQnV0IGRvIHlvdS
    ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
    geW91IHNlZSBpdD8gIC0tIEp1ZXJk