libpulsar
A modular compiler for the pulsar programming language
Loading...
Searching...
No Matches
Macros
capture.h File Reference

Syntactic sugar for capture blocks. More...

#include "def.h"

Go to the source code of this file.

Macros

#define __name   ) auto_t __name = ___932c5c2575d24f64ece6
 
#define in   ;
 
#define run(capture, value)
 

Detailed Description

Syntactic sugar for capture blocks.

Author
Ethan Uppal

It is important to note that there is no capturing going on here. It is simply syntactic sugar.

This file uses the hexadecimal number "932c5c2575d24f64ece6", which generated via random.org, to define an identifier that is unlikely to have name collisions with another.

Example:
Let's define a string manipulation macro as follows.
#include <stddef.h> // for size_t
#include "capture.h" // for $run
// Modifies the given string `str` with the routine `capture`.
#define update_string(str, capture) \
for (size_t i = 0; str[i]; i++) { \
$run(capture, str[i]); \
}
Syntactic sugar for capture blocks.
We can call it using the capture block syntactic sugar.
char* string = "hello";
update_string(string, $(c) in {
c = toupper(c);
});
printf("%s\n", string);
#define in

Definition in file capture.h.

Macro Definition Documentation

◆ __name

#define __name   ) auto_t __name = ___932c5c2575d24f64ece6

◆ in

#define in   ;

◆ run

#define run (   capture,
  value 
)
Value:
do { \
auto_t ___932c5c2575d24f64ece6 = (value); \
{ capture } \
} while (0)
#define auto_t
Definition def.h:53