Avoiding symbol capture when using macros to generate functions (or other macros)

I'm a bit confused as to exactly when symbol capture will occur with clojure macros. Suppose that I have a macro which defines a function from keywords. In this trivial example, (defmacro foo [keywd1 keywd2] `(defn ~(symbol (name keywd1)) [~(symbol (name keywd2))] (* 2 ~(symbol (name keywd2))))) I call (foo :bar :baz), and this gets expanded into (defn bar [baz] (* 2 baz)). So now the question -- can this lead to symbol capture? If so, under what circumstances? I kno

Macros Is a "transparent" macrolet possible?

I'd like to write a Clojure with-test-tags macro that wraps a bunch of forms, and adds some metadata to the name of each deftest form - specifically, add some stuff to a :tags key, so that I can play with a tool to run tests with a specific tag. One obvious implementation for with-test-tags is to walk the entire body recursively, modifying each deftest form as I find it. But I've been reading Let Over Lambda recently, and he makes a good point: instead of walking the code yourself, just wrap th

Macros Umbraco XSLT RenderTemplate Woes

Needing a little guidance with XSLT and Umbraco. Fairly new to XSLT but I think I understand the concepts. Right on one page I have two columns, each with their own separate pickable content. This is done via the standard content picker property (one for each column). The issue is that I need to be able to have two different templates on the page. So in essence the page navigated two which has the columns has to render two of it's child items in its own page. I have this working with one column

Macros Is it possible to write the following lisp macro as a function?

