How to allow optional trailing commas in macros?

Make the comma optional As DK. points out, the trailing comma can be made optional. Rust 1.32 You can use the ? macro repeater to write this and disallow multiple trailing commas: ($Name:ident { $($Variant:ident),* $(,)? }) => { // ^^^^^ Previous versions This allows multiple trailing commas: ($Name:ident { $($Variant:ident),* $(,)* }) => { … Read more

What makes Lisp macros so special?

To give the short answer, macros are used for defining language syntax extensions to Common Lisp or Domain Specific Languages (DSLs). These languages are embedded right into the existing Lisp code. Now, the DSLs can have syntax similar to Lisp (like Peter Norvig’s Prolog Interpreter for Common Lisp) or completely different (e.g. Infix Notation Math … Read more

Macros in Swift?

In this case you should add a default value for the “macro” parameters. Swift 2.2 and higher func log(message: String, function: String = #function, file: String = #file, line: Int = #line) { print(“Message \”\(message)\” (File: \(file), Function: \(function), Line: \(line))”) } log(“Some message”) Swift 2.1 and lower func log(message: String, function: String = __FUNCTION__, … Read more