ghollisjr / cl-ana

Free (GPL) Common Lisp data analysis library with emphasis on modularity and conceptual clarity.
GNU General Public License v3.0
197 stars 18 forks source link

No applicable method for the generic function cl-ana.table:table-load-next-row #40

Closed geostarling closed 4 years ago

geostarling commented 4 years ago

Hi,

I'm trying to run create simple project that utilizes ltab functionality. I'm following sample code from cl-ana/makeres-table/tests/tabletrans-test.lisp which I simplified like so:

(defpackage satur
  (:use :cl :cl-ana :cl-ana.makeres :cl-ana.plotting :cl-ana.makeres-progress :cl-ana.table-utils))

(in-package :cl-ana)

(defproject example "/home/example/Sources/exampleproj/"
  ;; progresstrans prints progress so you can see how a computation unfolds
  (list #'progresstrans #'macrotrans #'tabletrans)
  (fixed-cache 5))

(defres source
  (srctab (plist-opener '((:x 1)
                          (:x 2)
                          (:x 3)))))

(defres filtered
  (ltab (res source)
      ()
    (when (< (field x) 4)
      ;; you only have to add new fields, all source
      ;; fields not shadowed are still available:
      (push-fields
       ;; new field y, x is still accessible, unshadowed
       (y (* 2 (field x)))))))

(defres canon
  (tab (res filtered)
      ()
      (hdf-opener "/tmp/canon.h5"
                  '(("X" . :int)
                    ("Y" . :float)
                    ("Z" . :float)))
    (push-fields (x (field x))
                 (y (sqrt (field y)))
                 (z (float
                     (expt (field y)
                           2))))))

When I compile/load the project and invoke (makeres) in REPL, I get following error which I'm unable (or don't know how) to debug any further.

There is no applicable method for the generic function
  #<STANDARD-GENERIC-FUNCTION CL-ANA.TABLE:TABLE-LOAD-NEXT-ROW (7)>
when called with arguments
  (NIL).
   [Condition of type SB-PCL::NO-APPLICABLE-METHOD-ERROR]

Restarts:
 0: [RETRY] Retry calling the generic function.
 1: [RETRY] Retry SLY mREPL evaluation request.
 2: [*ABORT] Return to SLY's top level.
 3: [ABORT] abort thread (#<THREAD "sly-channel-1-mrepl-remote-1" RUNNING {1007D16073}>)

Backtrace:
 0: ((:METHOD NO-APPLICABLE-METHOD (T)) #<STANDARD-GENERIC-FUNCTION CL-ANA.TABLE:TABLE-LOAD-NEXT-ROW (7)> NIL) [fast-method]
 1: (SB-PCL::CALL-NO-APPLICABLE-METHOD #<STANDARD-GENERIC-FUNCTION CL-ANA.TABLE:TABLE-LOAD-NEXT-ROW (7)> (NIL))
 2: (CL-ANA.MAKERES::COMPSEQFN
      [No Locals])
 3: ((LAMBDA (&REST CL-ANA.MAKERES::ARGS) :IN CL-ANA.MAKERES::COMPRES
      Locals:
        CL-ANA.MAKERES::FN = #<FUNCTION CL-ANA.MAKERES::COMPSEQFN>
        #:LOOP-LIST-2 = NIL
        CL-ANA.MAKERES::TARGET-FNS = (#<FUNCTION CL-ANA.MAKERES::COMPSEQFN {531EE45B}> #<FUNCTION CL-ANA.MAKERES::COMPSEQFN {531EE64B}> #<FUNCTION CL-ANA.MAKERES::COMPSEQFN>)))
 4: (MAKERES
      Locals:
        ARGS = NIL
        SB-C::THING = #<CLOSURE (LAMBDA (&REST CL-ANA.MAKERES::ARGS) :IN CL-ANA.MAKERES::COMPRES) {10058CAC9B}>)
 5: (SB-INT:SIMPLE-EVAL-IN-LEXENV (MAKERES) #<NULL-LEXENV>)
 6: (EVAL (MAKERES))

The same error happens when I'm trying to use the result of ltab in dotab operator like so:

(defres (filtered sum)
  (dotab (res filtered)
      ((sum 0))
      sum
    (incf sum (field y))))

The issue manifests both on the current master - f616c5ce34 and on fa7cee4 . I use Guix-packaged distribution of cl-ana sources and SBCL 2.0.3.

Any help would be greatly appreciated.

ghollisjr commented 4 years ago

Hey I was able to reproduce this bug; apparently I introduced this bug when I optimized tabletrans a while ago, but I didn't check that specific test and instead tested against other code I was running.

I've fixed the code and uploaded it after more thorough testing.

There is one definite bug in your project definition though: macrotrans should come before tabletrans, and progresstrans should always come last. Otherwise progresstrans screws up the other transformations as they don't understand how progresstrans has changed target definitions, and macrotrans won't have a chance to expand macros that might, e.g., expand into "ltab" or "do-tab" forms.

So the order in your case should be: macrotrans tabletrans progresstrans.

I noted this in the wiki but it's easy to miss things like that. I should make a more noticeable, repeated note of that in the documentation.