macros

Can any one explain about X-macros with example code to use them? [closed]

蓝咒 提交于 2021-01-19 09:02:07
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 7 years ago . Improve this question I am trying to understand the X-macros topic in detail. But didn't get the full clarity on this. It would be better if any one of the expert will explain this topic with some example "how to use, how to call." I have found several articles, but didn't get the

Can any one explain about X-macros with example code to use them? [closed]

狂风中的少年 提交于 2021-01-19 09:02:04
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 7 years ago . Improve this question I am trying to understand the X-macros topic in detail. But didn't get the full clarity on this. It would be better if any one of the expert will explain this topic with some example "how to use, how to call." I have found several articles, but didn't get the

Can any one explain about X-macros with example code to use them? [closed]

做~自己de王妃 提交于 2021-01-19 09:01:36
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 7 years ago . Improve this question I am trying to understand the X-macros topic in detail. But didn't get the full clarity on this. It would be better if any one of the expert will explain this topic with some example "how to use, how to call." I have found several articles, but didn't get the

Typed racket require module repeated evaluation

こ雲淡風輕ζ 提交于 2021-01-05 07:22:46
问题 This is a follow-on to this answer to this question. When this code is saved to a file and run from the command line, it prints 13 three times. Twice I can understand, but three times? Why? When I run it from racket-mode in emacs it prints 13 five times! And when I run it in DrRacket it prints 13 seven times! The behaviour is also different in vanilla Racket? Changing #lang typed/racket to #lang racket prints 13 once from the command line, twice from emacs and three times from DrRacket. What

Rust recursive macro not working for generating struct

余生颓废 提交于 2021-01-03 08:47:05
问题 I am trying to write a macro that generates a struct in Rust. This macro will add different Serde attributes to struct fields based on the type of field. This is the final goal. For now, I'm simply trying to write a macro that uses another macro for generating a recursive code. This is what the code looks like: macro_rules! f_list { ($fname: ident, $ftype: ty) => { pub $fname: $ftype, } } macro_rules! mk_str { ($sname: ident; $($fname: ident: $ftype: ty,)+) => { #[derive(Debug, Clone)] pub

Why can I not access a variable declared in a macro unless I pass in the name of the variable?

*爱你&永不变心* 提交于 2020-12-29 09:49:26
问题 I have this macro: macro_rules! set_vars { ( $($x:ident),* ) => { let outer = 42; $( let $x = outer; )* } } Which expands this invocation: set_vars!(x, y, z); into what I expect (from --pretty=expanded ): let outer = 42; let x = outer; let y = outer; let z = outer; In the subsequent code I can print x , y , and z just fine, but outer seems to be undefined: error[E0425]: cannot find value `outer` in this scope --> src/main.rs:11:5 | 11 | outer; | ^^^^^ not found in this scope I can access the

Wrap function implementations returning a specific type into another function programatically

北战南征 提交于 2020-12-29 08:19:07
问题 I would like to wrap all the user defined functions in a scala project that return a certain type T , into a function that accepts a T and the function name as parameters. eg. given this function is in scope: def withMetrics[T](functionName: String)(f: => Try[T]): Try[T] = { f match { case _: Success[T] => println(s"send metric: success for $functionName") case _: Failure[T] => println(s"send metric: failure for $functionName") } f } the user can send metrics for their functions which return

Wrap function implementations returning a specific type into another function programatically

℡╲_俬逩灬. 提交于 2020-12-29 08:11:29
问题 I would like to wrap all the user defined functions in a scala project that return a certain type T , into a function that accepts a T and the function name as parameters. eg. given this function is in scope: def withMetrics[T](functionName: String)(f: => Try[T]): Try[T] = { f match { case _: Success[T] => println(s"send metric: success for $functionName") case _: Failure[T] => println(s"send metric: failure for $functionName") } f } the user can send metrics for their functions which return

Wrap function implementations returning a specific type into another function programatically

℡╲_俬逩灬. 提交于 2020-12-29 08:07:32
问题 I would like to wrap all the user defined functions in a scala project that return a certain type T , into a function that accepts a T and the function name as parameters. eg. given this function is in scope: def withMetrics[T](functionName: String)(f: => Try[T]): Try[T] = { f match { case _: Success[T] => println(s"send metric: success for $functionName") case _: Failure[T] => println(s"send metric: failure for $functionName") } f } the user can send metrics for their functions which return

Nested Loops Using Loop Macro in Common Lisp

点点圈 提交于 2020-12-26 09:38:44
问题 I am trying to implement a basic nested loop in CL, but the Loop macro is resisting this. Basically, I would like to find all possible products of 3-digit numbers and accumulate them into a list. Here is my attempt: (loop for x downfrom 999 to 998 do (loop for y downfrom 999 to 998 collect (* x y))) The code above returns NIL for some reason. By the way, I realize that I only run down to 998, but this is done for testing purposes. What could I do to obtain a list like this: (999*999 999*998 .