Questions tagged [macros]

1

votes
1

answer
2k

Views

SBT/Scala: macro implementation not found

I tried my hand on macros, and I keep running into the error macro implementation not found: W [error] (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them) I believe I've set up a two pass compilation with the macro implementati...
Wonko
0

votes
1

answer
31

Views

Using a macro with a defined body in C++

I am learning C++ and have come across this code snippet and cannot understand the syntax: . . #define DO_MUTEX(m, counter) char counter; \ for (counter = 1, lock(m); counter == 1; --counter, unlock(m)) #define mutex(m) DO_MUTEX(m, UNIQUE_COUNTER(m)) int main(){ mutex(my_mutex) { foo(); } . . . }...
Joe
1

votes
4

answer
1.6k

Views

How to use templates instead of macros to create a class with a dynamic number of functions

Currently i am creating a base class with set and get functions with a macro. But I would like to add more complex macros but macros are really bad for debugging so I would like to do it with templates but I have no idea does someone know a book or link for me. My real problem is far more complex I...
Max
1

votes
0

answer
7

Views

How to disable “unnecessary path disambiguator” warning?

I am generating code with a macro, which contains fully qualified type paths like this: let vec: Vec::; Note the extra :: before . This is necessary so that the same input token can be also be used for the constructor, by appending ::new(): Vec::::new() However, this produces warnings: warning: unne...
1

votes
2

answer
33

Views

How to use cycles in sas macro data step

I need to use cycles in a sas macro that writes a data step I have a code that should work but it doesn't. How can i fix it? %macro ci; data %do i=1 %to 3; _z%sysfunc(putn(%eval(&i),z2.)) ; %end; ; set _06; %do i=1 %to 3; if num="%sysfunc(putn(%eval(&i),z2.))" then output _z%sysfunc(putn(%eval(&i)...
Raffaele
0

votes
0

answer
4

Views

Loop strmatch, then dataset intersection, then extract data subset by observation

Step 1: Find intersection between two datasets. I would like to find the intersection between biglist and matchlist. use matchlist, clear //matchlist contains unique observations that I need levelsof countryname, local(country1) use biglist, clear //big list has a lot of duplicates and things I don'...
Susie
0

votes
0

answer
5

Views

PasteSpecial method of Range class failed in for loop

Writing macros to copy cells in a different workbook in a specific format.Getting error at different lines everytime I run the code I tried with unhide cells, selection `For i = 1 To lastrow If IsEmpty(ThisWorkbook.Sheets("Summary").Range("A" & i).Value) = False Then If ThisWorkbook.Sheets("Summary"...
DeepaB
1

votes
2

answer
1.7k

Views

R Version of SAS macro variable?

I am pretty familiar with SAS. I am a beginner in R and am trying to figure out what the R equivalent of macro variables is. Specifically I have 6 datasets with a common variable name, Price. I want to create a loop that changes Price in each data set to DatasetNamePrice. This would be simple in SAS...
BNT
1

votes
1

answer
1.3k

Views

Macro conditional statements in C

Is it possible to implement a macro conditional inside a macro function in C. Something like this: #define fun(x) #if x==0 fun1; #else fun2; #endif #define fun1 // do something here #define fun2 // do something else here In other words, preprocessor decides which macro to use based on an argument va...
Marko Gulin
1

votes
1

answer
127

Views

How do I reference a data file with a macro?

I have various Stata data files. These are located in different folders. I also have a single do file that uses these files, one at a time. Is there a way to use a macro to reference a particular dataset in my do file? For example: local datafile = "C:\filepath\mydata.dta" The idea is to use this l...
Kany
1

votes
1

answer
141

Views

Adding time in a file name

Consider the code snippet below: local date: display %td_CCYY_NN_DD date(c(current_date), "DMY") local date_string = subinstr(trim("`date'"), " " , "", .) save "`date_string'_example", replace mkdir "`date_string'_example" This creates output as follows: 20170521_example.dta However, I want to creat...
user42459
0

votes
0

answer
4

Views

How to convert text file to vbs file using vbscript?

I'm new in vbscript and I'm trying to save text file (.txt) as vbs file (.vbs) by reading or opening it. Can anyone tell me how to read a text file and save it as a file whose extension is user defined. I searched for the FileSystemObjects and found method to create a text file using CreateTextFile...
David
1

votes
1

answer
43

Views

Macro rule for matching a doc comment [duplicate]

This question already has an answer here: Generating documentation in macros 1 answer Is there a way to match doccomments in Rust's macro_rules? I have a macro that generates an enum for a bunch of C constants that bindgen creates: macro_rules! id_enum { ( enum $name:ident: $typ:ty { $( $enum_name:...
Colonel Thirty Two
1

votes
1

answer
80

Views

Cannot call a function-like procedural macro: cannot be expanded to statements

I'm trying to get my head around function-like procedural macros and struggling with the basics. For a starter, I tried to create a macro that just prints all the tokens and does nothing: extern crate proc_macro; extern crate syn; use proc_macro::TokenStream; #[proc_macro] pub fn my_macro(input: Tok...
Amomum
1

votes
1

answer
36

Views

Using implicit declaration for hiding helper functions

As specified here C makes implicit declaration of functions it does not know. So I tend to make use of it for hiding implementation details. I defined the following header file: #ifndef TEST_H #define TEST_H #define PRINT(msg) \ do{\ _print_info_msg(msg);\ printf(msg);\ } while(0) #endif //TEST_H an...
Some Name
1

votes
1

answer
11

Views

c++, a generic recursive template function to traverse tree like structures

I tried to traverse tree like structures with a generic recursive function without defining a recursive function in global each time for each structures. //structure #1 class CA { public: std::string name; std::vector vecChild; }; and I create a tree with CA auto root = new CA; root->name = "root";...
sainimu78
0

votes
1

answer
12

Views

Copy rows with specific columns based on entered date to other sheet

I have an existing VBA code that copies rows if an identifier column is marked with 'X'. Now I want it to be based off a date range entered by the user. Can somebody please help me convert the existing code to my required one? Thanks! Sub CopyRow() Application.ScreenUpdating = False Dim x As Long, M...
din2345
19

votes
2

answer
1.4k

Views

How to programmatically get the number of fields of a struct?

I have a custom struct like the following: struct MyStruct { first_field: i32, second_field: String, third_field: u16, } Is it possible to get the number of struct fields programmatically (like, for example, via a method call field_count()): let my_struct = MyStruct::new(10, "second_field", 4); let...
Akiner Alkan
1

votes
2

answer
1.6k

Views

Wrap lines at 80 characters

I want to break up lines longer than 80 characters into multiple lines at the same level of indentation as the original line. It should only make the cut at whitespace characters so that words don't get bisected. So, this: \begin{enumerate} \item Lorem ipsum dolor sit amet, consectetur adipiscing el...
Joe Mornin
1

votes
2

answer
319

Views

SAS macro for Date

I got 2 problems regarding the SAS date using macros. To make it more complicated I am stuck with 2 specific macros that i need to use(its part of the puzzle that I try to solve). The macro that I need to use are: %let id=741852 %let month=January February March April May June July August September...
1

votes
1

answer
143

Views

Placemarker and non-placemarker tokens in pre-processor?

C99 standard and having trouble to understand this : c99 - 6.10.3.3 Semantics 3 --- (2nd sentence) Placemarker preprocessing tokens are handled specially: concatenation of two placemarkers results in a single placemarker preprocessing token, and concatenation of a placemarker with a non-placema...
Omkant
1

votes
2

answer
2.5k

Views

Macros over multilines using #pragma and #ifdef

I'm a bit new to macros so go easy, but we have an external library that generates loads of warnings when compiled under windows (its not so bad on linux). Its a header only library so I can't just turn the warnings off for the whole library, but I can disable each section that is generating the wa...
Drew
1

votes
1

answer
49

Views

Macro Signature Not Honored by Velocity Engine

How can I enable Velocity engine to honor #macro signatures so that if I try calling a macro in templates Example: #myTestMacro($arg1 $arg2) that has a different signature when defined Example: #macro(myTestMacro $arg) Velocity will be smart enough to throw an error, so I can catch invalid numbe...
partizan
1

votes
2

answer
208

Views

Is it possible/smart to write a lazy loading macro implementor?

My code (especially as I get more into TDD) has lots of lazily-loaded properties, like: @interface MyClass () @property (nonatomic, strong) MyFoo *myFoo; @end @implementation MyClass - (MyFoo *)myFoo { if (!_myFoo) { _myFoo = [MyFoo alloc] sharedFoo]; // or initWithBar:CONST_DEF_BAR or whatever } re...
buildsucceeded
1

votes
4

answer
3.6k

Views

Array of strings in a Macro

I would like to take an array of strings in a macro. Firstly: is that possible? IF yes, can I call them one by one based on the index, when I am using them? Something like this: #define VAR "abc", "def", "xyz" Then when i want to use "def" somewhere, FUNC(VAR[1]);
Sunny
1

votes
1

answer
220

Views

get calling function with more hierarchical depth

The following code gets the calling function (like C _ _ FUNC _ _): def __func__(c: Context) = { import c.universe._ c.enclosingMethod match { case DefDef(mods, name, tparams, vparamss, tpt, rhs) => c.universe.reify(println( "\n mods "+c.literal(mods.toString).splice +"\n name "+c.literal(name.toS...
Eric Mariacher
1

votes
2

answer
193

Views

Can anybody please explain the behavour of C preprocessor in following examples?

I am implementing a C macro preprocessor (C99)... I am surprised by the following behaviour.... Ex1: #define PASTE(x) X_##x #define EXPAND(x) PASTE(x) #define TABSIZE 1024 #define BUFSIZE TABSIZE PASTE(BUFSIZE) EXPAND(BUFSIZE) expands to: X_BUFFSIZE X_1024 Ex2: #define EXPAND(s) TO_STRING(s) #define...
Sam
1

votes
4

answer
282

Views

which one is better Macro or String Constants?

I have confused which way I have to use for "seenArray" #define kseenArray @"seenArray" and NSString * const kseenArray = @"seenArray";Why?.In respect to memory ,if any, I want to know about it which one is better.
Sandy
1

votes
1

answer
1k

Views

LCM calculation bug in GCD/LCM x86 Intel NASM assembly program

I created a similar program in C++ first, and then I decided to try to write it in x86 assembly language (the type of assembly I was taught in college). I've already completed the C++ version, and my assembly version is almost complete. I did some desk-checking on both versions, first using (2400,...
Jamal
1

votes
3

answer
1.3k

Views

Macro to iterate over struct members

I use a struct of bit fields to access each colour channel in a pixel, the problem is that quite often I have code that applies in the same way to each channel, but because I cannot just iterate over the members of a struct in C I end up having 3 copies of the same code for each member, or more inco...
Michel Rouzic
1

votes
1

answer
2.5k

Views

How to call them with map parameters?

I have been strolling around with this but couldn't find any documentation or example code. Introduction: I have an ftl page that has this key/value map: roomType.description["ES"] = "texto" roomType.description["EN"] = "some text" roomType.description["PT"] = "texto" Question: How to pass the map a...
1

votes
2

answer
3.2k

Views

Logic of #define (microchip xc8 compiler)

I just started learning C for pic programming and I was looking at other people's code and at the includes files provided with the compiler, especially the fundamental ones (xc.h, pic.h, pic specific headers...) and I saw this construct (it's found in pic.h) #define __delay_us(x) _delay((unsigned lo...
zakkos
1

votes
2

answer
65

Views

How do you transform a vector of maps into a series of symbols that eval to a particular map?

I am a Clojure newbie using Light Table to learn macros. My goal is to convert a vector of maps into a list of def statements. I want to transform the following data structure: (def label-data [ {:label "lbl_first"} {:label "lbl_second"} {:label "lbl_third"} {:label "lbl_fourth"} ] ) ...into the fol...
tagivens
1

votes
2

answer
167

Views

Create a set of macros to define a type called RETURN_STATUS and the following values:

I'm attempting to complete an O'reilly textbook on my own. I'm at a point where I really dont understand what's going on anymore. I read the chapters but simply dont know what to do when I get to the programming exercises. I know this problem looks like it should be easy but I have no idea. The que...
Maurice Abney
1

votes
2

answer
6.1k

Views

How to create Mac OS X app installer

I have a project in XCode (version 4.6.2) which include application and command line utility. How can I create a installer for that project to test if everything works (e.g. command line utility is installed in the /usr/local/bin directory and application in the /Applications directory)? When I make...
1

votes
2

answer
615

Views

cl-who: using a variable in with-html-output-to-string

All the examples I've seen so far for cl-who work like this: (with-html-output-to-string (s) (:HTML (:HEAD (:TITLE "hello")) (:BODY (:DIV "world")))) Which works fine. However, I wanted to use with-html-output-to-string with a variable, instead of a hardcoded html tree; if *p* has (:HTML (:HEAD (:TI...
fableal
1

votes
1

answer
58

Views

Expanding a configuration stub into builder and value using macros

More a hypothetical question. Is it possible, using Scala macros, to turn a structure like this: object Foo extends Factory { // Factory = expansion magic trait Config { val i: Int = 33 val s: String = "foo" } def apply(c: Config): Foo = ??? } trait Foo (more or less automatically) into this: objec...
0__
1

votes
1

answer
60

Views

Call AnkhSVN commands in C#

Is there a way that I can call the same commands that Ankh SVN uses, within C# code? For example, can I call the same functionality that adds a solution to a subversion from code? I am writing Visual Studio addin that will allow me to reuse a solution template, rather than having to recreate the sa...
DevDave
1

votes
1

answer
1k

Views

How to pass a macro's result to another macro?

I have two macros in my C code the helps me to compose the name of certain variables. As an example, consider the following: #define MACROA(name) A_##name #define MACROB(name) B_##name void *MACROB(MACROA(object)); So, I'm trying to declare a variable called B_A_object. However, this doesn't work an...
LuisABOL
1

votes
1

answer
1.5k

Views

makefile double dollar sign in user defined function

In chapter 8 (P150) of Managing Projects with GNU Make, the author introduces Tromey’s Way. define make-depend $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -M $1 | \ $(SED) 's,\($$(notdir $2)\) *:,$$(dir $2) $3: ,' > $3.tmp $(MV) $3.tmp $3 endef %.o: %.c $(call make-depend,$
Albert Netymk

View additional questions