Questions tagged [metaprogramming]

Metaprogramming is the capability to reprogram ones programming environment, as with macros or metaclasses.

Metaprogramming - the capability to reprogram ones programming environment - can save time and code by allowing one to create new abstractions, or new and more concise syntax for repetitive tasks.

Notable metaprogramming facilities include:

  • Common lisp macros
  • Scheme hygienic macros
  • Common lisp metaobject protocol
  • Python metaclass facility
  • Smalltalk's entirely transparent and reflective execution environment

For more info see http://en.wikipedia.org/wiki/Metaprogramming.

4722 questions
3
votes
2 answers

When should I use "class Object", "class Module", "module Kernel" and nothing?

I'm new to ruby metaprogramming, and I see people metaprogramming code in different places, like class Object, class Module, module Kernel and "nothing" (ie, out of a class/module definition block). E.g.: I'm creating a c_attr_accessor method to…
Sony Santos
  • 5,435
  • 30
  • 41
3
votes
2 answers

Julia create function from string

In Julia v1.01 I would like to create a function from a string. Background: In a numerical solver, a testcase is defined via a JSON file. It would be great if the user could specify the initial condition in string form. This results in the…
Thomas
  • 1,199
  • 1
  • 14
  • 29
3
votes
3 answers

How to query for all base classes of a class at compile time?

With std::is_base_of::value one can check if a class A is a base class of class B. Is it also possible to query the compiler for all base classes of a class B, e.g., something like base_classes_of returning a std::tuple containing all base…
Lars
  • 2,616
  • 3
  • 21
  • 18
3
votes
1 answer

What's wrong with Class instances?

It would be good if someone could explain why, in Smalltalk, the expression class := Class new name: 'OurClass'; superclass: Object is not appropriate for creating a new class. More precisely, what's wrong and what's right when an object like…
Leandro Caniglia
  • 14,495
  • 4
  • 29
  • 51
3
votes
0 answers

Template specialization by member function pointer value category

I want to pass the type of a member function pointer to a class template, so that the template can use a parameter pack for working with the function parameter types. As an example, I would like to calculate the sum of the sizes of the parameter…
Erlkoenig
  • 2,664
  • 1
  • 9
  • 18
3
votes
3 answers

How can I add new attributes to a particular instance?

How can I add new attributes to a particular instance ? For example here I want to add attr_acessors methods to attributes "m1","m2" in object e1 and "m4".."m6" to e2 e1=Element.new("e1",["m1","m2"]) e2=Element.new("e2",["m4","m5","m6"]) e1.m1 =…
JCLL
  • 5,379
  • 5
  • 44
  • 64
3
votes
2 answers

Wrapping Python int/float objects

I am working on a Python concurrency framework (I know, YACF) and would like to be able to return variables as Futures, but without the user noticing it. Right now I am doing: x = someAsyncMethod(args) print "Return value is %d" % x.get_value(…
renejsum
  • 69
  • 7
3
votes
1 answer

REBOL metaprogramming questions

I'm very new to REBOL (i.e. yesterday). I am using the term "metaprogramming" here, but I'm not sure if it is accurate. At any rate, I'm trying to understand how REBOL can execute words. To give an example, here is some code in TCL: > # puts is…
ultranewb
  • 33
  • 2
3
votes
1 answer

Julia metaprogramming with using/imports

I would like to evaluate an expression that imports a Module, based on an argument expr. So far, I came up with: julia> expr = :(Base.Threads) julia> @eval using $expr ERROR: TypeError: import or using: expected Symbol, got Expr Stacktrace: [1]…
Šimon Mandlík
  • 303
  • 1
  • 6
3
votes
1 answer

How to make abstract protected fields in Python class?

I need to write dozen of class which differ each other only by variables, which are essential for stable work of class. Classes can not work without such variables and changing of variables can broke them. I have wriiten a code for creating a…
A. Bykov
  • 288
  • 1
  • 16
3
votes
3 answers

Javascript multiple "try"s

We all know the basic escaping mechanism in JS: try { ... } catch(err) { .. } I have a JSON data in which I want to check if a lead has a full name. If not, try to compose one with first and last name fields (I actually hard code a space…
Ben
  • 2,957
  • 2
  • 27
  • 55
3
votes
5 answers

Calling a method of a Ruby Singleton without the reference of 'instance'

I would like to call a method of a Singleton Object without the reference to its instance SingletonKlass.my_method instead of SingletonKlass.instance.my_method i've came up with this solution (using method_missing in the class): require…
ALoR
  • 4,904
  • 2
  • 23
  • 25
3
votes
0 answers

C++ Embedded Control Register Template

My current job has had me doing research into creating classes for arbitrary embedded device registers. Currently I am working with a number of targets with varying register sizes and I would like to standardize (or at least come up with some…
MiddleMan
  • 75
  • 3
3
votes
3 answers

Why enum instead of static bool?

Why is it considered better practice to use enum not static const bool in template metaprogramming? I've read that somewhere in Alexandrescu's book but cannot find it and really would like to know it.
There is nothing we can do
  • 23,727
  • 30
  • 106
  • 194
3
votes
1 answer

What is the use case of boost::hana forward declaration headers?

Most of the hana headers include also forward declaration headers contained in the subfolder fwd, e.g. #include
Adam Ryczkowski
  • 7,592
  • 13
  • 42
  • 68