// use Write trait that contains write() function
use std::io::Write;
fn main() {
std::io::stdout().write(b"Hello, world!\n").unwrap();
}
The std::io::Write trait is designed for objects which accept byte streams. In this case, a handle to standard output is acquired with ...
All instances of Preferences are always thread-safe across the threads of a single Java Virtual Machine (JVM). Because Preferences can be shared across multiple JVMs, there are special methods that deal with synchronizing changes across virtual machines.
If you have an application which is supposed...
/* define a list of preprocessor tokens on which to call X */
#define X_123 X(1) X(2) X(3)
/* define X to use */
#define X(val) printf("X(%d) made this print\n", val);
X_123
#undef X
/* good practice to undef X to facilitate reuse later on */
This example will result in the prep...
You can open the VB editor in any of the Microsoft Office applications by pressing Alt+F11 or going to the Developer tab and clicking on the "Visual Basic" button. If you don't see the Developer tab in the Ribbon, check if this is enabled.
By default the Developer tab is disabled. To enab...
A cross join is a Cartesian join, meaning a Cartesian product of both the tables. This join does not need any condition to join two tables. Each row in the left table will join to each row of the right table. Syntax for a cross join:
SELECT * FROM table_1
CROSS JOIN table_2
Example:
/* Sample...
From your project directory, run the go build command and specify the operating system and architecture target with the GOOS and GOARCH environment variables:
Compiling for Mac (64-bit):
GOOS=darwin GOARCH=amd64 go build
Compiling for Windows x86 processor:
GOOS=windows GOARCH=386 go build
...
In a nutshell, conditional pre-processing logic is about making code-logic available or unavailable for compilation using macro definitions.
Three prominent use-cases are:
different app profiles (e.g. debug, release, testing, optimised) that can be candidates of the same app (e.g. with extra log...
Macros are categorized into two main groups: object-like macros and function-like macros. Macros are treated as a token substitution early in the compilation process. This means that large (or repeating) sections of code can be abstracted into a preprocessor macro.
// This is an object-like macro
...
Using environment variables is a widely used way to setting an app's config depending on it environment, as stated in The Twelve-Factor App.
As configurations are likely to change between deployment environments, this is a very interesting way to modify the configuration without having to dig in th...
An Anaphoric Macro is a macro that introduces a variable (often IT) that captures the result of a user-supplied form. A common example is the Anaphoric If, which is like a regular IF, but also defines the variable IT to refer to the result of the test-form.
(defmacro aif (test-form then-form &o...
Macros return code. Since code in Lisp consists of lists, one can use the regular list manipulation functions to generate it.
;; A pointless macro
(defmacro echo (form)
(list 'progn
(list 'format t "Form: ~a~%" (list 'quote form))
form))
This is often very hard to...
The expansion of a macro often needs to use symbols that weren't passed as arguments by the user (as names for local variables, for example). One must make sure that such symbols cannot conflict with a symbol that the user is using in the surrounding code.
This is usually achieved by using GENSYM, ...
Channels can be used to send data from one thread to another. Below is an example of a simple producer-consumer system, where the main thread produces the values 0, 1, ..., 9, and the spawned thread prints them:
use std::thread;
use std::sync::mpsc::channel;
fn main() {
// Create a channel...
To find every vector of the form (x, y) where x is drawn from vector X and y from Y, we use expand.grid:
X = c(1, 1, 2)
Y = c(4, 5)
expand.grid(X, Y)
# Var1 Var2
# 1 1 4
# 2 1 4
# 3 2 4
# 4 1 5
# 5 1 5
# 6 2 5
The result is a data.frame with one...
Add this to your vimrc:
nnoremap Q @q
To start recording the "throwaway" macro, use qq. To finish recording hit q (in normal mode for both).
To execute the recorded macro, use Q.
This is useful for macros that you need to repeat many times in a row but won't be likely to use again af...
Predefined macros are those that the compiler defines (in contrast to those user defines in the source file). Those macros must not be re-defined or undefined by user.
The following macros are predefined by the C++ standard:
__LINE__ contains the line number of the line this macro is used on, an...
An idiomatic technique for generating repeating code structures at compile time.
An X-macro consists of two parts: the list, and the execution of the list.
Example:
#define LIST \
X(dog) \
X(cat) \
X(racoon)
// class Animal {
// public:
// void say();
// };
#define...