Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Implement cond #15

wants to merge 3 commits into from

Conversation

leonid-shutov
Copy link

@leonid-shutov leonid-shutov commented Dec 15, 2024

#9

  • tests and linter show no problems (npm t)
  • tests are added/updated for bug fixes and new features
  • code is properly formatted (npm run fix)
  • description of changes is added in CHANGELOG.md
  • update .d.ts typings

@leonid-shutov leonid-shutov changed the title implement cond Implement cond Dec 15, 2024
@@ -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
Copy link
Author

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

@leonid-shutov leonid-shutov force-pushed the main branch 2 times, most recently from 73e1160 to f768415 Compare December 20, 2024 19:04
Comment on lines 75 to 80
let header = '(';

for (const identifier of this.identifiers) {
if (header.length > 1) {
header += ', ';
}
header += identifier;
}

header += ')';

return `${header} => ${this.toExpression()}`;
}
Copy link
Author

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) {
Copy link
Author

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

Comment on lines +113 to +115
// 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,
);
}
}
}
Copy link
Author

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

Copy link
Member

@tshemsedinov tshemsedinov left a 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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants