GithubHelp home page GithubHelp logo

nimjl's Introduction

scinim

The core types and functions of the SciNim ecosystem

nimjl's People

Contributors

clonkk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

outcastgeek

nimjl's Issues

Small UX improvements

Hi @Clonkk, as I said, I think this is a great project ✨. But I believe nimpy has a better user experience currently, though:

import nimpy

let np = pyImport("numpy")

# An attempt to translate the README example to nimpy
var myval = 4.0
var res = np.sqrt(myval)
echo res
❯ nim c -r -d:danger --opt:speed --verbosity=0 asdf.nim
..............................2.0

No
a. init or exit
b. no default imports (faster/more straightforward/more explicit interface?)
c. no typecasting

So I have two questions and a suggestion:

  1. I know the following works because I've tested:
import nimjl

Julia.init()

var myval = 4.0              # no `'f64`
var res = Julia.sqrt(myval)  # no `to(float)`
echo res

Julia.exit()

So, do we need type conversions? Can't Julia types (primitives at least) be mapped automatically to Nim types/primitives? Isn't it done already? (I haven't looked at the code yet.)

  1. I know sqrt comes from the Julia Base module (from the docs about embedding and here). What's behind the design decision of not making it explicit in Nim? For instance, nimpy requires importing a builtin module:
import nimpy

let py = pyBuiltinsModule()

(As a second thought, I'm not sure how to import a Julia module yet, so that this comment might be just too naive/simply dumb.)

  1. Embedding Julia in C requires init and exit, okay. But should this be mapped to Nim? init can be called as soon as nimjl is imported, so problem solved. The tricky part is to call exit, so I tried a couple of ways of deferring this to the end of the program. Here's what I've found:

defer does not work (I didn't know that):

...
defer:
  Julia.exit()
# =>
# Error: defer statement not supported at top level

Using std/exitprocs work 🎉:

import nimjl
import std/exitprocs

Julia.init()
addExitProc proc =
  echo "Cleaning up nimjl!"
  Julia.exit()


# Actual working code:
var myval = 4.0
var res = Julia.sqrt(myval)
echo res
echo "That's all folks!"
$ nim c -r -d:danger --opt:speed --verbosity=0 exitprocstest.nim
................................................................................................................................................................................................................................................
Nimjl> Using Julia install: /opt/julias/julia-1.6.0
..2.0
That's all folks!
Cleaning up nimjl!

(Even though I like the solution above, another possibility would be to have a top-level, global object that runs Julia.exit in its destructor, but I haven't tested that, and I'm not sure if it has any extra advantage over the above.)

Natural usage of Julia during Runtime

Greetings,

first of all, thanks for this library. It sparked my interest, as I'm following Julia since many years.

I was wondering, whether it's feasible to have general support for loading Julia scripts during Nim runtime.

For example, when I init the Julia VM, then exit it, I cannot init it again, in another proc.
It's also not possible right now to just "run" a script, that has top level statements, which are not enclosed by functions. Or, it is possible, kind of, however it just seems to be a side-effect of how the VM loading works.

It'd be great, if it were possible to initialise the VM once during the app's lifetime, as intended, then being able to load scripts on demand and run them. Being able to run Pkg after init in native Nim would also be good to have.

The use case is distributing a complex program, which gives users the option to write scripts. The scripts are written in Julia and the complex program, written in Nim, calls the procedures from the Julia scripts, to modify functionality of the complex program.

Array indexing

Use Arraymancer's desugar [1..5|2] syntax converted to Julia indexing slice / views

Error: 'let' symbol requires an initialization

Only importing the package already throws an error:

import nimjl
$ nim c -r -d:danger --opt:speed --verbosity=0 example.nim
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: nimjl [Processing]
Hint: arrays [Processing]
Hint: types [Processing]
Hint: config [Processing]
Hint: os [Processing]
Hint: strutils [Processing]
Hint: parseutils [Processing]
Hint: math [Processing]
Hint: bitops [Processing]
Hint: macros [Processing]
Hint: algorithm [Processing]
Hint: unicode [Processing]
Hint: pathnorm [Processing]
Hint: osseps [Processing]
Hint: posix [Processing]
Hint: times [Processing]
Hint: options [Processing]
Hint: typetraits [Processing]
Hint: jlcores [Processing]
Hint: strformat [Processing]
/home/schneider/.nimble/pkgs/nimjl-0.5.4/nimjl/types.nim(17, 3) Error: 'let' symbol requires an initialization

The offending line is

https://github.com/Clonkk/nimjl/blob/ce83a65d76b73eb830081ad470c9c7af51b16fe7/nimjl/types.nim#L16-L17

$ nim -v
Nim Compiler Version 1.2.6 [Linux: amd64]
Compiled at 2020-09-07
Copyright (c) 2006-2020 by Andreas Rumpf

active boot switches: -d:release

$ julia -v 
julia version 1.6.0

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.