3

I am trying to run a test file in SBCL by executing the command sbcl --load file.lisp. However, when I execute the command the file is loaded, but I can't see my program output.

By the way here is a example of a test file:

(locally
    (declare #+sbcl(sb-ext:muffle-conditions style-warning))
  (handler-bind
      (#+sbcl(style-warning #'muffle-warning))
    (load "load.lisp")
 ))
(interval 5)
(interval 20)
(interval 500)

The load.lisp file, loads the source code of my program, that contains the definitions of several functions, including the interval function.

I already try other option from sbcl such as run sbcl --script file.lisp but the output is the same.

Anybody can help me with this problem? Thanks in advance.

** PRINT-OBJECT METHOD **

 (defmethod print-object ((tensor tensor) stream)
   "Implementation of the generic method print-object for the tensor data structure.
   If the tensor is a vector, prints its elements separated by a whitespace.
   If the tensor is not one of the previous cases, then for each sub-tensor of the
   first dimension, prints the sub-tensor separated from the next sub-tensor by a
   number of empty lines that is equal to the number of dimensions minus one."
  (labels ((rec (arg last-iteration)
              (cond ((null arg) nil)
                    ((atom (car arg))
                        (format stream
                                (if (null (cdr arg)) "~A" "~A ")
                                (car arg))
                        (rec (cdr arg) nil))
                    ((and (listp (car arg)) (null (cdr arg)))
                        (rec (car arg) last-iteration)
                        (unless last-iteration
                          (format stream "~%")))
                    (t
                        (rec (car arg) nil)
                        (format stream "~%")
                        (rec (cdr arg) last-iteration)))))
      (rec (tensor-content tensor) t)))
Marcus Gomes
  • 2,534
  • 2
  • 13
  • 15
  • what happens when you remove the mufflers? – sds Jun 08 '15 at 12:41
  • works for me... SCCL 1.1.16 on Mac OS X. – Rainer Joswig Jun 08 '15 at 12:43
  • I am using SBCL 1.2.11 on Mac OS X. When I remove the mufflers I get an error: `ill-formed handler binding: LOAD`. – Marcus Gomes Jun 08 '15 at 12:51
  • I forgot to mention when I execute the code a WARNING is raised: `WARNING: Specializing on the second argument to PRINT-OBJECT has unportable effects, and also interferes with precomputation of print functions for exceptional situations.`. In my implementation I had to define the generic function `print-object`. This could be related with the problem? – Marcus Gomes Jun 08 '15 at 13:16
  • `print-object` is already a defined function in Common Lisp. Specializing the stream parameter may also have non-portable effects... – Rainer Joswig Jun 08 '15 at 13:28
  • 1
    Without seeing your actual code, one can't reproduce your problem. – Rainer Joswig Jun 08 '15 at 13:29
  • Let me explain first, recently i had a project where we need to perform an implementation of APL for CLOS. The `print-object ` code is that: `(defmethod print-object ((tensor tensor) (stream stream))` – Marcus Gomes Jun 08 '15 at 13:38
  • And I am using `format` when I want to print the output to the `stream`. – Marcus Gomes Jun 08 '15 at 13:44
  • UPDATE: I remove the specialization for the stream parameter and the WARNING is not raised when I load the file, but still don't print the program output on SBCL. – Marcus Gomes Jun 08 '15 at 14:09
  • If I execute `sbcl --eval '(load "file.lisp" :print t)'` it prints the program output, but print as a comment and I don't want to do that. – Marcus Gomes Jun 08 '15 at 14:32
  • @MarcusGomes The examples in [Running a Common Lisp function from a Terminal command prompt](http://stackoverflow.com/questions/20301668/running-a-common-lisp-function-from-a-terminal-command-prompt) show output when running files from SBCL. I think we'll need to see you actual printing code to make any more of a diagnosis. – Joshua Taylor Jun 08 '15 at 18:57
  • @JoshuaTaylor The print-object code is available at the post. – Marcus Gomes Jun 08 '15 at 22:39

1 Answers1

2

When you load a file the return values of the forms are not automatically printed.

One option out of many:

(defun show (&rest items)
  (dolist (i items)
    (prin1 i)
    (fresh-line))
  (finish-output))

(locally
    (declare #+sbcl(sb-ext:muffle-conditions style-warning))
  (handler-bind
      (#+sbcl(style-warning #'muffle-warning))
    (load "load.lisp")
 ))

(show
  (interval 5)
  (interval 20)
  (interval 500))

Should be usable with sbcl --script file.lisp.

m-n
  • 1,476
  • 1
  • 9
  • 9
  • I can't modify the test files. It is supposed to work without the function show, as the original example. There is a way to do that in SBCL through the command-line? – Marcus Gomes Jun 08 '15 at 22:53
  • Would it be convenient for you to add printing code to `interval`? I'm not aware of a direct way to do what you want from the command line. You could write a lisp program that when loaded from the command line would load+print the forms in the test file, but that seems roundabout. – m-n Jun 08 '15 at 22:59
  • @MarcusGomes I forgot to @ mention you in my last comment. Do you mean that a third party has given you the task of "make loading this file print that output"? If so then making `interval` do its own printing may be what is expected. – m-n Jun 08 '15 at 23:23