carp-lang / Carp

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

feature request. more explicit error for unknown top level form #1330

Open rgkirch opened 3 years ago

rgkirch commented 3 years ago

This code is bad because I have a (do (fun 0)) out in space when that's not a valid thing to do in c. I expect it to be not uncommon for a beginner (like me) since it looks/feels like Clojure where that's a totally normal thing to do. It's not really an issue but I think it's worth mentioning. Thanks.

(use IO)

(register fun (Fn [Int] Int))

(do
  (fun 0))

(defn main []
  (println* "hey"))
$ carp no.carp -x
I did not understand the form `(external fun (Fn [Int] Int))` at C:/Users/richie/Documents/org/projects/handmade-carp/no.carp:3:15.

Traceback:
  (fun 0) at C:/Users/richie/Documents/org/projects/handmade-carp/no.carp:6:3.
(do (fun 0)) at C:/Users/richie/Documents/org/projects/handmade-carp/no.carp:5:1.
rgkirch commented 3 years ago

Actually, it's not a normal thing to do in clojure. I do it all the time because I can send the forms to the repl but I delete it when I'm done. Yea, not an issue. I'd still like a better error message though. It may be good enough to distinguish "not a valid top level form" from the catch all "idk what that is". Initially, I assumed it was a problem with registering the c function...

eriksvedang commented 3 years ago

This should work though, you can call functions from the repl or from top-level in a file like that. So this seems like another bug with the detection of static code maybe.

eriksvedang commented 3 years ago

Seems related to the (do ...).

rgkirch commented 3 years ago

Ok, thanks!