2

In Metaprogramming Ruby, the author states that only a few languages, including Ruby, can manipulate themselves at runtime. What other languages besides Ruby can support this type of metaprogramming?

The specific quote I'm referring to is in the introduction on page xix:

In this book, I'll stick to a different meaning of metaprogramming, focusing on code that manipulates itself at runtime. Only a few languages can do that effectively, and Ruby is one of them. You can think of this as dynamic metaprogramming to distinguish it from the static metaprogramming of code generators and compilers.

1
  • Python, JavaScript, many LISP dialects, at least. Approaches/limitations/acceptable patterns vary. Commented Jul 7, 2012 at 1:27

1 Answer 1

6

Most languages now days are moving towards providing that kind of functionality, but it's generally not as "clean" as it's in ruby. All these languages have a lot of those capabilities (reference):

  • ActionScript
  • BASIC
  • BeanShell[3]
  • Clojure
  • ColdFusion
  • Common Lisp and most other Lisps
  • Groovy[4]
  • E programming language
  • JavaScript
  • VBScript
  • MATLAB / Octave
  • Lua
  • Objective-C
  • Perl
  • PHP
  • Powershell
  • Python
  • Ruby
  • Smalltalk
  • Tcl

Other languages such as Java and C# (reference) have ways of inspecting and creating code at run time, but it's not so "natural" as in those languages, and it feels a lot like a hack.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reference. I think the question was more about the author's opinion than I first realized. He says only a few do it "effectively", so I guess I was thinking it was more cut and dry than it is. One person's opinion of "effectively" might be different than another's.
Although missing from that Wikipedia page, array languages typically have extreme (and consistent) capabilities for creating and/or replacing code dynamically. Those capabilities are not normally considered attractive in practice, however.
I am the author in question, and yes, I would put stress on "effectively". :) I agree with this answer that most modern languages provide some kind of runtime "metaprogramming" capability, but only a few languages make this feel like an integral part of the language, and even fewer make the border between "regular programming" and "metaprogramming" as indistinct as Ruby or LISP dialects. So, +1 on this answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.