threading macro -> with anonymous functions
You can have anonymous functions in Clojure macros. You are having problems, because you are missing some parentheses. 🙂 Your example is edited below. (-> 4 (#(+ % 1)) (#(- % 1)) (#(+ % 1)))
You can have anonymous functions in Clojure macros. You are having problems, because you are missing some parentheses. 🙂 Your example is edited below. (-> 4 (#(+ % 1)) (#(- % 1)) (#(+ % 1)))
In terms of readability, enumerations make better constants than macros, because related values are grouped together. In addition, enum defines a new type, so the readers of your program would have easier time figuring out what can be passed to the corresponding parameter. Compare #define UNKNOWN 0 #define SUNDAY 1 #define MONDAY 2 #define TUESDAY … Read more
I’ve done a screenshot to show where it is in Xcode, because it’s easier 🙂 Select project file Select the target you want Go to Build Settings Search for ‘preprocessor’ Add your preprocessor macro either for Debug, Release, or both.
M-0 C-x e to repeat last macro until an error happens (after the final line, either C-s = or C-n will be an error). You may hear an annoying beep.
Materialize the Value for a Type that has One Inhabitant
You can hack one together with std::any::type_name. macro_rules! function { () => {{ fn f() {} fn type_name_of<T>(_: T) -> &’static str { std::any::type_name::<T>() } let name = type_name_of(f); name.strip_suffix(“::f”).unwrap() }} } Note that this gives a full pathname, so my::path::my_func instead of just my_func. A demo is available.
If you wrote a = 7 INTMAX_MIN; you would expect to get a syntax error, because on the face of it that would be an illegal expression. And it will, because it expands to a = 7 (-9223372036854775807LL); which does indeed give you a syntax error. But without the parentheses it would expand to: a … Read more
Summary: This warning (C4127) in this particular case is a subtle compiler bug. Feel free to disable it. In depth: It was meant to catch situations when logical expression evaluates to a constant in non-obvious situations (such as, if(a==a && a!=a), and somehow, it turned while(true) and other useful constructs into invalid. Microsoft recommends using … Read more
The way I do it is like this: #define UNUSED(x) (void)(x) void foo(const int i) { UNUSED(i); } I’ve not had a problem with that in Visual Studio, Intel, gcc and clang. The other option is to just comment out the parameter: void foo(const int /*i*/) { // When we need to use `i` we … Read more
It is possible to insert a hash token into the preprocessed token stream. You can do it as follows: #define MACRO(hash, name) hash include name MACRO(#,”hello”) —expands to: # include “hello” However, the standard explicitly rules out any further analysis of such line for the existence of preprocessing directives [cpp.rescan]: The resulting completely macro-replaced preprocessing … Read more