I'm reading Paul Graham's ANSI Common Lisp. In the chapter about macros he shows the following example: (defmacro in (obj &rest choices) (let ((insym (gensym))) `(let ((,insym ,obj)) (or ,@(mapcar #'(lambda (c) `(eql ,insym ,c)) choices))))) (Returns true if the first argument is equal to any of the other arguments) He holds that it can't be written as a function. Wouldn't this function have the same functionality? (defun in (obj &rest choices) (red

how to save 2 texts in the same file.csv but in two differenct columns on iMacros

I'm working hard to understand how to save two different text, on the same file.csv (or .txt) but on two different columns. I've build a .JS that generate random TEXTs, then fill some fields and then procede with the rest of the macro. What I want to do, is to save those TEXTs (email, password) the the .csv but in {{!COL1}} & {{!COL2}} Is there any way to build something like this? Thank you so much! eiifq83234

Macros LibreOffice Calc, How to add a menu at file open and remove on file close

I have a few (recorded) macro's in LibreOffice Calc. I created a menu item and a few toolbar items for these macro's, but they are visible all the time. Since these macro's are specific for this spreadsheet ONLY (stored inside the spreadsheet), I would like to add the menu items "on-file-open", dim the added menu "on-file-not-active" and remove the menu items "on-file-close". Inside MS Excel, this is relatively easy, and I have done that many times, but I have not been able to find the LibreOff

Macros Error during expansion of macro in Chicken Scheme

I'm learning how the macro system in Scheme works and I'm trying to make my code look more JavaScript-y. So I thought I would start with the function macro. This is how I want a function definition to look: (function id (x) x) It should expand to the following: (define (id x) x) So I write a macro as follows: (define-syntax function (lambda (name args . body) `(define (,name ,@args) ,@body))) However when I use it I get the following error (in Chicken Scheme): Error: during

Macros Qlikview Macro VBScript to print pdf and email will not run consistently - Fails in email

I have been tearing my hair out over the last few days in trying to get this macro to work consistantly on the Windows scheduler. Basically the workflow is as follows: 1) Windows Scheduler - Daily, uses Admin user credentials 2) Batch file - Reloads using /l 3) Reloads Qlikview application, which has triggers on post reload to save a pdf and email it using PDF Xchange and an html formatted e-mail to cover mobile. I am getting such inconsistent behaviour that I cannot isolate the problem to

Macros How to modify place with arbitrary function

Sometimes we need to modify a place but here is no built-in function that meets our needs. For instance, here are incf and decf for addition and subtraction: CL-USER> (defvar *x* 5) *X* CL-USER> (incf *x* 3) 8 CL-USER> *x* 8 CL-USER> (decf *x* 10) -2 CL-USER> *x* -2 But how about multiplication and division? What if we wish to modify a place with arbitrary function, like this: (xf (lambda (x) ...) *x*) xf utility would be very useful, especially when we have to deal with de

Macros LINT exclude macro from evaluation

I am using LINT to check automatically generated C-sourcefiles. In these sourcefiles there is the use of those macros (simplified): #define MACRO_CHECK(a, b, c) \ ((a==b) ? b : (SET_VAR, c)) #define SET_VAR \ global_var = 0 \ In the code, these macros are used like this: if ( (x==0) && (MACRO(var1,var2,var3)==0) ) { //... } My LINT-analysis gives me the following message: LINT Note 9007: side effects on right hand of logical operator Since my Macro is writing a value

Macros haxe Incrementing class ID with an autoBuild macro

I'm trying to use an autoBuild macro on my Component class so that every class extending Component get an incrementing ID (0, 1, 2, 3...), the problem is that it seems haxe caches some files, so when recompiling some classes won't get rebuilt, so let's say some already built classes have ID 0, 1 and 2. Now I create some new classes and they will also get ID 0, 1 and 2 because the already built classes arent processed so they don't increment the ID. So I end up with some classes with the same ID

Can macros expand to a combination of patterns?

As of Rust 1.0, there is no way to group multiple patterns into one binding: // It does not compile match x as char { b @ ('A' | 'Z') => println!("A or Z: {}", b), _ => println!("Try again") } // Correct version match x as char { b @ 'A' | b @ 'Z' => println!("A or Z: {}", b), _ => println!("Try again") } I was wondering if a macro could do the dirty job of binding all the different possibilities. Here is a partial attempt: macro_rules! bind_alternatives { ($

ImageJ / Fiji: detailed procedure of importing text image sequence by macros?

It seems that there is no official plugin at ImageJ or Fiji on how to import text image sequence. As I searched, it just possible by using macros. I found this script by searching: dir = getDirectory("Choose directory"); list = getFileList(dir); run("Close All"); setBatchMode(true); for (i=0; i<list.length; i++) { file = dir + list[i]; run("Text Image... ", "open=&file"); } run("Images to Stack", "use"); setBatchMode(false); I tried to use this script, so I saved it in a text file (I

Macros Fixing "no rules expected the token" macro error

I'm trying to write a macro for destructuring BSON data which looks like this: let bson: Document = ...; let (id, hash, name, path, modification_time, size, metadata, commit_data) = bson_destructure! { get id = from (bson), optional, name ("_id"), as ObjectId; get hash = from (bson), as String, through (|s| ContentHash::from_str(&s)); get name = from (bson), as String; get path = from (bson), as Bson, through (PathBuf::from_bson); get modification_time = from (bson), as

Macros define scheme macro for xor

Notice the following macro is working. (define-syntax xor (syntax-rules () ((xor a1 a2) (if a1 (false? a2) (true? a2))) ((xor a1 a2 a3 ...) (let ((a (xor a1 a2))) (xor a a3 ...))))) However it seems if I leave out the a3 in the parameter list of the general case, it won't work properly. (define-syntax xor (syntax-rules () ((xor a1 a2) (if a1 (false? a2) (true? a2))) ((xor a1 a2 ...) (let ((a (xor a1 a2))) (xor

Macros JasperSoft Studio 5.6.1 Excel Macro Merge Template

I am attempting to merge an excel exported file from Jaspersoft Studio 5.6.1 with a macro-enabled excel file. However, when I use the "Add JasperReports Server Resource", other file types are not permitted. What is the proper procedure for uploading macro.xls? Is the macro file needed in the local studio folder structure and get compiled together with the .jrxml OR does it exist on the JasperServer as a resource that is retrieved when the report is executed? This is a requirement for us in orde

Macros Possible to apply constraints on identifiers passed into a macro?

Since Rust doesn't yet support concat_idents in stable, it may be necessary to pass in multiple similar identifiers as arguments. This allows for accidentally passing in the wrong positional arguments. Is there a way to check the identifiers match some basic rules such as "contains text", "starts with", "ends with", etc. struct_bitflag_flag_fn_impl!( MyStructType, my_struct_flag::SELECT, select_test, select_set, select_clear, select_set_bool, select_toggle); struct_bitflag_flag_fn_imp

Macros Error message 'unclosed %DO statement' for sas macro to compare two numeric values

I am using the macro below to compare two numeric values as part of an exercise. options mlogic mprint; %let price_trd = 93.68; %put &price_trd.; %let max_price = 100.94; %put &max_price.; %macro test; %if &price_trd. < &max_price %then %do; %if %sysevalf(&price_trd. LT &max_price) %then %do; %put Pass HERE; %end; %mend; %test; I am getting the errors below: There is one unclosed %DO statement. The macro was not compiled. Please let me know our a

Macros Scheme macro what does match what?

From https://www.gnu.org/software/guile/manual/html_node/Syntax-Rules.html#Syntax-Rules I got the following macro example: (define-syntax simple-let (syntax-rules () ((_ (head ... ((x . y) val) . tail) body1 body2 ...) (syntax-error "expected an identifier but got" (x . y))) ((_ ((name val) ...) body1 body2 ...) ((lambda (name ...) body1 body2 ...) val ...)))) I am trying to understand how this macro works. So I annotated it a little: ;; EXAMPLE

How to prevent form evaluation in lisp macros?

I'm trying to create a simple memo defun. How can I prevent evaluating of args form in this code? (defmacro defun/memo (name args &rest body) `(let ((memo (make-hash-table :test 'equalp))) (defun ,name ,args (if (gethash (loop for x in ,args collect x) memo) (gethash (loop for x in ,args collect x) memo) (let ((result (progn ,@body))) (setf (gethash (loop for x in ,args collect x) memo) result) result))))) Error: ; in: DEFUN A

Macros How to write a DSL that creates a function with arguments?

I would like to define a macro such that I can pass a do block into it, and have the macro create a function that calls the block, with an argument. I am running into a chicken & egg issue because the code below complains that name is not defined. defmodule MyMacro do defmacro greet(do: block) do quote do def hello(name), do: unquote(block) end end end defmodule Test do import MyMacro greet do IO.puts("Hello, #{name}!") end end Attempting to compile this code

Macros How to match trait bounds in a macro?

I'm trying to match the trait bounds for generic types: macro_rules! test { ( where $( $bounded_type:ident: $( $bound:tt )++, )+ ) => { // Dummy expansion for test: struct Foo<T, U> where $( $bounded_type : $( $bound )++, )+ { t: T, u: U } } } test! { where T: PartialEq + Clone, U: PartialEq, } fn main() {} Unfortunately, if I understand we

Macros Expressing a Lot with a Small Number of Operators

In his book On Lisp, Paul Graham emphasizes that Lisp is “the extensible language”. He says this means building progressively higher language interfaces up toward a language in which an application can be usefully discussed or analyzed. This results in an orthogonal language ... in which you can express a lot by combining a small number of operators in a lot of different ways. As an experiment I’d like to try and extend one of the more useful sequence functions, namely remove. Putting aside fo

Macros GraffitiCMS Comment Forms

In GraffitiCMS v1.2, I'm trying to include the comment form on my blog posts, but the submit button does nothing. Comments are enabled for the post, and I've included $macros.CommentForm() in the blog.post.view file. I've also confirmed that the necessary Ajax.ashx file exists on the root. Are there any other dependencies? Are there any instructions posted anywhere that explain how to make this work? I've been Googling for several hours and can't find any. NOTE: I cannot upgrade to v1.3 at thi

Macros How do I share a atom within a macro in Clojurescript?

I have the following code in a clj (clojure) namespace. (ns project.clojure.clojurescript-macros) (def trace-history (atom [])) ; hmm, you could run out of memory on recursive functions here? ; Fortunately functions aren't actually recursive in clojure. :] (defmacro push-args [name args] `(swap! trace-history (fn [stack#] (conj stack# [~name (zipmap ~(vec (map str args)) ~args)])))) (push-args :hello [:a :b :c]) within another cljs (clojurescript) namespace, I have the follow

Macros How do I define a macro with multiple pragmas for Clang?

I'd like to add some macros to ease (un)setting a specific warning around routines that we are deprecating internally. I'd like to turn this: #pragma clang diagnostic push #pragma clang diagnostic warning "-Wdeprecated-declarations" void Foo() __attribute__((deprecated("Warning: deprecated routine"))) #pragma clang diagnostic pop into this: MY_DEPRECATED_BEGIN void Foo() MY_DEPRECATED MY_DEPRECATED_END The MY_DEPRECATED_BEGIN macro is giving me trouble as I have to specify two pragmas

Mutt macros: How to set and then use a variable in one macro?

I'm trying to write a small mutt macro that will set a variable, and then re-use that variable in the same macro. What I'm really trying to do is compose a message and sub in the To: address (which later I will populate dynamically). This is in my .muttrc set my_to = "bobby@test.com" macro index E "<enter-command> set my_to = barry@test.com<enter>mn\$my_to" My problem is the variable my_to never changes from bobby@... to barry@... I believe it has to do with the $ being interpr

Macros Is there any way to define a compile-time (expansion-time) macro variable in Racket or any other Scheme?

To give a simple example: (define-macro-variable _iota 0) ; define-macro-variable does not really exist (define-syntax (iota stx) (syntax-case stx () ((iota) (let ((i _iota)) (set! _iota (+ i 1)) #`#,i)))) Such that given: (define zero (iota)) (define one-two-three (list (iota) (iota) (iota))) (define (four) (iota)) the following should all evaluate to #t: (equal? zero 0) (equal? one-two-three '(1 2 3)) ; possibly in a different order (equal? (four) 4) (equal? (f

Macros Sublime Text 3: How can I configure a macro to respond to ALL commands?

My current dilemma is a difficulty in calling some commands. Essentially, I want to create a macro that performs the following operations in sequence: Ctrl + D Ctrl + C Ctrl + ; Ctrl + V For those of you who know your keyboard shortcuts, it's evident that this does the following: Selects the current word Copies it to the clipboard Opens the "Goto Anything" search box, and prefixes your query with a # sign, denoting you wish to search for a symbol/function Pastes the copied word in the sear

Do Swig's macros support calling nested macros, dynamically?

I've created a Swig macro that dynamically calls new macros. The result I've found from doing this is that the HTML markup from within the nested macro is not rendering as HTML, rather it's rendering as an HTML text node which includes the HTML tag I used. My test markup was simply an H1 element with "Hello World!" inside the element. Do Swig's macros support calling nested macros? Or any ideas of how I can get the HTML markup from the nested macro to render as HTML? Here's the exact code I'm

Macros Specman DAC macro: How to define 2 inputs of different type (uint and string)?

in my verification environment I have different registers' types with almost the same name that differs only by index, e.g.: timer_load_0, timer_load_1 etc.. I try to create a macro that gets 2 parameters: string (the 'name' of the register without its index) and uint (the register's index) and returns a variable of "concatenated" register type. For example I would like that the command: my_idx : uint = 0; create_reg "timer_load" my_idx; will return the variable timer_load_0. My macro code:

Is it possible to perform calculations with static primitives using Rust's macros / syntax extensions?

I'm curious as to whether it is possible to perform compile time calculations on static primitives that return other static primitives. For example, something like this: static FOUR: uint = add!(2u, 2u); static FORTY_TWO: f32 = div!(84f32, 2f32); static CHANNELS: uint = 2; static FRAMES: uint = 256; static BUFFER_SIZE: uint = mul!(CHANNELS, FRAMES); If it is possible, how would one approach this?

Macros Sublime Text Select and Copy in one (macro and keybinding) not working, why?

I have a select-copy.sublime-macro files that contains this: [ { "command": "expand_selection_to_word" }, { "command": "copy" } ] I then have this in my sublime-keymap file: { "keys": ["ctrl+d"], "command": "run_macro_file", "args": {"file": "Packages/User/select-copy.sublime-macro" } } However, given a line like this: property: val[|]ue; Where [|] is the cursor, when I press my keybinding (ctrl+d), I would expect to get 'value' copied. However, when I paste, I act

Macros How do I debug an OpenOffice function macro?

I'm trying to do some basic spreadsheet tasks within OpenOffice for which the standard functions won't suffice, so I'd like to write my own macro in BASIC. However, my function doesn't work. How do I go about debugging it? I tried inserting MsgBox("something") throughout my code but this has no effect (no message box appears when I call the function from Calc. I also tried placing breakpoints throughout the function, which Calc simply ignores. How can I debug my function? The debugging guide

Arbitrary arguments in Elixir Macros - wrapping a body

I'm working on a small library dealing with ETS and I want to be able to exit functions early if the table doesn't exist. I can't put this in a guard because Elixir prevents talking to :ets in a guard, and so I have to basically put this check in every function, which ends up looking something horrible like this (code is to demo - I know it's messy :)): def get_and_update(cache, key, modifier) do unless is_ets_table(cache) do { :error, create_error(cache) } else set(cache, key, modi

Macros Managing signed numerical macro arguments in Latex

I have signed numbers with the unwanted effects : x+-5 x--5 (I don't know in advance whether the constant \const is positive or negative). I created these macros to cope with the problem : \def\plus#1{\ifthenelse{#1<0}{#1}{+#1}} \def\cutMinus-#1{#1} % to remove the minus in front of a negative number \def\minus#1{\ifthenelse{#1<0}{+\cutMinus#1}{-#1}} Then with x\plus{\const} I get the expression correctly : x-5 Goal : I wish I could use \plus and \minus as a replacement of the

Cartesian macros on type fields in Julia

The Base.Cartesian module offers the @nref macro: using Base.Cartesian i_1, i_2 = 1, 1 A = rand(3,3) @nref 2 A i This returns A[1,1]. However, @nref does not work with fields of a (custom) type: type Foo bar::Matrix end foo = Foo( rand(3,3) ) i_1, i_2 = 1, 1 @nref 2 foo.bar i This results in an error: ERROR: MethodError: `_nref` has no method matching _nref(::Int64, ::Expr, ::Symbol) Closest candidates are: _nref(::Int64, ::Symbol, ::Any) The error seems reasonable as foo.bar is

Macros Replace missing value with a macro

As I want to make a macro program to replace multiple variable'missing values by their previous non-missing values within a group and before that I need to sort the dataset using multiple-by variables in order to identify every observations. I have a test dataset: data temp2; input countryname $1-5 +1 countrycode $7-8 +1 dev 1. +1 legal 1. +1 audit 1.; datalines; china 22 9 2 3 china 22 . . 3 china 22 7 3 . china 21 4 . . japan 13 3 . 1 japan 12 3 . . japan 13 1 2 3 ; run; And as you can se

Macros Is it possible to define a macro which handles grammatical cases?

I'd like to define a macro callme which can be applied like this. fn main() { let a=4; let b=5; callme!( a (b) => { a+b } ; a (b) => { a*b } ; a (b) ~ C ); } I do not know how to get a working macro definition for callme. Currently I'm trying something like this: macro_rules! callme { ( $($A: ident ($B: ident) => {$E: expr}) ; * ) => ( $( println!("{:?} {:?} {:?}", $A, $B, $E); ) * ); (

What are each part of macros named in the C standard?

I am writing an academic paper related to the C language, but I am pretty confused about the terminology and afraid that the word I used is not complied with the standard. For example, #define AREA_CIRCLE(radius) (M_PI * radius * radius) |<-----------------------A------------------------>| |<-B->| |<---C--->| |<D >| |<----------E--------->| printf("%f\n", AREA_CIRCLE(1024)); |<------A'----->| |<---C'-->| |E'| I am not

Macros How do I write macro arguments which capture parenthesis?

I am hoping to write a Rust macro which forwards its entire argument to a second macro — even when that argument contains exciting parenthesization. Here is what I have tried so far: macro_rules! parse { (done) => (println!("done!")); (if ($cond:tt) {$then:tt}) => (println!("if! "); parse!($cond); parse($then)); } macro_rules! forward { ($($e:tt)*) => (parse!($($e)*; done)); } fn main() { forward!(if (done) {done} ); } This doesn't work, and produces the error:

Macros Macro block unexpectedly returns [do: return value]

I have the following definition inside a macro: defmacro route(pattern, options \\ [], block) do name = "my_fun" def unquote(name)(var!(conn)) do unquote(block) end end I am calling the macro with this function: route "/" do conn |> put_resp_content_type("text/plain") |> send_resp(200, "Hello, world!") The inner block is returning a %Plug.Conn{} struct, but when I print the results of unquote(block) in my macro, I get [do: %Plug.Conn{}] What am I doing wrong? Where di

Macros How do I pass the output of a tiddlywiki widget as input to a macro?

I have a tiddlywiki [TW5] macro to determine the age of a person--usage would be: <<getAge birthDate deathDate>> Usage: <<getAge "1898-10-04" "1947-12-09">> I want to use this macro on a person tiddler--a tiddler that identifies an individual. I also have event tiddlers--such as a person's birth and another for a person's death. Person tiddlers are tagged as "person", birth tiddlers are tagged as "birth" and "event" and

Macros Lisp - "case" macro implementation

I'm wondering how the case macro works, but just expanding it is not enough. How does it generate the cond statement without knowing how many arguments there are? Does it use a loop or something? And if so then why does it not show up when i run macroexpand. I need to write something that works in a similar way, that's why I ask.

Macros Trying to rewrite an ugly macro

I'm new to lisp, and have been trying to learn Common Lisp by diving in and writing some code. I've read plenty of documentation on the subject, but it's taking a while to really sink in. I have written a couple of macros (? and ??) for performing unit tests, but I'm having some difficulty. The code is at the end of the post, to avoid cluttering the actual question. Here is an example of usage: (?? (? "Arithmetic tests" (? "Addition" (= (+ 1 2) 3) (= (+ 1 2 3) 6)

Macros erlang macro expansion bug

macro module: -module(macro). -include_lib("eunit/include/eunit.hrl"). -define(EXPAND(_T), ??_T). macro_test() -> ?assertEqual("Test", ?EXPAND(Test)), ?assertEqual("Test.test", ?EXPAND(Test.test)). Is resulting : 6> c(macro). {ok,macro} 7> eunit:test(macro). macro: macro_test (module 'macro')...*failed* in function macro:'-macro_test/0-fun-1-'/1 (macro.erl, line 9) **error:{assertEqual_failed,[{module,macro}, {line,9}, {e

Macros Strange macroexpansion error in SBCL

I want to write a Fibonacci number computing function fib in Lisp using SBCL 1.3.3 for Windows x86_64. Use lazy computation to avoid repetition. The working code so far is: (defvar *fibs* (make-hash-table)) (defun get-value (idx) (if (functionp (gethash idx *fibs*)) (setf (gethash idx *fibs*) (funcall (gethash idx *fibs*))) (gethash idx *fibs*))) (defun fib (n) (loop for i from 0 below n if (< i 2) do (setf (gethash i *fibs*) 1) else do (setf (gethash i *fibs*)

  1    2   3   4   5   6  ... 下一页 最后一页 共 10 页