-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Implement cond #15
base: main
Are you sure you want to change the base?
Implement cond #15
Conversation
@@ -16,3 +16,19 @@ test('Translate LISP to JavaScript', () => { | |||
const expected = 22; | |||
assert.strictEqual(result, expected); | |||
}); | |||
|
|||
test('Translate LISP condition to JavaScript', () => { | |||
// TODO: replace with comparison operators when they are implemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could use eq
here but it doesn't transform properly #14
73e1160
to
f768415
Compare
lib/expressions.js
Outdated
let header = '('; | ||
|
||
for (const identifier of this.identifiers) { | ||
if (header.length > 1) { | ||
header += ', '; | ||
} | ||
header += identifier; | ||
} | ||
|
||
header += ')'; | ||
|
||
return `${header} => ${this.toExpression()}`; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoid creating an extra array as Murych suggested
} else if (operand instanceof OperationExpression) { | ||
for (const name of operand.identifiers.values()) { | ||
if (operand.identifiers !== undefined) { | ||
for (const name of operand.identifiers) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think information expert works well here
// eslint-disable-next-line consistent-return | ||
interpret(context) { | ||
for (const { condition, consequents } of this.clauses) { | ||
if (condition.interpret(context) !== false) { | ||
return consequents.reduce( | ||
(_, consequent) => consequent.interpret(context), | ||
undefined, | ||
); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lisp returns nil if there are no matches. What behavior do we expect? Currently it returns undefined in this case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Compact empty lines and one-operator blocks
- Move oll fields to constructor
#9
npm t
)npm run fix
)