isaacg1 / pyth

Pyth, an extremely concise language. Try it here:
https://pyth.herokuapp.com/
MIT License
263 stars 57 forks source link

REPL when no flags are set, and execute code from stdin #208

Closed FliiFe closed 8 years ago

FliiFe commented 8 years ago

The current behavior for the interpreter is to enter REPL mode when no argument is given, but you can't give code directly to stdin. For example, this

$ ./pyth.py <<<'"Hello'

or

$ echo '"Hello' | ./pyth.py

Will output this :

Welcome to the Pyth REPL.
Each input line will be compiled and executed, and the results of
each one will be passed into the next one's input stream.

>>> Hello
>>>

That is not a desired behavior.

So, could we execute code from stdin ?

FliiFe commented 8 years ago

So, judging by the code, it looks like this behavior is not wanted, but the logical operators are not bound correctly This is the code :

    # Check for command line flags.
    # If debug is on, print code, python code, separator.
    # If help is on, print help message.
    if (len(sys.argv) > 1 and
            "-r" in sys.argv[1:] 
            or "--repl" in sys.argv[1:]) \
            or all(flag in ("-d", "--debug") for flag in sys.argv[1:]):

        Repl("-d" in sys.argv[1:] or "--debug" in sys.argv[1:]).cmdloop()
isaacg1 commented 8 years ago

I like the behavior of entering the REPL with no flags. I agree that the code is written incorrectly (len(sys.argv) > 1 is unnecessary and placed wrong). If you want to execute code, you can just use -c, what's wrong about that?

isaacg1 commented 8 years ago

I removed that unnecessary check you mentioned.