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
1 answer

Could somebody explain the template resolution order rules to me?

Ok, complete pseudo code here. template void fun(/*...*/) { some_meta_typelist pushback T; } So the idea is that at any point this function is instantiated it grows the some_meta_typelist object. If this is done across boundaries,…
Tavison
  • 1,523
  • 1
  • 11
  • 19
3
votes
1 answer

modify function so that control flow constructs use `{...}` AND keep comments at right place

I would like to modify an input function, so that the expressions always call `{`(), and doing so, keep the comments at the right place. Here is an example : input_fun <- function(){ if(TRUE) foo else # bar bar if(FALSE) { …
moodymudskipper
  • 46,417
  • 11
  • 121
  • 167
3
votes
1 answer

Generating a method for each subtype within a module

(Reposted from Julia slack for posterity) let’s say I have some constants like const FooConst = 1 const BarConst = 2 and I also have some struct struct Foo end struct Bar end and I now want to define a method for each struct to look up that…
3
votes
1 answer

Julia Plotly doesn't show plot with subplots

I did some workaround before to achieve wonderful subplots in Julia Plotly, but currently struggling with a more complex problem. There are three ways below that should do the job. draw1 does it perfectly, but not applicable in my situation, draw2…
3
votes
1 answer

Where do the three arguments come from in this __exit__ function extending a python base type?

I tried to play around with the built in string type, wondering if I could use strings with the with syntax. Obviously the following will fail: with "hello" as hello: print(f"{hello} world!") Traceback (most recent call last): File "",…
alexexchanges
  • 3,252
  • 4
  • 17
  • 38
3
votes
2 answers

Compile time specialize against function pointer references for avoiding -Waddress

I'm encountering the following issue with GCC (tested with v6.4 it's the same behavior on the current trunk) which can be reduced to the following minimalistic example: Further we look at callable objects such as classes that implement operator()…
Naios
  • 1,513
  • 1
  • 12
  • 26
3
votes
1 answer

Expose template-template parameter of type

I have a type that depends on a template template parameter: template class Y_> struct A { /*...*/ }; which I construct with a factory function: template class…
Tom
  • 3,281
  • 26
  • 33
3
votes
2 answers

Dynamically create an escaped constant (Ruby on Rails)

I need to dynamically create a constant that is escaped out of the current namespace, so I need the '::' in front of my constant. However, when I try the below, I get the below error... def make_constant(type) …
user2012677
  • 5,465
  • 6
  • 51
  • 113
3
votes
1 answer

How can I list all symbols used in a call?

I would like to list all symbols or names used in a call. I found the following way but surely there is a more idiomatic or efficient approach ? expr <- quote(a + b * (a / b)) expr <- as.list(expr) while(!identical(expr, (expr <-…
moodymudskipper
  • 46,417
  • 11
  • 121
  • 167
3
votes
0 answers

missing default argument on trailing parameter pack on clang

Clang complains about trailing parameter pack is not defaulted but as far as i know it is in standard and possible. Am i doing wrong or is it a bug of clang ? It is my in repo, if you want to look at full source code, it is here. Clang version is…
calynr
  • 1,264
  • 1
  • 11
  • 23
3
votes
2 answers

How to set default behaviors of magic methods in python?

Suppose I want to have a wrapper class Image for numpy array. My goal is to let it behave just like a 2D array but with some additional functionality (which is not important here). I am doing so because inheriting numpy array is way more…
Chen
  • 113
  • 5
3
votes
1 answer

Why doesn't instance_exec overwrite local variables present in a Proc object's binding?

I'm writing a DSL for a project and I've run into an issue involving local variables bleeding into nested procs when I don't want them to. It seems like no matter what I try, I can't overwrite a local variable's value with something from another…
Nick deLannoy
  • 31
  • 1
  • 4
3
votes
2 answers

I'd like a preprocessing language for metaprogramming

I'm looking for a language sort of like PHP, but more brief -- I'm tempted to call it a "templating engine" but I'm pretty sure that's the wrong term. What is the right term? A text preprocessor? Anyway I'd like it to be .NET-based because I want to…
Qwertie
  • 16,354
  • 20
  • 105
  • 148
3
votes
2 answers

meta-programming and the substitute function in R

f <- function() { x <- 6 + 4 substitute(x) } f() The above will output: [1] 10 However, the below: x <- 6 + 4 substitute(x) outputs: x Why are they different?
3
votes
2 answers

GCC and Clang disagree about constexpr-ness of lambda?

Why does Clang fail to compile the following code, with the message that the expression is not constexpr, and why does GCC not? Which compiler is correct? https://godbolt.org/z/nUhszh (Obviously, this is just an example. I do, in fact, need to be…
paladin324
  • 332
  • 1
  • 10