carp-lang / Carp

A statically typed lisp, without a GC, for real-time applications.
Apache License 2.0
5.47k stars 173 forks source link

fix: Infinite loop when evaluating `(())` (#1427) #1456

Open Gavinok opened 1 year ago

Gavinok commented 1 year ago

Evaluation of (()) is treated as a malformed expression rather than causing an infinite loop.

hellerve commented 1 year ago

Thanks, this is super useful! 🎉

Can we add a test for this? I suggest we put one in test/test_for_errors where we keep the expected failing code snippets. Then we add the expected output to test/output. See this commit for an example.

Gavinok commented 1 year ago

No problem I am just happy to help. Should be good to go. Let me know if I missed anything

hellerve commented 1 year ago

Super! Maybe we should introduce a special error type to improve the error message—or maybe that would be overkill. What does everyone else think?

Gavinok commented 1 year ago

Not exactly sure what a better fitting existing error message would look like. Could try something like the error message of used for applying non functions.

You are trying to call the non-function `()` at line 4, column 2 in 'REPL'. at REPL:4:1.

That's just an idea for reusing an existing error. Don't have any clever unique ideas personally.

hellerve commented 1 year ago

Of the two, I personally prefer the non-function error message. But I’d wait for feedback from the others :)

eriksvedang commented 1 year ago

Very nice! I also prefer the non-function error.

Gavinok commented 1 year ago

@hellerve is there anyone else we are waiting to hear from?

hellerve commented 1 year ago

No, I think we’re good to merge. @eriksvedang is the only one with those rights, though :)

eriksvedang commented 1 year ago

The test suite fails on this branch – does it help if you merge in latest master?