{"action":"created","issue":{"url":"https://api.github.com/repos/Frege/frege-interpreter/issues/33","repository_url":"https://api.github.com/repos/Frege/frege-interpreter","labels_url":"https://api.github.com/repos/Frege/frege-interpreter/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/Frege/frege-interpreter/issues/33/comments","events_url":"https://api.github.com/repos/Frege/frege-interpreter/issues/33/events","html_url":"https://github.com/Frege/frege-interpreter/issues/33","id":191810460,"number":33,"title":"When using the ScriptEngine to execute Frege, bindings are not visible","user":{"login":"renatoathaydes","id":1901277,"avatar_url":"https://avatars.githubusercontent.com/u/1901277?v=3","gravatar_id":"","url":"https://api.github.com/users/renatoathaydes","html_url":"https://github.com/renatoathaydes","followers_url":"https://api.github.com/users/renatoathaydes/followers","following_url":"https://api.github.com/users/renatoathaydes/following{/other_user}","gists_url":"https://api.github.com/users/renatoathaydes/gists{/gist_id}","starred_url":"https://api.github.com/users/renatoathaydes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/renatoathaydes/subscriptions","organizations_url":"https://api.github.com/users/renatoathaydes/orgs","repos_url":"https://api.github.com/users/renatoathaydes/repos","events_url":"https://api.github.com/users/renatoathaydes/events{/privacy}","received_events_url":"https://api.github.com/users/renatoathaydes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-26T15:10:21Z","updated_at":"2016-11-26T16:48:52Z","closed_at":null,"body":"I am using the following Java code, approximately, to run Frege scripts:\r\n\r\n```java\r\nScriptEngine scriptEngine = new ScriptEngineManager().getEngineByName( \"frege\" );\r\n\r\nBindings bindings = scriptEngine.getBindings( ScriptContext.ENGINE_SCOPE );\r\nbindings.put( \"out\", out );\r\nbindings.put( \"err\", err );\r\nbindings.put( \"ctx\", bundleContext );\r\n\r\n@Nullable Object result = scriptEngine.eval( script );\r\n```\r\n\r\nThe bindings variables, `out`, `err` and `ctx` do not seem to be available in the script, as they should.\r\n\r\nI get this error when I try to access `out`, for example:\r\n\r\n```\r\nfrege.runtime.Undefined: [E <console>.fr:5: can't resolve `out`, did you mean `sum` perhaps?]\r\n```"},"comment":{"url":"https://api.github.com/repos/Frege/frege-interpreter/issues/comments/263073409","html_url":"https://github.com/Frege/frege-interpreter/issues/33#issuecomment-263073409","issue_url":"https://api.github.com/repos/Frege/frege-interpreter/issues/33","id":263073409,"user":{"login":"mmhelloworld","id":771425,"avatar_url":"https://avatars.githubusercontent.com/u/771425?v=3","gravatar_id":"","url":"https://api.github.com/users/mmhelloworld","html_url":"https://github.com/mmhelloworld","followers_url":"https://api.github.com/users/mmhelloworld/followers","following_url":"https://api.github.com/users/mmhelloworld/following{/other_user}","gists_url":"https://api.github.com/users/mmhelloworld/gists{/gist_id}","starred_url":"https://api.github.com/users/mmhelloworld/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mmhelloworld/subscriptions","organizations_url":"https://api.github.com/users/mmhelloworld/orgs","repos_url":"https://api.github.com/users/mmhelloworld/repos","events_url":"https://api.github.com/users/mmhelloworld/events{/privacy}","received_events_url":"https://api.github.com/users/mmhelloworld/received_events","type":"User","site_admin":false},"created_at":"2016-11-26T16:48:52Z","updated_at":"2016-11-26T16:48:52Z","body":"Hi,\r\n\r\nTwo things:\r\n\r\n1. The necessary mechanism to make bindings work is actually on the Frege script engine's `put` but you are actually directly modifying the `Bindings` object so it doesn't currently work with your approach. It would be nice to improve this but for now, you could do: `scriptEngine.put(...)` instead of `bindings.put`\r\n\r\n2. For the bindings, the type must be specified and the type must be known to Frege as shown in the test [here](https://github.com/Frege/frege-interpreter/blob/master/frege-interpreter-core/src/test/java/frege/interpreter/scriptengine/FregeScriptEngineTest.java#L62) with this snippet:\r\n\r\n```java\r\n        frege.put(\"bar :: Integer\", new BigInteger(\"12312332142343244\"));\r\n        final Object actual = frege.eval(\"bar + 3.big\");\r\n        final Object expected = new BigInteger(\"12312332142343247\");\r\n        assertEquals(expected, actual);\r\n```\r\n\r\nHere the type of `bar` is specified while calling `put` and the type `Integer` is the Frege equivalent of Java type `BigInteger`."}}
{"actor":{"display_login":"mmhelloworld"}}