Skip to content

Instantly share code, notes, and snippets.

@kenwebb
Last active June 17, 2019 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kenwebb/1bd86906cc9f819062ee4abdc9025d4d to your computer and use it in GitHub Desktop.
Save kenwebb/1bd86906cc9f819062ee4abdc9025d4d to your computer and use it in GitHub Desktop.
MLKit
<?xml version="1.0" encoding="UTF-8"?>
<!--Xholon Workbook http://www.primordion.com/Xholon/gwt/ MIT License, Copyright (C) Ken Webb, Mon Jun 17 2019 12:12:03 GMT-0400 (Eastern Daylight Time)-->
<XholonWorkbook>
<Notes><![CDATA[
Xholon
------
Title: MLKit
Description:
Url: http://www.primordion.com/Xholon/gwt/
InternalName: 1bd86906cc9f819062ee4abdc9025d4d
Keywords:
My Notes
--------
June 17, 2019
I created a new directory on my computer: ~/mlspace
See README.txt in the new directory.
- includes complete instructions on how I instaled MLKit
I was unable to run mlkit itsle, due to a conflict between amd64 and i386 support.
But I am able to run smltojs, and execute the resulting app in a web browser.
The MLKit installation includes:
SMLtoJs — Compile SML programs into JavaScript.
My goal is to use MLKit-generated JavaScript code as part of Xholon applications.
example:
=======
fact.sml
--------
fun fact n : IntInf.int =
if n=0 then 1 else n * fact(n - 1)
val () =
print (IntInf.toString (fact 120) ^ "\n")
compile
-------
cd ~/mlspace/kswcode01
smltojs -o fact fact.sml
[Created file fact.html]
generated .html
---------------
<!-- JavaScript generated by SmlToJs - Standard ML to JavaScript Compiler -->
<!-- See http://www.smlserver.org/smltojs -->
<script type="text/javascript" src="/usr/lib/smltojs/prims.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/Initial-sml.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/General-sml.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/List-sml.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/Vector-sml-code3.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/ByteTable-sml-code5.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/StringCvt-sml.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/StrBase-sml.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/Char-sml.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/IntInfRep-sml.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/Word32-sml.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/Int32-sml.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/Int31-sml.js"></script>
<script type="text/javascript" src="/usr/lib/smltojs/basis/MLB/Js/IntInf-sml.js"></script>
<script type="text/javascript" src="./MLB/Js/fact-sml.js"></script>
generated .js
-------------
if ((typeof(fact$2auto$0fact$1)) == "undefined") {fact$2auto$0fact$1 = {};
};
(function(){var fix$136 = {};
fix$136.$fact = function(n$48){var t$137;
var v$120 = [0,[null,false]];
switch (v$120[0]) { case 0: {var v$126 = n$48[1];
var v$127 = v$120[1];
var t$141;
var fix$138 = {};
fix$138.$eq_list = function(v$130,v$131){lab$eq_list: while (true) {if (v$130 == null) {return (v$131 == null)?true:false;
} else {if (v$131 == null) {return false;
} else {var v$132 = v$130;
var v$133 = v$131;
if (v$132[0] == v$133[0]) {var t$139 = v$132[1];
var t$140 = v$133[1];
var v$130 = t$139;
var v$131 = t$140;
continue lab$eq_list;
} else {return false;
};
};
};
};
};
var eq_list$128 = fix$138.$eq_list;
t$141 = (eq_list$128(v$126[0],v$127[0]));
t$137 = (t$141?(v$126[1] == v$127[1]):false);
break; }default: {t$137 = false;
} };
if (t$137) {return [0,[[1,null],false]];
} else {return basis$0IntInfRep$1.s$t$1207(n$48,fix$136.$fact(basis$0IntInfRep$1.s$g$1251(n$48,[0,[[1,null],false]])));
};
};
fact$2auto$0fact$1.fact$45 = fix$136.$fact;
basis$0General$1.print$156((basis$0IntInf$1.toString$2342(fact$2auto$0fact$1.fact$45([0,[[120,null],false]]))) + "\n");
return 0;
})();
smltojs -help > help.txt
-------------
--import_basislib, -basislib (on)
Import Basis Library automatically in your projects. If
you wish to make use of the Standard ML Basis Library
in your projects, this option should be turned on, unless
you wish to import the Basis Library manually in your
projects.
--javascript_library_paths S, -jslibs S
Use this option to add javascript library paths
to the generated html and thereby allow for SML
code to reference existing JavaScript libraries.
--js_path_relative_to S
Absolute directory for which each absolute
Javascript file path is made relative to in
the resulting run.html file.
References
----------
(1) https://github.com/melsman/mlkit
(2) http://elsman.com/mlkit/doc
(3) http://elsman.com/mlkit/
The Standard ML Compiler and Toolkit
The MLKit compiler covers all of Standard ML, as defined in the 1997 edition of the Definition of Standard ML.
The MLKit implements most of the latest Standard ML Basis Library specification.
(4) http://sml.sourceforge.net/Basis/
(5) https://github.com/melsman/mlkit/blob/master/README_SMLTOJS.md
SMLtoJs (pronounced "SML toys") is a compiler from Standard ML to JavaScript,
which allows programmers to enjoy the power of Standard ML static typing,
higher-order functions, pattern matching, and modules for programming client-side web applications.
SMLtoJs compiles all of Standard ML, including most of the Standard ML Basis Library.
It also has good support for integrating with JavaScript.
Compiling in the Browser. A version of SMLtoJs can be compiled by SMLtoJs itself, which leads to a proper browser hosted Standard ML compiler.
]]></Notes>
<_-.XholonClass>
<!-- domain objects -->
<PhysicalSystem/>
<Block/>
<Brick/>
<!-- quantities -->
<Height superClass="Quantity"/>
</_-.XholonClass>
<xholonClassDetails>
<Block>
<port name="height" connector="Height"/>
</Block>
</xholonClassDetails>
<PhysicalSystem>
<Block>
<Height>0.1 m</Height>
</Block>
<Brick multiplicity="2"/>
</PhysicalSystem>
<Blockbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var a = 123;
var b = 456;
var c = a * b;
if (console) {
console.log(c);
}
//# sourceURL=Blockbehavior.js
]]></Blockbehavior>
<Heightbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
var myHeight, testing;
var beh = {
postConfigure: function() {
testing = Math.floor(Math.random() * 10);
myHeight = this.cnode.parent();
},
act: function() {
myHeight.println(this.toString());
},
toString: function() {
return "testing:" + testing;
}
}
//# sourceURL=Heightbehavior.js
]]></Heightbehavior>
<Brickbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
$wnd.xh.Brickbehavior = function Brickbehavior() {}
$wnd.xh.Brickbehavior.prototype.postConfigure = function() {
this.brick = this.cnode.parent();
this.iam = " red brick";
};
$wnd.xh.Brickbehavior.prototype.act = function() {
this.brick.println("I am a" + this.iam);
};
//# sourceURL=Brickbehavior.js
]]></Brickbehavior>
<Brickbehavior implName="org.primordion.xholon.base.Behavior_gwtjs"><![CDATA[
console.log("I'm another brick behavior");
]]></Brickbehavior>
<SvgClient><Attribute_String roleName="svgUri"><![CDATA[data:image/svg+xml,
<svg width="100" height="50" xmlns="http://www.w3.org/2000/svg">
<g>
<title>Block</title>
<rect id="PhysicalSystem/Block" fill="#98FB98" height="50" width="50" x="25" y="0"/>
<g>
<title>Height</title>
<rect id="PhysicalSystem/Block/Height" fill="#6AB06A" height="50" width="10" x="80" y="0"/>
</g>
</g>
</svg>
]]></Attribute_String><Attribute_String roleName="setup">${MODELNAME_DEFAULT},${SVGURI_DEFAULT}</Attribute_String></SvgClient>
</XholonWorkbook>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment