Questions tagged [macros]

A macro in computer science is a rule or pattern that specifies how a certain input sequence (often a sequence of characters) should be mapped to a replacement output sequence (also often a sequence of characters) according to a defined procedure. Do not use this tag for questions regarding Microsoft's Visual Basic for Applications. VBA evolved from an early macro language, but is not a macro language itself.

Filter by
Sorted by
Tagged with
4
votes
1answer
4k views

Qt foreach-like alternative to iterate over value AND key of an associative container

The Qt documentation recommend an iterator-based solution to iterate over an associative container like QMap and QHash, and I always wondered if there really isn't a (nice) solution using a ...
4
votes
1answer
188 views

Is this a good way to implement let-with?

I've implemented a let-with macro that takes an association list, keyed by symbols, that enables code to bind their corresponding values to local variables. It's ...
3
votes
1answer
45 views

Function declarations using macros to support multiple platforms

I wrote a C++ plugin that retrieves screen pixel. It works on Windows and Android. I noticed that dllexport is only required on Windows but not on Android and ...
3
votes
2answers
1k views

C try/catch macros

I've created simple try/catch macros that now I'd like to promote to wider use in my projects. I would have really liked to be able to do without global variables but I have not found any way to do ...
3
votes
1answer
216 views

Simplifying Macro-Generating Racket Macro

I'm trying to write a small macro library in Racket that extends a few of the racket/match functions I use, by printing which clause was expanded. While this seems ...
3
votes
1answer
56 views

Clang preprocessor concatenates an extra space vs. gcc - standard C99

I maintain a C library project both on gcc and clang. I am looking for advice on how to make the following macros more portable, terse, readable or standard abiding. When I compile ...
3
votes
2answers
141 views

Replace a #define/template “Variable Wrapper” system with a pure template/OOP solution

I have an inherited code base that I am looking to improve. Below is a "variable wrapper" template class and #defines that i would like to replace with a template only solution, or redesign ...
3
votes
1answer
3k views

Speed up Excel Macro b/n copy and paste external files

I posted on the Stack Overflow. They recommended me to post on here So the whole scope of this Excel file is to copy and paste from other 27 external files to the current Excel file one by one. to ...
3
votes
1answer
183 views

Once-only macro

I have been learning common lisp and am a newbie, using the great book Practical Common Lisp. There is a once-only macro in the book that I spent a lot of time figuring out how it works. Even after I ...
3
votes
1answer
99 views

in-nest-sequence: sequence generator in Racket

in-nest-sequence is a sequence generator that takes a function and an initial value, and the return value of invoking the function on the current value is used as ...
3
votes
1answer
48 views

Autotools pull in standard build system

I have been updating my build tools to optionally us autotools (autoconfig/automake/libtool etc.). As part of this change I have written a couple of M4 macros. This not being something I have done ...
3
votes
1answer
541 views

Error-handling #ifdefs for AFNetworking requests

I am using AFNetworking 1.4.3 to send and receive network messages in iOS. My application works slightly differently in DEBUG and RELEASE mode, so I need to use ...
3
votes
2answers
611 views

scope_exit macro

This is actually not something new, but I think many people wanted something useful and not incredibly complicated. So, here it is: ...
3
votes
1answer
67 views

Saving the values of all variabled declared in a block

Often when running exprimental code to empirically investigate an algorithm, you tweak a parameter, then rerun the code, and generate a bunch of saved models for various parameters. To make sure I ...
3
votes
0answers
36 views

Yet another reflection library

Tried to do my own implementation of reflection(introspection) for using in my next projects. Is it optimized at compile time? If no, how can I improve it? This macro is good interface for adapting ...
3
votes
0answers
67 views

Rust List comprehension macro

I'm very new to Rust and as I've been going through the book I became very interested in its macros. To better understand them I tried to write something of a usable list comprehension like those in ...
3
votes
0answers
82 views

Racket macro for variadic FFI

I'm working on FFI wrapper for SDL2 library in Racket. The library includes several variadic functions (e.g. SDL_SetError, SDL_LogMessage etc); Racket FFI does not have straight way for importing ...
3
votes
0answers
98 views

Allowing switching between operator[] and at() based on NDEBUG macro version

The problem: std::vector and other containers have two functions for accessing / modifying their content: operator[] and ...
2
votes
2answers
151 views

Index Match implementation

The code below takes header variables, retrieves the column index, and then, using an Index/Match function, returns data from a matching account number. The reason it is written this way is because I ...
2
votes
2answers
137 views

C++ Minimalistic Unit Testing Library

I was looking for a unit testing library for C++, and I found many. Unfortunately, I decided I didn't want to use any of them. I decided to make my own. This is the result. I made heavy use of the ...
2
votes
1answer
403 views

Simplify complex hash-table manipulations in Common Lisp

I'm trying to write a simple triplestore in Common Lisp that will store triples in the form subject-predicate-object. The code is inspired by the book "Programming the Semantic Web". ...
2
votes
2answers
227 views

with-alist-bind

Take 4 (alteration based on feedback from Rainer Joswig): ...
2
votes
1answer
59 views

C++17 enum macro with to_string operator

I created a simple enum macro that creates a to_string method for the enum. This has been done before, but my version is designed to compile quickly. From what I ...
2
votes
2answers
89 views

A stack optimized for filter queries, written in the C++ preprocessor

Given a stack with N elements and a query Q, we need to find all elements of stack for which ...
2
votes
1answer
512 views

Generic Macro Generated Linked List in C

Generate a linked list of any type using macros. The linked list contains functions for adding and removing elements to both ends and also at the middle. You can also add elements relatively to a list ...
2
votes
1answer
610 views

Mutable stack in Racket

I'm learning Racket and have implemented a mutable stack, which is just a bunch of wrappers around an underlying struct containing a size and buffer list (so it's ...
2
votes
1answer
104 views

Optimize Nested For loops

I have built a covid model using uva data. Currently that data is unavailable so I'm using another source. The new source is, of course, a differnt format. So rather than refactor all of my model ...
2
votes
1answer
273 views

Objective C implementation of Swift's if-let

This [Objective-]C-preprocessor macro currently handles single-variable if-let-not-nil and if-let-is-type, but doesn't handle multiple simultaneous tests and doesn't handle ...
2
votes
1answer
58 views

Custom threading macro

To help myself learn macros, I made a custom version of the threading macro that lets you choose which argument the "thread" gets put into. My main concern is simplifying it, and making it more ...
2
votes
2answers
2k views

Objective-C debug macros

I'm looking for a review of my macros. I have these in the project pre-compile header. I tent to copy them into all my new projects as well, unless its a very simple project. ...
2
votes
0answers
90 views

Simple generic macro-generated containers

In order to learn macros in C I decided to make a generic data structures generator for other projects that I have in C. The main macros are the following: ...
2
votes
0answers
304 views

Interpreter for an assembly language with variadic instructions

I am currently implementing a virtual machine that runs a programming language similar to assembly. The difference is that an instruction in this language can have any number of operands. and the ...
2
votes
0answers
97 views

`multiple-value-call` in Scheme

Common Lisp has a "special operator" called multiple-value-call, which does something similar to Scheme's call-with-values but ...
1
vote
4answers
2k views

Macro for rounding with variable precision

I use the following MY_ROUND macro for rounding: ...
1
vote
1answer
139 views

Macro to generate an enum and an array of strings

Often when I find myself working with magic number enum values and I want to know what they represent, so I create an array of strings in order to print out their label. This macro automates that ...
1
vote
1answer
47 views

Macro that generates a defn

I need to save nested data to disk for a project. Right now, my state is a nested record, and has proven to be a pain to serialize. I tried compressing it to a map, but after testing it, I realized my ...
1
vote
1answer
256 views

Writing filter with one or more comparison values

...
1
vote
0answers
101 views

Optimizing VBA code , Takes more than 50 minutes to update

Could you please help me optimize the macro, Its taking more than 50 minutes but still no success. The For loop is looping untill 1.0 million + rows. Screen is flickering. I have tried Application....
1
vote
0answers
70 views

Clojure macro to gather functions in a namespace into a map

I'm learning Clojure via a pet project. The project would consist of several workers that would be called from other functions. Each worker is defined in their own namespace as a set of functions (...
1
vote
0answers
52 views

Implementation of catch test framework in Racket

As an exercise in learning how to use Racket macros I decided to implement a subset of the features in the catch test framework for C++. In particular the catch test framework has a unique feature ...
1
vote
0answers
63 views

Creating class method using macro to accept Visitator for each of their fields

I had a lot of classes that used a macro with listed fields. The macro was used to serialization, more like MSGPACK_DEFINE. I need a substitution of this mechanism, ...
0
votes
1answer
58 views

All of Clojure's Expression Threading Macros

I was bored and in a mood to write some macros, so I decided as an exercise to try and remake each of the standard threading macros: ->, ...
-1
votes
1answer
234 views

Increase the execution speed of VBA macro code

I am providing you with the code of my macro and hope that somebody can tell me what is making my macro slow and provide me with a solution as to how to make it run faster. Currently the execution of ...
-2
votes
2answers
588 views

Using C preprocessor macro instead of private static const [closed]

Recently I have been using more macros in my C++ code. I wrote a class with a private static const float because it is useful to prevent making mistakes. Then I ...
-4
votes
1answer
60 views

Defining constants in the original standard of C [closed]

I'm learning C using Mike McGraths 3rd edition. I know the book is old but I want to have a better appreciation for the changes made to C through its timeline. The compiler error is error: ‘SYSTEM’ ...

1
2