{"category":{"__v":2,"_id":"566e55c12c1e760d0030c56d","pages":["566e55c12c1e760d0030c56e","566e55c12c1e760d0030c56f","566e55c12c1e760d0030c570","566e55c12c1e760d0030c571","566e55c12c1e760d0030c572","566e55c12c1e760d0030c573","566e55c12c1e760d0030c574","566e55c12c1e760d0030c575","566e55c12c1e760d0030c576","566e55c12c1e760d0030c577","566e55c12c1e760d0030c578","566e55c12c1e760d0030c579","566e55c12c1e760d0030c57a","566e55c12c1e760d0030c57b","566e55c12c1e760d0030c57c","566e55c12c1e760d0030c57d","566e55c12c1e760d0030c57e","566e55c12c1e760d0030c57f","566e55c12c1e760d0030c580","566e55c12c1e760d0030c581","566e55c12c1e760d0030c582","566e55c12c1e760d0030c583","566e55c12c1e760d0030c584","566e55c12c1e760d0030c585","566e55c12c1e760d0030c586","566e55c12c1e760d0030c587","566e55c12c1e760d0030c588","566e5640c15c8f0d000ee863"],"project":"54408e54309354080070a896","version":"566e55c02c1e760d0030c56c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-10-17T03:34:44.886Z","from_sync":false,"order":0,"slug":"documentation","title":"Documentation"},"project":"54408e54309354080070a896","user":"544083bee239230800071bef","version":{"__v":1,"_id":"566e55c02c1e760d0030c56c","project":"54408e54309354080070a896","createdAt":"2015-12-14T05:38:08.400Z","releaseDate":"2015-12-14T05:38:08.400Z","categories":["566e55c12c1e760d0030c56d"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.2.3","version":"1.2.3"},"_id":"566e55c12c1e760d0030c575","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-05-10T01:51:37.102Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":7,"body":"# Introduction\n\nJulia modules may be imported from Javascript using a syntax similar to that used by *[common.js](http://requirejs.org/docs/commonjs.html)*.  Upon import of a Julia package, a Javascript object is created with function objects corresponding to the exported functions declared in the module declared by the Julia package.\n# Julia Dict to JSON to Javascript\n\nThe following example illustrates the concept:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var julia = require('node-julia');\\nvar juliaJSON = julia.import('JSON');\\n\\n// Create a JRef of a Julia Dict then export that JSON of\\n// the Dict, but Julia exports this as a string, so then\\n// use JSON.parse on the output.\\n\\nvar x = julia.eval('Dict(\\\"a\\\" => \\\"b\\\")');\\nvar y = juliaJSON.json(x);\\n\\nconsole.log(JSON.parse(y));\\t\",\n      \"language\": \"javascript\",\n      \"name\": \"DictToJSON.js\"\n    }\n  ]\n}\n[/block]\n# The *functionNames* variable\n\nIn addition to all of the functions exported from the Julia package, being equated to Javascript functions, the *functionNames* variable is an array of strings of all of names of those functions and can be seen using the following example:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var julia = require('node-julia');\\nvar JuMP = julia.import('JuMP');\\n\\nconsole.log(JSON.stringify(JuMP.functionNames,null,2));\",\n      \"language\": \"javascript\",\n      \"name\": \"FunctionNames.js\"\n    }\n  ]\n}\n[/block]\n## Output\n\n    [\n      \":::at:::LinearConstraint\",\n      \"@LinearConstraints\",\n      \"@QuadConstraint\",\n\n    ...\n\n      \"setLower\",\n      \"setName\",\n      \"setObjective\",\n      \"setObjectiveSense\",\n      \"setPrintHook\",\n      \"setSolutionValue!\",\n      \"setSolveHook\",\n      \"setSolver\",\n      \"setUpper\",\n      \"setValue\",\n      \"solve\",\n      \"writeLP\",\n      \"writeMPS\"\n    ]\n\n# Caveat for Macro Functions\nNote how macro names are also included, however there are 2 things to remember here.  First, the character **@** is illegal as a field identifier in Javascript, so referring to the example above, **@LinearConstraint** could be invoked using the following `JuMP['@LinearConstraint'](...)`, but currently the effect is not what is expected; a quote block is returned rather than an inline expansion and evaluation.  Thus, macros invoked in this way will be seldom used, nevertheless, they are included for completeness.\n\n# Example: using JuMP\n\nExtending the above example, and taking from the [JuMP simple example](http://jump.readthedocs.org/en/release-0.9/quickstart.html#simple-example), and noting the use of `julia.eval(...)` when invoking macros, JuMP can be used as follows:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"var julia = require('node-julia');\\nvar JuMP = julia.import('JuMP');\\nvar m = julia.eval('m = JuMP.Model()');\\nvar x = julia.eval('JuMP.@defVar(m,0 <= x <= 2)');\\nvar y = julia.eval('JuMP.@defVar(m,0 <= y <= 30)');\\n\\njulia.eval('JuMP.@setObjective(m,Max, 5x + 3*y)');\\njulia.eval('JuMP.@addConstraint(m,1x + 5y <= 3.0)');\\n\\nvar status = JuMP.solve(m);\\n\\nconsole.log('Objective value: ',JuMP.getObjectiveValue(m));\\nconsole.log('X value: ',JuMP.getValue(x));\\nconsole.log('Y value: ',JuMP.getValue(y));\\n\",\n      \"language\": \"javascript\",\n      \"name\": \"using_JuMP.js\"\n    }\n  ]\n}\n[/block]\n## Output\n\n    Objective value:  10.6\n    X value:  2\n    Y value:  0.2","excerpt":"","slug":"import","type":"basic","title":"Import"}
# Introduction Julia modules may be imported from Javascript using a syntax similar to that used by *[common.js](http://requirejs.org/docs/commonjs.html)*. Upon import of a Julia package, a Javascript object is created with function objects corresponding to the exported functions declared in the module declared by the Julia package. # Julia Dict to JSON to Javascript The following example illustrates the concept: [block:code] { "codes": [ { "code": "var julia = require('node-julia');\nvar juliaJSON = julia.import('JSON');\n\n// Create a JRef of a Julia Dict then export that JSON of\n// the Dict, but Julia exports this as a string, so then\n// use JSON.parse on the output.\n\nvar x = julia.eval('Dict(\"a\" => \"b\")');\nvar y = juliaJSON.json(x);\n\nconsole.log(JSON.parse(y));\t", "language": "javascript", "name": "DictToJSON.js" } ] } [/block] # The *functionNames* variable In addition to all of the functions exported from the Julia package, being equated to Javascript functions, the *functionNames* variable is an array of strings of all of names of those functions and can be seen using the following example: [block:code] { "codes": [ { "code": "var julia = require('node-julia');\nvar JuMP = julia.import('JuMP');\n\nconsole.log(JSON.stringify(JuMP.functionNames,null,2));", "language": "javascript", "name": "FunctionNames.js" } ] } [/block] ## Output [ "@LinearConstraint", "@LinearConstraints", "@QuadConstraint", ... "setLower", "setName", "setObjective", "setObjectiveSense", "setPrintHook", "setSolutionValue!", "setSolveHook", "setSolver", "setUpper", "setValue", "solve", "writeLP", "writeMPS" ] # Caveat for Macro Functions Note how macro names are also included, however there are 2 things to remember here. First, the character **@** is illegal as a field identifier in Javascript, so referring to the example above, **@LinearConstraint** could be invoked using the following `JuMP['@LinearConstraint'](...)`, but currently the effect is not what is expected; a quote block is returned rather than an inline expansion and evaluation. Thus, macros invoked in this way will be seldom used, nevertheless, they are included for completeness. # Example: using JuMP Extending the above example, and taking from the [JuMP simple example](http://jump.readthedocs.org/en/release-0.9/quickstart.html#simple-example), and noting the use of `julia.eval(...)` when invoking macros, JuMP can be used as follows: [block:code] { "codes": [ { "code": "var julia = require('node-julia');\nvar JuMP = julia.import('JuMP');\nvar m = julia.eval('m = JuMP.Model()');\nvar x = julia.eval('JuMP.@defVar(m,0 <= x <= 2)');\nvar y = julia.eval('JuMP.@defVar(m,0 <= y <= 30)');\n\njulia.eval('JuMP.@setObjective(m,Max, 5x + 3*y)');\njulia.eval('JuMP.@addConstraint(m,1x + 5y <= 3.0)');\n\nvar status = JuMP.solve(m);\n\nconsole.log('Objective value: ',JuMP.getObjectiveValue(m));\nconsole.log('X value: ',JuMP.getValue(x));\nconsole.log('Y value: ',JuMP.getValue(y));\n", "language": "javascript", "name": "using_JuMP.js" } ] } [/block] ## Output Objective value: 10.6 X value: 2 Y value: 0.2