macros

In Python, how can I include (not import) one file within another file, macro style, without changing namespace?

天大地大妈咪最大 提交于 2020-05-23 23:49:39
问题 First I do know about 'import'. When I try 'import' it doesn't work. What I'm trying to do is split a single module into two parts, one of which is editable by a group and the other of which is not. I want the group to write well-defined 'retrieval functions' without the temptation or ability to edit the backend code that runs them (even accidentally). The changes in namespace on an 'import' are getting in my way. I'm looking for a macro-style inclusion of File_A's text within File_B, to be

(Chez) Scheme macro for hiding lambdas

廉价感情. 提交于 2020-05-13 14:35:56
问题 I would like to write a macro to create shorthand syntax for hiding more verbose lambda expressions, but I'm struggling to understand how to write macros (which I realize is an argument against using them). Given this example: (define alist-example '((x 1 2 3) (y 4 5 6) (z 7 8 9))) (define ($ alist name) (cdr (assoc name alist))) ((lambda (a) (map (lambda (x y z) (+ x y z)) ($ a 'x) ($ a 'y) ($ a 'z))) alist-example) ((lambda (a) (map (lambda (y) (/ y (apply max ($ a 'y)))) ($ a 'y))) alist

(Chez) Scheme macro for hiding lambdas

社会主义新天地 提交于 2020-05-13 14:34:12
问题 I would like to write a macro to create shorthand syntax for hiding more verbose lambda expressions, but I'm struggling to understand how to write macros (which I realize is an argument against using them). Given this example: (define alist-example '((x 1 2 3) (y 4 5 6) (z 7 8 9))) (define ($ alist name) (cdr (assoc name alist))) ((lambda (a) (map (lambda (x y z) (+ x y z)) ($ a 'x) ($ a 'y) ($ a 'z))) alist-example) ((lambda (a) (map (lambda (y) (/ y (apply max ($ a 'y)))) ($ a 'y))) alist

Any utility to test expand C/C++ #define macros?

狂风中的少年 提交于 2020-05-09 18:27:34
问题 It seems I often spend way too much time trying to get a #define macro to do exactly what i want. I'll post my current dilemma below and any help is appreciated. But really the bigger question is whether there is any utility someone could recommend, to quickly display what a macro is actually doing? It seems like even the slow trial and error process would go much faster if I could see what is wrong. Currently, I'm dynamically loading a long list of functions from a DLL I made. The way I've

Vim Macro on Every Line of Visual Selection

瘦欲@ 提交于 2020-05-09 17:33:22
问题 I'd like to run a macro on every line in a selection, rather than totalling up the number of lines in my head. For instance, I might write a macro to transform: Last, First Into First Last and I'd like it to run on all these lines: Stewart, John Pumpkin, Freddy Mai, Stefan ... Any ideas Vim gurus? EDIT: This is just an example, obviously this is trivialy regexable, but there are other instances that come up that aren't quite so easy that I'd prefer to use macros. 回答1: Suppose you had a macro

What are all the cases of ellipsis in Scheme pattern matching Hygienic Macros System

柔情痞子 提交于 2020-04-30 09:21:22
问题 This is continuation of my previous question Missing argument in syntax-rules Hygienic macro call from Scheme R5RS example so you can have only this two cases: First (foo bar baz) ... that can be used as foo ... ==> (foo_1 _ foo_2 _ foo_3 _) bar ... ==> (_ bar_1 _ bar_2 _ bar_3 _) or (foo bar bar) ... but what should expand this expression into? (foo baz) ... Second (foo bar baz ...) which can be used as baz ... that expands into ,@(1 2 3) if input is (anything 0 1 2 3) . Are there any other

Is there a VS Code shortcut for creating a new file from selected or clipboard code?

蹲街弑〆低调 提交于 2020-04-16 04:16:36
问题 I work with large html files that I would like to fragment into separate files. The process of doing this is quite tedious as it requires copying the code, creating a new file, pasting it in the new file, and then selecting a folder and a new name to save it under. Is there a built-in shortcut, macro or extension for VS Code for making this easier? 回答1: Here is a macro which does what you want. I am using the macro extension multi-command but there are others. In settings.json: "multiCommand

Why can't a string literal be concatenated to __FUNCTION__?

断了今生、忘了曾经 提交于 2020-04-14 07:36:07
问题 Isn't __FUNCTION__ a string literal? I'd always thought it was - along the lines of __FILE__ , but I just discovered I can't adjacently concatenate a string literal to it. If it's not a string literal, what is it defined as? I can't get cscope to resolve it. E.g. #include <iostream> int main( int argc, char* argv[] ) { std::cout << __FILE__ << std::endl; std::cout << __FILE__ "A" << std::endl; std::cout << __FUNCTION__ << std::endl; //std::cout << __FUNCTION__ "A" << std::endl; // Doesn't

What is the macro definition of isupper in C?

家住魔仙堡 提交于 2020-04-10 12:33:15
问题 I want to know how the "isupper" macro is defined in C/C++. Could you please provide me the same or point me to available resources. I tried looking at ctype.h but couldnt figure it out. 回答1: It's implementation defined -- every vendor can, and usually does, do it differently. The most common usually involves a "traits" table - an array with one element for each character, the value of that element being a collection of flags indicates details about the character. An example would be: traits[

What is the macro definition of isupper in C?

♀尐吖头ヾ 提交于 2020-04-10 12:32:34
问题 I want to know how the "isupper" macro is defined in C/C++. Could you please provide me the same or point me to available resources. I tried looking at ctype.h but couldnt figure it out. 回答1: It's implementation defined -- every vendor can, and usually does, do it differently. The most common usually involves a "traits" table - an array with one element for each character, the value of that element being a collection of flags indicates details about the character. An example would be: traits[