Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function cannot be used outside of evalString #259

Closed
jeroenvandijk opened this issue Jan 28, 2020 · 4 comments
Closed

Function cannot be used outside of evalString #259

jeroenvandijk opened this issue Jan 28, 2020 · 4 comments

Comments

@jeroenvandijk
Copy link
Contributor

version

"@borkdude/sci": "0.0.12",

platform

Javascript, NodeJS,

problem

Functions created in evalString cannot be used in the javascript context

repro

const { evalString } = require('@borkdude/sci');
var myFN = evalString("(fn [a] (+ a 10))")
myFN(4)

Gives

myFN(4)
      ^
TypeError: myFN is not a function

expected behavior

evalString should return a function that can be used from the javascript context. Like in the CLJ version:

(let [f (sci/eval-string "(fn [a] (+ a 10))")]
  (f 4))

Code above returns 14

@jeroenvandijk
Copy link
Contributor Author

The function can be retrieved by accessing fields of the returned value. E.g.

 var f = evalString("(clj->js (fn [a b] (+ a b)))")
  console.log(f.s(1, 2))

I'm wondering if this is because of the metadata that is added: https://github.com/borkdude/sci/blob/c2ffce590f8185b9fd5fdbb7e3746ba37f2ae02f/src/sci/impl/fns.cljc#L84 For all none macro fn's this is not needed I think

@borkdude
Copy link
Collaborator

borkdude commented Jan 28, 2020

@jeroenvandijk

const { evalString, toJS } = require('@borkdude/sci');

and then call toJS to the function, this will remove the metadata.

@borkdude
Copy link
Collaborator

I'll check if non-macro functions work correctly without metadata and then publish a new release.

@borkdude
Copy link
Collaborator

Fixed in npm version 0.0.13-alpha.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants