macros

In clojure, how can I evaluate the arguments to a macro from another macro?

偶尔善良 提交于 2020-01-23 05:28:33
问题 I have two macros. The first one takes a symbol as the only parameter (because it's passed to def, which needs a symbol). The second function takes a list of symbols and should call the first with each symbol individually. (defmacro m1 [s] '(let [f# ... dynamic function definition ...] (def ~s f#)) The second macro should take a list of symbols and pass them to the first, but I can't get it to work. The best I could come up with was the following: (defmacro m2 [symbols] `(for [s# ~symbols]

How to expand macro and delete comma

倖福魔咒の 提交于 2020-01-23 02:04:20
问题 For example I want to write my own printf() alternative, but I have to perform calculations on the variable arguments: #define log(fmt_string, ...) my_log(fmt_string, pack_args(__VA_ARGS__), __VA_ARGS__) where pack_args(...) - is a macro too. How should I change this code to handle the only fmt_string presence scenario? log("Some message here"); 回答1: In P99 I have two macros #define P00_ARG( \ _1, _2, _3, _4, _5, _6, _7, _8, \ _9, _10, _11, _12, _13, _14, _15, _16, \ ... etc ... \ _153, _154,

How to expand macro and delete comma

99封情书 提交于 2020-01-23 02:04:05
问题 For example I want to write my own printf() alternative, but I have to perform calculations on the variable arguments: #define log(fmt_string, ...) my_log(fmt_string, pack_args(__VA_ARGS__), __VA_ARGS__) where pack_args(...) - is a macro too. How should I change this code to handle the only fmt_string presence scenario? log("Some message here"); 回答1: In P99 I have two macros #define P00_ARG( \ _1, _2, _3, _4, _5, _6, _7, _8, \ _9, _10, _11, _12, _13, _14, _15, _16, \ ... etc ... \ _153, _154,

Is it bad practice to have a macro definition return a value for a function?

冷暖自知 提交于 2020-01-22 20:54:05
问题 Using a macro defined to conditionally return a value has a disadvantage where it is not apparent from only looking at the client code might exit at the point of the macro. The use case I am considering is writing a value and error checking, like so: #define WRITE_CHK(file, param)\ if (!write_that_returns_zero_on_fail(file, param)) {\ handle_error();\ return false;\ } client code: bool myfunc() { ... WRITE_CHK(file, param) // function might return here ... return true; } I am curious if the

Evaluate all macros in a C++ header file

孤者浪人 提交于 2020-01-22 00:14:38
问题 I have a requirement to build an automated system to parse a C++ .h file with a lot of #define statements in it and do something with the value that each #define works out to. The .h file has a lot of other junk in it besides the #define statements. The objective is to create a key-value list, where the keys are all the keywords defined by the #define statements and the values are the evaluations of the macros which correspond to the definitions. The #defines define the keywords with a series

Evaluate all macros in a C++ header file

狂风中的少年 提交于 2020-01-22 00:14:30
问题 I have a requirement to build an automated system to parse a C++ .h file with a lot of #define statements in it and do something with the value that each #define works out to. The .h file has a lot of other junk in it besides the #define statements. The objective is to create a key-value list, where the keys are all the keywords defined by the #define statements and the values are the evaluations of the macros which correspond to the definitions. The #defines define the keywords with a series

Macros and how to trace them

泪湿孤枕 提交于 2020-01-21 23:51:24
问题 The trace macro is very useful for debugging. But it comes to a halt, when used upon any macro. Like if I try to do the following : CL-USER> (trace push) Then, it'll give an error saying: can't use encapsulation to trace anonymous function #<FUNCTION (MACRO-FUNCTION PUSH) {100053FB9B}> [Condition of type SIMPLE-ERROR] Well, that's obvious because the clhs page of trace, clearly defines it upon functions. So, what is the reason for not having any facility for tracing macros in Common Lisp? Is

Macros and how to trace them

﹥>﹥吖頭↗ 提交于 2020-01-21 23:51:06
问题 The trace macro is very useful for debugging. But it comes to a halt, when used upon any macro. Like if I try to do the following : CL-USER> (trace push) Then, it'll give an error saying: can't use encapsulation to trace anonymous function #<FUNCTION (MACRO-FUNCTION PUSH) {100053FB9B}> [Condition of type SIMPLE-ERROR] Well, that's obvious because the clhs page of trace, clearly defines it upon functions. So, what is the reason for not having any facility for tracing macros in Common Lisp? Is

Error: expected expression on line using #defined constant

99封情书 提交于 2020-01-21 12:48:15
问题 I'm doing this if ([resourceCompletionReward objectAtIndex:experienceD] != 0) { But Xcode is giving me an error: Expected expression I've defined experienceD as #define experienceD 0; What am I doing wrong? 回答1: The semicolon shouldn't be there. #define experienceD 0 will compile just fine. Also it's a good practice to name constants with an UPPER_CASE_NOTATION like this. For completeness I will add that Apple suggests (from the Coding Guidelines for Cocoa) In general, don’t use the #define

What types of Macros/Syntax Extensions/Compiler Plugins are there?

巧了我就是萌 提交于 2020-01-21 06:32:49
问题 I am very confused by the many terms used for several macro-like things in the Rust ecosystem. Could someone clarify what macros/syntax extensions/compiler plugins there are as well as explain the relationship between those terms? 回答1: You are right: it is confusing. Especially, because most of those features are unstable and change fairly often. But I'll try to summarize the current situation ( December 2016 ). Let's start with the Syntax Extension : it's something that has to be "called" or