How do Ruby and Python implement their interactive consoles?
        Posted  
        
            by sxa
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by sxa
        
        
        
        Published on 2010-04-15T21:52:35Z
        Indexed on 
            2010/04/15
            22:13 UTC
        
        
        Read the original article
        Hit count: 305
        
When implementing the interpreter for my programming language I first thought of a simple console window which allows the user to enter some code which is then executed as a standalone program as a shell.
But there are severe problems: If every line of code the user enters is handled as a standalone program, it has to go through the tokenizer and parser and is then just executed by the interpreter - what about functions then?
- How can the Python/Ruby interactive consoles (IDLE, irb) "share" the code? How is the code entered handled?
 
Example:
>> def x:
>>  print("Blah")
>> 
>> x()
Where is the function stored so it can be called at any time again?
How can the interactive console take everything entered as obviously one program without executing everything over and over again?
© Stack Overflow or respective owner