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

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

Generating documentation in macros

It is possible to capture doc comments in macro invocations. It is not widely-known, but Rust documentation is actually represented as a special kind of attribute on an item. For example: /// Some documentation comment pub fn function() {} // is equivalent to #[doc=”Some documentation comment”] pub fn function() {} And it is possible to … Read more