ggplotnim icon indicating copy to clipboard operation
ggplotnim copied to clipboard

Formula usage in a template problematic

Open Vindaar opened this issue 4 years ago • 1 comments

I just thought I introduced a regression with PR #115, because the following is broken:

import ggplotnim

template callMe(): untyped =
  let couplings = newSeq[float](10)
  let vals = newSeq[float](10)
  let df = seqsToDf({"Couplings" : couplings, "Vals": vals})
    .mutate(f{"Couplings" ~ `Couplings` * 1e-12 * 1e-12})

proc foo() =
  callMe()

foo()

it errors out with Error: undeclared identifier: '~'.

However, this is already present on the master branch.

Maybe related to: https://github.com/nim-lang/Nim/issues/11091 ?

Vindaar avatar Jun 10 '21 23:06 Vindaar

Great, add to that generic procedures. This is broken:

proc plotGasGain*[T](charge, counts: seq[T],
                     fitX, fitY: seq[T],
                     xMin, xMax: float,
                     G_fit, chiSq: float,
                     chipNumber, runNumber: int,
                     pathPrefix: string,
                     gasGainInterval = none[GasGainIntervalData]()) =
  ## given a seq of traces (polya distributions for gas gain) plot
  ## the data and the fit, save plots as svg.
  let dfRaw = seqsToDf({ "charge / e-" : charge,
                         "counts" : counts })
  let dfFit = seqsToDf({ "charge / e-" : fitX,
                         "counts" : fitY })
  let df = bind_rows([("Polya", dfRaw),
                      ("Fit", dfFit)],
                     id = "Type")
    # filter to max 2.5e4 electrons, more irrelevant for polya
    .filter(f{c"charge / e-" <= 2.5e4})
    .mutate(f{float -> bool: "FitRange" ~ c"charge / e-" >= xMin})

The stage of adding all symbols to a typed table is not being run (or the symbols aren't resolved? But the CT table is simply empty) before we enter the actual column extraction and type inference.

Also thanks Github for not allowing me to transfer this issue over to Datamancer.

edit: this can be fixed by making compileFormulaImpl a proper typed macro (which we can do now :partying_face:)

Vindaar avatar Jun 29 '21 10:06 Vindaar