This behavior is actually defined by CPython which specs interactive input as 
being:

interactive_input ::=  [stmt_list] NEWLINE | compound_stmt NEWLINE

The stmt_list allows the semi-colon delinated lines and the compound_stmt 
allows a single statement.

The idea here is that this is for a console input and that there really should 
be only one statement being entered at a time.

We could de-couple the relationship between interactive code & printing 
expression statements though.  Internally they're not really that related so it 
wouldn't be that hard to do.  If that sounds like it'd help you (or if there's 
others that would like to see it) you could open a feature request on CodePlex.

> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:users-
> [EMAIL PROTECTED] On Behalf Of Jeff Slutter
> Sent: Saturday, December 06, 2008 3:33 PM
> To: Discussion of IronPython
> Subject: [IronPython] SourceCodeKind.Statements versus
> SourceCodeKind.InteractiveCode
>
> I'm working on getting an interactive script console into my
> application. Information on how to do this is a bit hard to find but I
> came across an app.py by Jim Hugunin showing how to do it with
> Silverlight.
>
> I based my C# app around that and have something working pretty well.
> I'm always using SourceCodeKind.InteractiveCode when compiling the
> source snippets and it works great. But there is a situation where it
> doesn't do what I expect.
>
> If I pass in the following string:
>
> a = 10 + 3;
> print(a);
>
> (note: two statements, separated with a newline)
>
> It will give me an error saying that the 'print' is an unexpected
> token.
>
> If I pass in the following string:
>
> a = 10 + 3; print(a);
>
> It works as expected (printing out 13).
>
> It works fine if there are multiple lines for a statement like:
>
> if( a > 10 ):
>  print(a);
>
> If I use SourceCodeKind.Statements then all of the above works just
> fine, but I don't get the nice things like the automatic print of the
> returned value of the statement or the "_" variable.
>
> Is there a reason why InteractiveCode does things different like that?
> I
> want to give a consistent interface to my users and I think they would
> expect that they can give two statements at once (especially if they
> can
> do it on the same line).
>
> I can work around this to get what I want by building up my buffer one
> line at a time and testing to see if it is a "complete" statement and
> executing that, then continuing to feed in the next line, etc. But, if
> I
> don't have to, I don't want to do that.
>
> Any ideas?
>
> Thanks
> Jeff
>
> _______________________________________________
> Users mailing list
> Users@lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to