Help with metaprogramming

2022-01-03 Thread keks84
A big THANK YOU to all of you guys! Your replies give a lot of things to consider: quote and procedural version, even a dsl package. Well worth to have a closer look at Nim.

Help with metaprogramming

2022-01-03 Thread planetis
with fusion astdsl, it becomes a little simpler to write (not by much, for this example though): import fusion/astdsl macro transposeImpl(M, N: static[int]; x, res: typed): untyped = result = buildAst(stmtList): #let typeSym = getTypeInst(res) #let type

Help with metaprogramming

2022-01-03 Thread planetis
This is a very nice use case, I made an example for you import std/macros type Matrix[M, N: static[int]] = array[M * N, float32] macro transposeImpl(M, N: static[int]; x, res: typed): untyped = result = newNimNode(nnkStmtList) for n in 0 ..< N * M:

Help with metaprogramming

2022-01-03 Thread Hlaaftana
>From what I understand you are asking for the same thing as the code given >does. This might be wrong though. The point of the given code is that in Nim, >`a[b, c]` is a valid expression that parses to a call to a routine named `[]` >with the arguments `a, b, c`. Here is how the given code is u

Help with metaprogramming

2022-01-02 Thread keks84
Sample generated code from "symbolically" running the for-loops using for x = A\b > // loading A > A[1] = gn_C1 + 1/RC1; > A[2] = - gn_C1 - 1/RC1; A[3] = -1; A[4] = - gn_C1 - 1/RC1; A[5] = gn_C1 + > gn_C2n + 1/RC1 + 1/RC2N + 1/Rshort_antp_

Help with metaprogramming

2022-01-02 Thread SolitudeSF
Huh?

Help with metaprogramming

2022-01-02 Thread keks84
Thanks for replying. I am an absolute beginner in Nim, so please bear with me. Looks like an ordinary numerical function, where is the code generation? As use case, an algorithm for x=Ab (like gaussian elimination) and sparsity pattern for A and b, is converted to an array of simple expressions

Help with metaprogramming

2022-01-02 Thread planetis
I don't think a macro is necessary in your case, a proc can work just fine: proc `[]`*[T](m: Matrix[T], i, j: int): T {.inline.} = result = m.data[i * m.n + j] Run

Help with metaprogramming

2022-01-02 Thread keks84
Hi, I am considering Nim as programming language for its metaprogramming capabilities. As a test case for code generation, I would like to convert matrix expressions like `A[i,j]` to `Avec[3]`, given` i = 1`,` j = 2`. In Matlab this could be done using string manipulations, in Julia on the AST