Skip to content

A new macro for @vars #206

Closed
Closed
@AmplitudeGravity

Description

@AmplitudeGravity

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions