Giter Club home page Giter Club logo

Comments (5)

n-riesco avatar n-riesco commented on June 26, 2024

For the time being, here are two workarounds:

  • Use eval:
    eval(require("fs").readFileSync("f.js").toString());
  • Use the flag --ijs-startup-script=path:
    $ ijs --ijs-startup-script=f.js

I don't feel keen on messing with the Javascript grammar to support magics (IPython's % or Node.js's .). Up to now, the approach followed in IJavascript is to define a global object to communicate with the IJavascript kernel ($$mime$$, $$async$$, $$done$$(), ...). We could define the global $$session$$ and provide methods such as $$session$$.load(filename) and $$session$$.save(filename).

I realise that the number of IJavascript globals is increasing and I've been thinking for a while that, at some point in the future, we should define only one global. For example:

$$.async

$$.load(filename)
$$.save(filename)

$$.msg_id
$$.write(msg_id, data)
$$.writeToStdout(msg_id, data)
$$.writeToStderr(msg_id, data)
$$.close(msg_id)
$$.closeStdout(msg_id)
$$.closeStderr(msg_id)
$$.writeAsMime(msg_id, mime)
$$.writeAsHtml(msg_id, html)
$$.writeAsPng(msg_id, png)

from ijavascript.

rgbkrk avatar rgbkrk commented on June 26, 2024

I'm not a fan of any globals, though I hear ya. I'll rely on the eval trick.

Most of my suggestions are going to be about mirroring node's repl as much as possible, while extending it with rich display.

from ijavascript.

n-riesco avatar n-riesco commented on June 26, 2024

Magics have their own kind of problems:

$ node
> .load f.js
> x = 2
2
> .load "f" + ".js"
Failed to load:"f" + ".js"
> 

whereas globals blend nicely with Javascript because they are Javascript:

eval(require("fs").readFileSync("f" + ".js").toString());

from ijavascript.

rgbkrk avatar rgbkrk commented on June 26, 2024

They definitely do. I even despise them being within IPython as it breaks compatibility with plain Python scripts.

What I want to make sure of is that if a node user was used to being able to do something at the command line and they start using it in a notebook (or console), that we don't break their normal flow. That's my two cents. If it belongs in a different kernel, that's ok. I'm just going to raise things as I use ijavascript in my daily flow and submit PRs when it seems like you're happy with the ideas.

from ijavascript.

n-riesco avatar n-riesco commented on June 26, 2024

I will leave the issue open. I would like to provide this functionality. I'm keener to use a global, but there are more possibilities.

from ijavascript.

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.