11. FAQ (Frequently Asked Questions)




11.0. What to do when I get this error?




11.0.0. Module has undefined references


when you load a partially linked object file, or when a function you compiled calls a C function that is not defined in any previously loaded library or module you get the above error. To find out which functions are not defined, type (mod-undefined) .



11.0.1. compiler : Unknown Type in: ()


This message may occur for a variety of reasons, but the most common one is that the compiler can't figure out the type of the return value of an expression. A frequent cause is an hash-brace construct (inline C code segment) that is the last expression of a function (and therefore its return value). Lush cannot know the type of the value returned by a hash-brace unless you cast it.

Example 1:

  ;; this causes an error
  (de foo1-broken (x) ((-double-) x) #{ $x*$x #})
  ;; this is correct
  (de foo1-correk (x) ((-double-) x) (to-double #{ $x*$x #}))
Example 2:
  ;; this causes an error (dunno the return type).
  (de foo2-broken (x) ((-idx1- (-int-)) x) #{ *(IDX_PTR($x,int)) = 34 #})
  ;; this is correct (return value is nil).
  (de foo2-correk (x) ((-idx1- (-int-)) x) #{ *(IDX_PTR($x,int)) = 34 #} ())



11.1. How Do I ... ?




11.1.0. Read lines from a file into a list


 (de read-lines(f)
  (reading f
    (let ((ans ()))
      (while (<> (skip-char "\n\r\f") "\e")
        (setq ans (cons (read-string) ans)))
      (reverse ans))))



11.1.1. Apply a function to all elements of a vector


interpreted lisp way:
 (idx-bloop ((x v)) (func x))
efficient compiled C code way:
  (cidx-bloop ("i" ("v" v)) #{ *v = my_c_fun(*v); #}) ())



11.1.2. Get a pointer to the raw data of an idx


just use the idx-ptr function.
  (idx-ptr m}



11.1.3. Get a pointer to a function written in Lisp


Some functions in popular libraries take function pointers as argument (a typical example is the GSL function minimization routines). To obtain a pointer to the compiled version is a function written in Lisp, simply use the function to-gptr :
 (de myfunc (x) ((-double-) x) (- (* x x) 2))
 (dhc-make () myfunc)
 (some-root-finding-function-in-C (to-gptr myfunc))



11.1.4. Know if a function can be used in compiled code


Just use compilablep :
  ? (compilablep +)
  = t