Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new macro for @vars #206

Open
AmplitudeGravity opened this issue Apr 13, 2020 · 2 comments
Open

A new macro for @vars #206

AmplitudeGravity opened this issue Apr 13, 2020 · 2 comments

Comments

@AmplitudeGravity
Copy link

I write a macro for @vars when I use symengine. It can be applied to construct multi symbol variables. It seems convenience. I donot know if there are better way to realize this feature. I just leave the code here. Feel free to use or improve it.

macro vars(x,n::Int64)
    q=Expr(:block)
    for i = 1:n
        push!(q.args, Expr(:(=), esc(Symbol("$x$i")), Expr(:call, :(SymEngine._symbol), Expr(:quote, Symbol("$x$i")))))
    end
    push!(q.args, Expr(:tuple, map(esc, "$x".*map(string,1:n).|>Symbol)...))
    q
end

To use it, you can call
@vars x 16
@vars α 16
The outputs are

(x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15, x16)

(α1, α2, α3, α4, α5, α6, α7, α8, α9, α10, α11, α12, α13, α14, α15, α16)

@jverzani
Copy link
Contributor

This is also available through something like: [symbols("α$i") for i in 1:30]. I would think that is sufficient. Users might get confused as to what this does: n=16; @vars x n.

@AmplitudeGravity
Copy link
Author

This is also available through something like: [symbols("α$i") for i in 1:30].

That is only realized part feature of macro @vars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants