From: ·········@math.ufl.edu
Subject: Getting SBCL to load ".lsp" with non-std characters
Date: 
Message-ID: <cf955aa6-8058-4ddf-b104-f1606f882602@l32g2000hse.googlegroups.com>
    Typically I run CLISP.  I have a bunch of CL files
that `load' each other, and I'd like to run them once
under SBCL   ---hopefully needing no alteration of the
filenames nor of their contents.
    I wonder if someone could save me some
documentation-searching and tell me how to set-up the
following in SBCL.

1: I'd like  (load "algebra")  to load file "algebra.lsp".
However, it seems that SBCL searches for "algebra.lisp",
then errors when it finds no such file.  [Extension ".lsp"
is the only one that exists in the current directory.]

Is there an SBCL variable such as

   (setq  ext-sbcl::*try-these-extensions*
           '(".lisp"  ".cl" | ) )

to which I can adjoin ".lsp"?


2: There are non-standard characters, e.g � and �, in my
files's comments.  I invoke CLISP as

	clisp -E iso-8859-1

so that my strange-character files will load.  Is there an
SBCL equivalent?

From: Richard M Kreuter
Subject: Re: Getting SBCL to load ".lsp" with non-std characters
Date: 
Message-ID: <87ve56o89i.fsf@progn.net>
·········@math.ufl.edu writes:

> 1: I'd like  (load "algebra")  to load file "algebra.lsp".
> However, it seems that SBCL searches for "algebra.lisp",
> then errors when it finds no such file.  [Extension ".lsp"
> is the only one that exists in the current directory.]
>
> Is there an SBCL variable such as
>
>    (setq  ext-sbcl::*try-these-extensions*
>            '(".lisp"  ".cl" | ) )
>
> to which I can adjoin ".lsp"?

No, there isn't.  The easiest thing to do is to supply a complete
pathname, e.g., "algebra.lsp".  If you want fancy defaulting (or
selection of a compiled file in preference to a source file), I'd
suggest using a defsystem that supports that sort of thing, or else
implementing a wrapper function around LOAD that does what you like,
e.g., (untested),

(defun my-load (pathname &rest load-keys &key)
  (assert (pathname-name pathname))
  (let (path-to-load)
    (if (pathname-type pathname)
        (setf path-to-load pathname
        (let* ((source (merge-pathnames
                        pathname (make-pathname :type "lsp"
                                                :case :local)))
               (binary (compile-file-pathname source))
               (source-exists-p (probe-file source))
               (binary-exists-p (probe-file binary)))
          (cond ((and source-exists-p (not binary-exists-p))
                 (setf path-to-load source))
                ((and binary-exists-p (not source-exists-p))
                 (setf path-to-load binary))
                ((not (or binary-exists-p source-exists-p))
                 (error "No cookie."))
                (t (error "A source file and a binary exist.  ~
                           I'm just a stupid program!  ~
                           Do you expect me to read your mind?"))))))
    (apply 'load path-to-load load-keys)))

Notice that this wrapper never tries loading a file whose name lacks
an extension; if you want that, change the wrapper.

> 2: There are non-standard characters, e.g � and �, in my
> files's comments.  I invoke CLISP as
>
> 	clisp -E iso-8859-1
>
> so that my strange-character files will load.  Is there an
> SBCL equivalent?

That way of invoking Clisp sets several variables that specify the
encodings Clisp uses.  In SBCL, there is just one default external
format, and it's determined SBCL starts, using various system
settings.  So if you want all your I/O to be done using the iso-8859-1
encoding, start SBCL like this (on a system with the suitably
configured locale data):

$ LC_ALL=en_US.ISO-8859-1 sbcl

However, that might be overkill.  LOAD takes a standard keyword
argument, :EXTERNAL-FORMAT, with which you can specify the external
format of a source file.  So you can start SBCL with any locale
settings and proceed to LOAD a source file with any supported external
format, e.g., with

* (load "algebra.lsp" :external-format :iso-8859-1)

--
RmK
From: ·········@math.ufl.edu
Subject: Re: Getting SBCL to load ".lsp" with non-std characters
Date: 
Message-ID: <49f883fd-65b0-4b28-9f98-d925d2a5cd6f@b2g2000hsg.googlegroups.com>
Thanks very much for a quick and informative reply.

> ... I'd suggest using a defsystem that supports that sort
> of thing, or else implementing a wrapper function around
> LOAD that does what you like,

I certainly eventually need to learn one of these
defsystems, but I'll play with the wrapper-idea FTTBeing.


> ... LOAD takes a standard keyword argument,
> :EXTERNAL-FORMAT, with which you can specify the external
> format of a source file.  So you can start SBCL with any
> locale settings and proceed to LOAD a source file with
> any supported external format, e.g., with
>
> * (load "algebra.lsp" :external-format :iso-8859-1)

  Thank you for ":external-format :iso-8859-1".  That loaded my
strange-chars-in-comments file just fine.
=============================================================

  I now see that some of my files _print_ strange
characters.  I made a test file "temp.cl" comprising the line

        (format t "The 1/2  character: �")

The    (load "temp.cl" :external-format :iso-8859-1)
form does load it and prints

        The 1/2  character: ½

but with a spurious character �.    Referring to your

/--------------------------------------------------------\
> ... In SBCL, there is just one default external format,
> and it's determined [when] SBCL starts, using various
> system settings.  So if you want all your I/O to be done
> using the iso-8859-1 encoding, start SBCL like this (on a
> system with the suitably configured locale data):
>
> $ LC_ALL=en_US.ISO-8859-1 sbcl
\________________________________________________________/

I re-invoked SBCL via    LC_ALL=en_US.ISO-8859-1 sbcl
[to the bash shell-prompt under Mac OSX] and found that

        (load "temp.cl")

produced

/--------------------------------------------------------\
debugger invoked on a SB-INT:STREAM-DECODING-ERROR:
  decoding error on stream
  #<SB-SYS:FD-STREAM for "file /Users/squash/Top/Lisp/
temp.cl" {11639181}>
  (:EXTERNAL-FORMAT :UTF-8):
    the octet sequence (189) cannot be decoded.
...
\________________________________________________________/

When I use the full form

        (load "temp.cl" :external-format :iso-8859-1)

then the file loads as before, still printing the spurious �.

[Aside: Probably irrelevant, but environment variable
LC_ALL is not defined in my bash shell.]

  I now see that, in conjuction with "LC_ALL=en_US.ISO-8859-1",
you specified "suitably configured locale data", but I
don't know what they should be.