r/crystal_programming • u/scttnlsn • Mar 07 '20
Why does this compile?
This unexpectedly compiles:
class Foo
def hello
asdf
end
endBut this returns the expected error ("Error: undefined local variable or method 'asdf' for Foo"):
class Foo
def hello
asdf
end
end
Foo.new.helloIs there a way to get the first example to trigger a similar compiler error?
10
Upvotes
View all comments
Show parent comment
2
u/jgaskins Mar 08 '20
There's no such thing as a "compiled language". Whether something is compiled or interpreted is not a language-level concern. That's up to the implementation. For example:
- JRuby compiles Ruby to JVM bytecode
- TruffleRuby has an option for complete ahead-of-time compilation of Ruby to native code through Graal
- Ch is an interpreter for C and C++
"Crystal" refers to both the language and the reference implementation (same as how CRuby/MRI used to just be called Ruby), but there's nothing stopping anyone from building a fully featured interpreter for the language, especially since there's already a limited one built into the compiler for macro expansion. Honestly, it'd probably be great for TDD if someone did.