Is it possible to declare variables procedurally using Rust macros?

Yes however this is only available as a nightly-only experimental API which may be removed. You can pass arbitrary identifier into a macro and yes, you can concatenate identifiers into a new identifier using concat_idents!() macro: #![feature(concat_idents)] macro_rules! test { ($x:ident) => ({ let z = concat_idents!(hello_, $x); z(); }) } fn hello_world() { } … Read more

Generalized Threading Macro in Clojure

There is now a generalized threading macro in Clojure since 1.5 called as->. This tweet gives an example of how it works: https://twitter.com/borkdude/status/302881431649128448 (as-> “/tmp” x (java.io.File. x) (file-seq x) (filter (memfn isDirectory) x) (count x)) First ‘x’ is bound to “/tmp” and a file is made out of it. ‘x’ is rebound again to … Read more

Mathematica: Unevaluated vs Defer vs Hold vs HoldForm vs HoldAllComplete vs etc etc

These are pretty tricky constructs, and it’s tough to give clear explanations; they aren’t as straightforward as Lisp macros (or, for that matter, the relationship between Lisp’s QUOTE and EVAL). However, there’s a good, lengthy discussion available in the form of notes from Robby Villegas’s 1999 talk “Unevaluated Expressions” on Wolfram’s website. Defer is omitted … Read more

What does the tt metavariable type mean in Rust macros?

That’s a notion introduced to ensure that whatever is in a macro invocation correctly matches (), [] and {} pairs. tt will match any single token or any pair of parenthesis/brackets/braces with their content. For example, for the following program: fn main() { println!(“Hello world!”); } The token trees would be: fn main () ∅ … Read more

Examples of what Lisp’s macros can be used for

Source code transformations. All kinds. Examples: New control flow statements: You need a WHILE statement? Your language doesn’t have one? Why wait for the benevolent dictator to maybe add one next year. Write it yourself. In five minutes. Shorter code: You need twenty class declarations that almost look identical – only a limited amount of … Read more

What is the difference between a preprocessor macro with no arguments, and one with zero arguments

Replacement only occurrs for a function-like macro if the macro name is followed by a left parenthesis. So, the following all invoke the function-like macro MY_MACRO(): MY_MACRO() MY_MACRO ( ) MY_MACRO ( ) But this would not: MY_MACRO SomethingElse It depends on how you are using the macro and what it is used for as … Read more