No 666
This commit is contained in:
parent
0890607493
commit
5a0b436932
|
@ -30,15 +30,29 @@ describe("Arity check", () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("function trics", () => {
|
describe("symbol not defined", () => {
|
||||||
testEvalToBe("f(x)=x(y); f(f)", "Error(y is not defined)")
|
testEvalToBe("f(x)=x(y); f(f)", "Error(y is not defined)")
|
||||||
testEvalToBe("f(x)=x; f(f)", "Ok(lambda(x=>internal code))")
|
testEvalToBe("f(x)=x; f(f)", "Ok(lambda(x=>internal code))")
|
||||||
testEvalToBe("f(x)=x(y); f(z)", "Error(z is not defined)")
|
testEvalToBe("f(x)=x(y); f(z)", "Error(z is not defined)")
|
||||||
testEvalToBe("f(x)=x(y); f(2)", "Error(2 is not a function)")
|
testEvalToBe("f(x)=x(y); f(2)", "Error(2 is not a function)")
|
||||||
testEvalToBe("f(x)=x(1); f(2)", "Error(2 is not a function)")
|
testEvalToBe("f(x)=x(1); f(2)", "Error(2 is not a function)")
|
||||||
MySkip.testParseToBe("f(x)=f(y)=2; f(2)", "????")
|
})
|
||||||
MySkip.testEvalToBe("f(x)=f(y)=2; f(2)", "????") //prevent multiple assignment
|
|
||||||
testEvalToBe("f(x)=x+1; g(x)=f(x)+1;g(2)", "????") //TODO: f is not found
|
Only.describe("call and bindings", () => {
|
||||||
|
testEvalToBe("f(x)=x+1", "Ok({f: lambda(x=>internal code)})")
|
||||||
|
testEvalToBe("f(x)=x+1; f(1)", "Ok(2)")
|
||||||
|
testEvalToBe("f=1;y=2", "Ok({f: 1,y: 2})")
|
||||||
|
testEvalToBe("f(x)=x+1; y=f(1)", "Ok({f: lambda(x=>internal code),y: 2})")
|
||||||
|
testEvalToBe("f(x)=x+1; y=f(1); f(1)", "Ok(2)")
|
||||||
|
testEvalToBe("f(x)=x+1; y=f(1); z=f(1)", "Ok({f: lambda(x=>internal code),y: 2,z: 2})")
|
||||||
|
testEvalToBe("f(x)=x+1; g(x)=f(x)+1", "Ok({f: lambda(x=>internal code),g: lambda(x=>internal code)})") //TODO: f is not found
|
||||||
|
MyOnly.testEvalToBe("f(x)=x+1; g(x)=f(x)+1; y=g(2)", "????") //TODO: f is not found
|
||||||
|
MySkip.testEvalToBe("f(x)=x+1; g(x)=f(x)+1; g(2)", "????") //TODO: f is not found
|
||||||
|
})
|
||||||
|
|
||||||
|
Skip.describe("function trics", () => {
|
||||||
|
MySkip.testParseToBe("f(x)=f(y)=2; f(2)", "????") // TODO: No multiple assignment
|
||||||
|
MySkip.testEvalToBe("f(x)=f(y)=2; f(2)", "????") // TODO: No multiple assignment
|
||||||
MySkip.testEvalToBe("y=2;g(x)=y+1;g(2)", "????") //TODO : y is not found
|
MySkip.testEvalToBe("y=2;g(x)=y+1;g(2)", "????") //TODO : y is not found
|
||||||
MySkip.testEvalToBe("y=2;g(x)=inspect(y)+1", "????") //TODO : 666
|
MySkip.testEvalToBe("y=2;g(x)=inspect(y)+1", "????") //TODO : 666
|
||||||
})
|
})
|
||||||
|
|
|
@ -41,12 +41,7 @@ let dispatchMacroCall = (
|
||||||
let doBindExpression = (bindingExpr: expression, statement: expression, environment) =>
|
let doBindExpression = (bindingExpr: expression, statement: expression, environment) =>
|
||||||
switch statement {
|
switch statement {
|
||||||
| ExpressionT.EList(list{ExpressionT.EValue(EvCall("$let")), symbolExpr, statement}) => {
|
| ExpressionT.EList(list{ExpressionT.EValue(EvCall("$let")), symbolExpr, statement}) => {
|
||||||
let rExternalBindingsValue = reduceExpression(
|
let rExternalBindingsValue = reduceExpression(bindingExpr, bindings, environment)
|
||||||
bindingExpr,
|
|
||||||
Belt.Map.String.fromArray([("x", ExpressionValue.EvNumber(666.))]),
|
|
||||||
// bindingsToHandDown,
|
|
||||||
environment,
|
|
||||||
)
|
|
||||||
|
|
||||||
rExternalBindingsValue->Result.flatMap(externalBindingsValue => {
|
rExternalBindingsValue->Result.flatMap(externalBindingsValue => {
|
||||||
let newBindings = Bindings.fromValue(externalBindingsValue)
|
let newBindings = Bindings.fromValue(externalBindingsValue)
|
||||||
|
|
|
@ -33,6 +33,8 @@ let rec reduceExpression = (expression: t, bindings: T.bindings, environment: en
|
||||||
expressionValue,
|
expressionValue,
|
||||||
'e,
|
'e,
|
||||||
> =>
|
> =>
|
||||||
|
{
|
||||||
|
Js.log(`reduce: ${T.toString(expression)} bindings: ${bindings->Bindings.toString}`)
|
||||||
switch expression {
|
switch expression {
|
||||||
| T.EValue(value) => value->Ok
|
| T.EValue(value) => value->Ok
|
||||||
| T.EList(list) =>
|
| T.EList(list) =>
|
||||||
|
@ -45,7 +47,7 @@ let rec reduceExpression = (expression: t, bindings: T.bindings, environment: en
|
||||||
}
|
}
|
||||||
| _ => reduceExpressionList(list, bindings, environment)
|
| _ => reduceExpressionList(list, bindings, environment)
|
||||||
}
|
}
|
||||||
}
|
}}
|
||||||
|
|
||||||
and reduceExpressionList = (
|
and reduceExpressionList = (
|
||||||
expressions: list<t>,
|
expressions: list<t>,
|
||||||
|
|
|
@ -79,3 +79,6 @@ and checkIfCallable = (evValue: expressionValue) =>
|
||||||
| EvCall(_) | EvLambda(_) => evValue->Ok
|
| EvCall(_) | EvLambda(_) => evValue->Ok
|
||||||
| _ => ErrorValue.RENotAFunction(ExpressionValue.toString(evValue))->Error
|
| _ => ErrorValue.RENotAFunction(ExpressionValue.toString(evValue))->Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let toString = (bindings: ExpressionT.bindings) =>
|
||||||
|
bindings->toExternalBindings->ExpressionValue.EvRecord->ExpressionValue.toString
|
||||||
|
|
Loading…
Reference in New Issue
Block a user