Marco Munari
2022-01-10 00:52:07 UTC
I thought it could be nice to introduce condition inside macro definition, to produce less jumping code (so compiler can output bigger but more efficient code with concise definition)
a syntax could be defined by adding an optional #defif (due to the late time this could be introduced to C, that would be my preference reminding to who would learn by seeing it that the if is part of the macro definition) as
#define macro(#N,x) #defif (#N>0) macro(#N-1,…) #defelse …
usable with macro(5,x)
expansion parameter that i called #N need to be a constant provided to the expansion engine, the # prefix I indicated here is not a syntax necessity because it can be deduced by the fact that this parameters appears in the #defif condition which also must be fully valuable during preprocessing (just a bit more powerful preprocessing)
or if you prefer instead of #defif a shorter #IF or even #if but inside the line (expandable with \ ending lines) of a #define pragma, and the correspondent #defelse or #ELSE or #else
the result of the definition has to be a single entity as it is currently, but can be tweaked over the parameters of the macro definition during each expansion
e.g. for something like binary search in batch of direct elaboration without use of stack each batch of depth 5
#define f(N,bt,a) #defif(N>0) (a == bt->val) ? bt : (a < bt->val) ? f(N-1,bt->left,a) : f(N-1,bt->right,a) #defelse g(bt,a)
struct {int val; binarytree *left,*right} binarytree;
int g(binarytree bt, int a) {
return f(5,bt,a); /* recursive batch dept 5 is stored only here */
}
would correspond to a very uncomfortable to write and maintain but efficient form
what do you think of the idea?
All the best,
MARco MunARi
—
x(t),y(t) = th(3t-34.5)*e^[-(3t-34.5)^2]/2-4.3+e^(-1.8/t^2)/(.8*atg(t-
3)+2)(t-1.8)-.3th(5t-42.5),(1.4e^[-(3t-34.5)^2]+1-sgn[|t-8.5|-.5]*1.5*
|sin(pi*t)|^[2e^(-(t-11.5)^2)+.5+e^(-(.6t-3.3)^2)])/(.5+t)+1 ; 0<t<14
a syntax could be defined by adding an optional #defif (due to the late time this could be introduced to C, that would be my preference reminding to who would learn by seeing it that the if is part of the macro definition) as
#define macro(#N,x) #defif (#N>0) macro(#N-1,…) #defelse …
usable with macro(5,x)
expansion parameter that i called #N need to be a constant provided to the expansion engine, the # prefix I indicated here is not a syntax necessity because it can be deduced by the fact that this parameters appears in the #defif condition which also must be fully valuable during preprocessing (just a bit more powerful preprocessing)
or if you prefer instead of #defif a shorter #IF or even #if but inside the line (expandable with \ ending lines) of a #define pragma, and the correspondent #defelse or #ELSE or #else
the result of the definition has to be a single entity as it is currently, but can be tweaked over the parameters of the macro definition during each expansion
e.g. for something like binary search in batch of direct elaboration without use of stack each batch of depth 5
#define f(N,bt,a) #defif(N>0) (a == bt->val) ? bt : (a < bt->val) ? f(N-1,bt->left,a) : f(N-1,bt->right,a) #defelse g(bt,a)
struct {int val; binarytree *left,*right} binarytree;
int g(binarytree bt, int a) {
return f(5,bt,a); /* recursive batch dept 5 is stored only here */
}
would correspond to a very uncomfortable to write and maintain but efficient form
what do you think of the idea?
All the best,
MARco MunARi
—
x(t),y(t) = th(3t-34.5)*e^[-(3t-34.5)^2]/2-4.3+e^(-1.8/t^2)/(.8*atg(t-
3)+2)(t-1.8)-.3th(5t-42.5),(1.4e^[-(3t-34.5)^2]+1-sgn[|t-8.5|-.5]*1.5*
|sin(pi*t)|^[2e^(-(t-11.5)^2)+.5+e^(-(.6t-3.3)^2)])/(.5+t)+1 ; 0<t<14