1
0
mirror of https://github.com/Baidicoot/rpncalc-v4 synced 2024-12-04 15:29:54 +00:00

unsafeCoerce

This commit is contained in:
Aidan K. Ewart 2020-05-31 03:19:30 +01:00
parent 75dedb204a
commit 908af0dd72
3 changed files with 5 additions and 4 deletions

View File

@ -52,6 +52,7 @@ const snd = (_, args) => [args[0].snd];
const eq = (_, args) => {
if (args[0].type === args[1].type && args[0].val === args[1].val) {
console.log(args[0], args[1])
return [{type:"ident", val:"true"}];
} else {
return [{type:"ident", val:"false"}];
@ -92,7 +93,7 @@ addDefn("snd", ["pair"], snd);
addDefn("arr", ["int"], arr);
addDefn("!!", ["int", "array"], index);
addDefn("len", ["array"], len);
addDefn("coerce", 2, coerce);
addDefn("unsafeCoerce", 2, coerce);
//addRPNDefn("unit", "(-> 0 arr)");
//addRPNDefn("mono", "(-> 1 arr)");
//addRPNDefn("unwrap", "(-> 0 !!)");

View File

@ -33,9 +33,10 @@ can call <code>fst</code> and <code>snd</code> on pairs
<h3>Type Literals</h3>
Essentialy strings.
<br>
Example useage: <code>"1 "int coerce 1 +</code>
Example useage: <code>"1 "int unsafeCoerce 1 +</code>
<h3>Equality</h3>
Internaly JS-based, derived for all objects, pushes lambdas representing true and false onto the stack.
<br>
For example: <code>"true-option "false-option val1 val2 ==</code>
<h2>Examples</h2>
factorial: <code>(!; x -> 1 '(-> x 1 - ! x *) x 0 ==)</code>

View File

@ -145,12 +145,11 @@ const parseName = (stream) => {
}
const parseType = (stream) => {
let syn = attempt(parseSyntax("\""))(stream);
if (syn.parsed === null) {
return {parsed:null, stream:syn.stream};
}
let id = parseIdent(syn.stream);
let id = or(parseIdent, parseInteger)(syn.stream);
if (id.parsed === null) {
return {parsed:null, stream:id.stream};
}