mirror of https://github.com/Baidicoot/rpncalc-v4
unsafeCoerce
This commit is contained in:
parent
75dedb204a
commit
908af0dd72
|
@ -52,6 +52,7 @@ const snd = (_, args) => [args[0].snd];
|
||||||
|
|
||||||
const eq = (_, args) => {
|
const eq = (_, args) => {
|
||||||
if (args[0].type === args[1].type && args[0].val === args[1].val) {
|
if (args[0].type === args[1].type && args[0].val === args[1].val) {
|
||||||
|
console.log(args[0], args[1])
|
||||||
return [{type:"ident", val:"true"}];
|
return [{type:"ident", val:"true"}];
|
||||||
} else {
|
} else {
|
||||||
return [{type:"ident", val:"false"}];
|
return [{type:"ident", val:"false"}];
|
||||||
|
@ -92,7 +93,7 @@ addDefn("snd", ["pair"], snd);
|
||||||
addDefn("arr", ["int"], arr);
|
addDefn("arr", ["int"], arr);
|
||||||
addDefn("!!", ["int", "array"], index);
|
addDefn("!!", ["int", "array"], index);
|
||||||
addDefn("len", ["array"], len);
|
addDefn("len", ["array"], len);
|
||||||
addDefn("coerce", 2, coerce);
|
addDefn("unsafeCoerce", 2, coerce);
|
||||||
//addRPNDefn("unit", "(-> 0 arr)");
|
//addRPNDefn("unit", "(-> 0 arr)");
|
||||||
//addRPNDefn("mono", "(-> 1 arr)");
|
//addRPNDefn("mono", "(-> 1 arr)");
|
||||||
//addRPNDefn("unwrap", "(-> 0 !!)");
|
//addRPNDefn("unwrap", "(-> 0 !!)");
|
||||||
|
|
|
@ -33,9 +33,10 @@ can call <code>fst</code> and <code>snd</code> on pairs
|
||||||
<h3>Type Literals</h3>
|
<h3>Type Literals</h3>
|
||||||
Essentialy strings.
|
Essentialy strings.
|
||||||
<br>
|
<br>
|
||||||
Example useage: <code>"1 "int coerce 1 +</code>
|
Example useage: <code>"1 "int unsafeCoerce 1 +</code>
|
||||||
<h3>Equality</h3>
|
<h3>Equality</h3>
|
||||||
Internaly JS-based, derived for all objects, pushes lambdas representing true and false onto the stack.
|
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>
|
For example: <code>"true-option "false-option val1 val2 ==</code>
|
||||||
<h2>Examples</h2>
|
<h2>Examples</h2>
|
||||||
factorial: <code>(!; x -> 1 '(-> x 1 - ! x *) x 0 ==)</code>
|
factorial: <code>(!; x -> 1 '(-> x 1 - ! x *) x 0 ==)</code>
|
||||||
|
|
|
@ -145,12 +145,11 @@ const parseName = (stream) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseType = (stream) => {
|
const parseType = (stream) => {
|
||||||
|
|
||||||
let syn = attempt(parseSyntax("\""))(stream);
|
let syn = attempt(parseSyntax("\""))(stream);
|
||||||
if (syn.parsed === null) {
|
if (syn.parsed === null) {
|
||||||
return {parsed:null, stream:syn.stream};
|
return {parsed:null, stream:syn.stream};
|
||||||
}
|
}
|
||||||
let id = parseIdent(syn.stream);
|
let id = or(parseIdent, parseInteger)(syn.stream);
|
||||||
if (id.parsed === null) {
|
if (id.parsed === null) {
|
||||||
return {parsed:null, stream:id.stream};
|
return {parsed:null, stream:id.stream};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue