Can you name languages with static type checking (like Java) and where code is data (like in LISP)? I mean both things in one language.
相关问题
- Generating powerset in one function, no explicit r
- Forming Lisp code to task — related to flatten lis
- Is divide by zero an error or an exception?
- unfold function in scheme
- Confused by Lisp Quoting
相关文章
- Does learning one Lisp help in learning the other?
- Are there any reasons not to use “this” (“Self”, “
- What is the definition of “natural recursion”?
- How do I write a macro-defining macro in common li
- Call/Return feature of classic C++(C with Classes)
- How can I unintern a qualified method?
- What are the major differences between C and C++ a
- Changing the nth element of a list
Maybe Strongtalk or Zero which are reflective system a la Smalltalk, but are statically typed.
Racket (formerly PLT Scheme) has a statically typed dialect, which is designed to work nicely with Scheme idioms -- including macros. (It works by type-checking the expansion results.)
Qi is a statically-typed Lisp dialect. Also, many other Lisp dialects have (optional) static typing.
Java itself has very limited capabilities of this kind.
The interesting question is not so much whether you can have metaprogramming and static typing, it's whether you can have dynamic metaprogramming be statically type-safe.
There is Template Haskell which does metaprogramming and is type-safe, but it is static metaprogramming.
At the moment I can not think of any language that I know for a fact allows dynamic metaprogramming and where dynamic metaprogramming is statically type-safe. Qi might be bale to do it, but I'm not sure.
Template Haskell is statically typed but allows you to manipulate code as data, aka metaprogramming. Related languages include MetaML and MetaOCaml. Look up the work of Tim Sheard.
F# has Quotation expressions. From the MSDN page:
I think these are available in C#, but (1) I don't know what the syntax is (2) the data structures are different.
These languages allow code as data at compile time, like Lisp macros:
Disclaimer: I haven't really used any of these. As far as I know, they are all much more complicated than Lisp's
quote
.However, 90% of "Code as data" using
quote
can be accomplished with closures, since they delay evaluation too. Many languages have a convenient syntax for making closures (C#, Clojure, Scala and Ruby especially come to mind) and don't needquote
that much. Even in Scheme, which is a definitive Lisp, the prevailing style favours passing functions over writing macros.If you're simply looking for the ability to execute code dynamically in a statically typed language, then Java itself can do that:
http://www.javaworld.com/javaworld/jw-06-2006/jw-0612-dynamic.html
If you need more than that (want methods and classes as first-class objects, etc.), then you'll want to use something like Haskell or C# (as mentioned in other answers) instead.