Coder Social home page Coder Social logo

Comments (4)

DinoV avatar DinoV commented on July 17, 2024

There is an overload in the parser which does this, Parser.ParseFile(bool makeModule, bool returnValue). Passing true for returnValue causes this behavior. If you use the SourceCodeKind.AutoDetect it’ll flow true in for the returnValue and you should see the desired behavior.

From: Doug Blank [mailto:[email protected]]
Sent: Saturday, April 19, 2014 5:50 AM
To: IronLanguages/main
Subject: [main] Allow SourceCodeKind statements to return value (#190)

IronPython, similar to CPython, has modes for how to evaluate code. Expressions will return a value, but I don't think any of the statement-oriented evaluations will return a value. However, IPython has another manner of executing code that will return the last expression, even if after a set of statements. For example, if you enter this in a cell:

x = 1

y = 2

x + y

You'll get "3" as output. The way that they do that is to parse the input, and evaluate each statement, returning the result of the last one. This is really handy when doing cell-based computation as it allows the last item to be displayed/viewed/used.

It would be nice if IronPython allowed this type of evaluation.

SourceKinds:

https://github.com/IronLanguages/main/blob/master/Runtime/Microsoft.Scripting/SourceCodeKind.cs

β€”
Reply to this email directly or view it on GitHubhttps://github.com//issues/190.

from main.

dsblank avatar dsblank commented on July 17, 2024

Thank you; that worked like a charm!

from main.

slide avatar slide commented on July 17, 2024

Can we close out this issue then?

from main.

dsblank avatar dsblank commented on July 17, 2024

From my perspective, yes. I don't know if this documented anywhere... that might be the only action item from this. Thanks!

from main.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.