@@ -15,6 +15,9 @@ import {
15
15
import { L } from './helper.js'
16
16
import { UnboundVariableError } from './errors.js'
17
17
18
+ const x = Symbol ( 'x' )
19
+ const y = Symbol ( 'y' )
20
+
18
21
describe ( 'apply' , ( ) => {
19
22
describe ( 'CAR' , ( ) => {
20
23
test ( 'returns the head elements when present' , ( ) => {
@@ -72,7 +75,8 @@ describe('apply', () => {
72
75
73
76
describe ( 'function is unknown atom' , ( ) => {
74
77
test ( 'function value is evaluated from context and then applies to arguments' , ( ) => {
75
- assert . strictEqual ( lApply ( 'atomAlias' , L ( NIL ) , L ( [ 'atomAlias' , ATOM ] ) ) , T )
78
+ const mySymbol = Symbol ( 'mySymbol' )
79
+ assert . strictEqual ( lApply ( mySymbol , L ( NIL ) , L ( [ mySymbol , ATOM ] ) ) , T )
76
80
} )
77
81
test ( 'function that does not exist in context should throw exception' , ( ) => {
78
82
assert . throws ( ( ) => lApply ( 'unknownSymbol' , L ( ) , L ( ) ) )
@@ -81,23 +85,19 @@ describe('apply', () => {
81
85
82
86
describe ( 'lambda' , ( ) => {
83
87
test ( 'returns evaluation result from lambda expression binding argument to parameter symbol' , ( ) => {
84
- assert . strictEqual ( lApply ( L ( LAMBDA , L ( 'x' ) , 'x' ) , L ( 12 ) ) , 12 )
88
+ assert . strictEqual ( lApply ( L ( LAMBDA , L ( x ) , x ) , L ( 12 ) ) , 12 )
85
89
} )
86
90
87
91
test ( 'multiple parameter bindings and function call expressions are evaluated' , ( ) => {
88
92
assert . deepStrictEqual (
89
- lApply ( L ( LAMBDA , L ( 'x' , 'y' ) , L ( CONS , 'x' , 'y' ) ) , L ( 1 , 2 ) ) ,
93
+ lApply ( L ( LAMBDA , L ( x , y ) , L ( CONS , x , y ) ) , L ( 1 , 2 ) ) ,
90
94
[ 1 , 2 ] ,
91
95
)
92
96
} )
93
97
94
98
test ( 'parameter bound variable value should shadow variable value in context' , ( ) => {
95
99
assert . strictEqual (
96
- lApply (
97
- L ( LAMBDA , L ( 'x' ) , 'x' ) ,
98
- L ( 'localValue' ) ,
99
- L ( [ 'x' , 'shadowedValue' ] ) ,
100
- ) ,
100
+ lApply ( L ( LAMBDA , L ( x ) , x ) , L ( 'localValue' ) , L ( [ x , 'shadowedValue' ] ) ) ,
101
101
'localValue' ,
102
102
)
103
103
} )
@@ -107,10 +107,10 @@ describe('apply', () => {
107
107
describe ( 'eval' , ( ) => {
108
108
describe ( 'binding' , ( ) => {
109
109
test ( 'should return bound argument' , ( ) => {
110
- assert . strictEqual ( lEval ( 'x' , L ( [ 'x' , 1 ] ) ) , 1 )
110
+ assert . strictEqual ( lEval ( x , L ( [ x , 1 ] ) ) , 1 )
111
111
} )
112
112
test ( 'should throw if symbol not found' , ( ) => {
113
- assert . throws ( ( ) => lEval ( 'x' , L ( ) ) , UnboundVariableError )
113
+ assert . throws ( ( ) => lEval ( x , L ( ) ) , UnboundVariableError )
114
114
} )
115
115
} )
116
116
} )
0 commit comments