When I try load Lift package through emacs-slime.
(load "/home/user/lib/lift")
I catch the next error
; compiling (LOAD "/home/user/lib/lift");; swank:close-connection: encoding error on stream
#<SB-SYS:FD-STREAM
for "socket 127.0.0.1:36328, peer: 127.0.0.1:59724"
{1003D9F5E1}>
(:EXTERNAL-FORMAT :LATIN-1):
the character with code 1069 cannot be encoded.
What wrong and how I can load this package?
From the CL spec, LOAD is used for loading Common Lisp source or compiled files. I'm guessing that /home/user/lib/lift is a directory on your system, and that's why LOAD isn't working.
You'll probably have the most luck if you install LIFT using Quicklisp, then load the library like it says in the LIFT User's Guide:
(in-package #:common-lisp-user)
(use-package :lift)
Related
I'm currently working on extending racklog, which is a library I installed by running raco pkg install in the repo directory.
I'm trying to provide a new function, namely a struct constructor. Currently, I'm defining the struct as follows in racklog.rkt. I then provide it from that file.
; racklog.rkt
(struct my-struct (value))
(provide my-struct)
The main file of the library just provides everything from this file:
; main.rkt
(require "racklog.rkt")
(provide (all-from-out "racklog.rkt"))
However, when I try to use the provided constructor (which should be named my-struct) in a file requiring this module, it says that the id isn't found. In particular, I'm trying:
; test.rkt
(require racklog)
my-struct
This also happens even with non-struct things such as defined variables, functions, etc. All the other provided forms seem to be working fine. What's the way I can fix this so I can use the provided constructor? Thanks!
This is an unfortunate stale compiled file issue. Try raco setup --pkgs racklog to compile racklog and run your program again. It should now work. Alternatively, you can manually delete the compiled directories.
I have installed Kieran Healy's emacs social sciences starter kit. I have changed the name of the file kjhealy.org to ljs.org (as per his instructions). The starter kit settings seem to load, but I get the following error.
Warning (initialization): An error occurred while loading
‘/Users/ljs/.emacs.d/init.el’:
File error: Cannot open load file, No such file or directory, ob-shell
When I open emacs with the --debug-init files, I get the following:
Debugger entered--Lisp error: (void-function package-initialize)
(package-initialize)
eval-buffer(#<buffer *load*> nil "/Users/ljs/.emacs.d/init.el" nil t)
; Reading at buffer position 403
load-with-code-conversion("/Users/ljs/.emacs.d/init.el"
"/Users/ljs/.emacs.d/init.el" t t)
load("/Users/ljs/.emacs.d/init" t t)
#[nil "^H\205\276^# \306=\203^Q^#\307^H\310Q\202A^#
\311=\2033^#\312\307\313\314#\203#^#\315\202A^#\312\307\313\$
command-line()
normal-top-level()
Any help with this greatly appreciated.
The underlying reason for this problem is that the file ob-sh.el was renamed to ob-shell.el and the corresponding babel language became shell. That happened in version 8.2.5 (more precisely, it's commit 583e7ab17:
$ git describe 583e7ab17
release_8.2.4-332-g583e7ab17
so 332 commits after 8.2.4).
So if your version of emacs is 8.2.4 or earlier, you have to use sh as the babel language and load the file ob-sh.el. For 8.2.5 and later (including the current version that is distributed with emacs), you have to use shell as the babel language and load the file ob-shell.el.
Hope that clarifies.
In emacs cider repl, now I know how to use clojure.tools.namespace in a leiningen project. However, when I use it on a single clj file which doesn't belong to any project, it seems clojure.tools.namespace doesn't work on the file:
=> #<FileNotFoundException java.io.FileNotFoundException: Could not locate com/foo__init.class or com/foo.clj on classpath: >
I have declared clojure.tools.namespace in .lein/profile.clj and require it in the clj file. How should I make clojure.tools.namespace work on a single clj file?
My profile.clj
{:user
{:repl-options {:timeout 128000}
:plugins [;; REPL
[cider/cider-nrepl "0.9.0-SNAPSHOT"]
[refactor-nrepl "0.2.2"]
;; Application server
[lein-immutant "2.0.0-SNAPSHOT"]
;; Automated testing
[lein-cloverage "1.0.2"]
[lein-test-out "0.3.1"]
;; Package management
[lein-ancient "0.6.2"]
[lein-clojars "0.9.1"]
;; Documentation
[codox "0.6.8"]
[lein-clojuredocs "1.0.2"]
;; Static analysis
[lein-typed "0.3.4"]
;; [jonase/eastwood "0.1.2"]
[lein-bikeshed "0.1.6"]
[lein-kibit "0.0.8"]]
:jvm-opts ["-Dapple.awt.UIElement=true"]
:dependencies [[org.clojars.gjahad/debug-repl "0.3.3"]
[difform "1.1.2"]
[spyscope "0.1.4"]
[org.clojure/tools.trace "0.7.8"]
[org.clojure/tools.namespace "0.2.9"]
[im.chit/vinyasa "0.2.0"]
[slamhound "1.5.5"]
[criterium "0.4.3"]]
:injections [(require 'spyscope.core)
(require 'alex-and-georges.debug-repl)
(require 'com.georgejahad.difform)
(require '[vinyasa.inject :as inj])
(inj/inject 'clojure.core '>
'[[clojure.repl apropos dir doc find-doc pst source]
[clojure.tools.trace trace trace-forms trace-ns trace-vars
untrace-ns untrace-vars]
[clojure.test run-tests run-all-tests]
[clojure.pprint pprint pp]
[com.georgejahad.difform difform]
[alex-and-georges.debug-repl debug-repl]
[vinyasa.pull pull]])]}}
While this doesn't answer your specific question, it might provide some ideas on
alternative workflows which may help.
lein-exec This is a lein plugin that
lets you write clojure scripts or evaluate clojure expressions on the command line
in a similar way to what can be done with shells, python, ruby, perl etc. Of
course, startup time is a bit high, but this plugin will help you deal with
dependencies etc inside your single clj script file. (there are other possible
solutions to improve the startup speed). See this blog post for some examples
http://charsequence.blogspot.in/2012/04/scripting-clojure-with-leiningen-2.html
A scratch project. I have a fairly generic project called scratch. It just allows
me to create a new file within the src directory of the project which I can use for
experiments or demonstrations. For example, I have a file called stackoverflow.clj
within this scratch project which I use when working out the answer to a clojure
question on stack overflow. In fact, I have a lot of individual clj files in this
directory, each just representing a simple idea, test, experiment etc. It isn't
really a project i.e. I couldn't do a lein run at the root of the project and
expect anything meaningful. However, I can go to the source directory in emacs,
open a file and then run cider.
I was trying to make executable file using lisp code. But I can't compile lisp file at all because there is no hellowolrd package before loading helloworld system
;; test.lisp
(asdf:load-system :helloworld)
(defun main()
(helloworld:start))
Of course, I made the helloworld system and put It in ~/quicklisp/local-projects/. helloworld system is successfully loaded without errors.
;; ~/quicklisp/local-projects/helloworld/helloworld.asd
(asdf:defsystem helloworld
:version "1.0"
:components ((:file "package")))
;; ~/quicklisp/local-projects/helloworld/package.lisp
(defpackage :helloworld
(:use :common-lisp :asdf)
(:export :start))
(in-package :helloworld)
(defun start()
(format t "Welcome, ASDF"))
I want to compile test.lisp without explicit loading. I also tried use-package and defpackage but failed.
;; test.lisp
(asdf:load-system :helloworld)
(use-package :helloworld)
(defun main()
(helloworld:start))
;; test.lisp
(asdf:load-system :helloworld)
(defpackage :test
(:use :cl :asdf)
(:export :main))
(in-package :test)
(defun main()
(helloworld:start))
How can I use helloworld package defined in helloworld system without loading it?
Should I have to make a new system using helloworld system?
In this code, there's something interesting going on:
;; test.lisp
(asdf:load-system :helloworld)
(defun main()
(helloworld:start))
You can't compile it as a whole because, as you've noted trying to read the symbol hellowworld:start is a problem, because there's no helloworld package yet. To read the symbol, you at least need to have the package defined. But then, why don't we get the same problem with (asdf:load-system :helloworld)? Simply, the ASDF package has already been defined (either the implementation includes it, or you loaded it already, or something else. One thing you could do, then, is to make sure at compilation time that you've already loaded your helloworld system:
;; test.lisp
(eval-when (:compile-toplevel)
(asdf:load-system :helloworld))
(defun main()
(helloworld:start))
That should let you compile the file; since you'll evaluate the loading form when compiling, and then the package will be defined by the time you define main.
Of course, now you'll have a compiled file, but what will happen if you load it into a fresh instance of Lisp where the helloworld system hasn't been loaded? You'll have a problem. So you really want to load that system when you load the file too, and probably if you're just executing forms from the file too (e.g., if you were reading forms one at a time and evaluating them). So you probably want to evaluate that load-system in two more contexts:
;; test.lisp
(eval-when (:compile-toplevel :load-toplevel :execute)
(asdf:load-system :helloworld))
(defun main()
(helloworld:start))
All that said, be sure to consider whether this is the most appropriate way to load your system in this case. It may make sense if, for some reason, you're trying to keep all the code in one file, or making a delivery script. If, on the other hand, you're making another ASDF loadable system, then you'd probably just include helloworld as a dependency and let ASDF handle loading the dependencies.
1- To have a file that can be both compiled and loaded, use eval-when. See my article http://fare.livejournal.com/146698.html
2- I recommend using cl-launch:
cl-launch -sp helloworld -r start -o helloworld -d !
3- If you don't want to waste 60MB in space, but instead can stand half a second to a few seconds of startup latency, use a #!/usr/bin/cl script.
If you want to compile a binary, you can use a simple Lisp script for that, e. g. (assuming SBCL)
;;;; build.lisp
(require "asdf")
(asdf:operate 'asdf:load-op "helloworld")
(sb-ext:save-lisp-and-die "helloworld"
:toplevel helloworld:start
:executable t)
Makefile:
all:
sbcl --load build.lisp
When loading a file, Lisp consequently executes its forms, so by the time it arrives at save-lisp-and-die it already knows about the helloworld package.
There are also dedicated tools for making executables, buildapp and cl-launch. The latter can produce executable scripts and work with saved cores.
UPD
Yes, the executable built in this way will contain the whole Lisp, so 1) it will be huge; 2) having two or more such executables means that you've got (probably superfluous) copies of the whole Lisp.
Another implementation can produce smaller binaries, e. g. CLISP; they say commercial ones are even better.
For Lisp-less target computers this is the only possible solution. On the contrary, if a target computer has a Lisp compiler, there are are two other options: scripts and saved cores.
You can make a shell script invoking sbcl --load <file>or use cl-launch to obtain a sophisticated shell wrapper, which can be as portable as you want it to. SBCL and CLISP support shebang, too.
However, if startup time matters, loading libraries will be a bottleneck, even though they are compiled only once. In this case you can work around by using a custom core, or image. A core can be thought of as a saved state of the Lisp world, and saving a core is the primary task of sb-ext:save-lisp-and-die and its counterparts. Loading a core is fast, and you immediately have all the libraries compiled in it. But then again the size becomes considerable, though not as huge as in the case of a standalone executable. Naturally, one core can be used for several applications. Cl-launch can work with cores as well; in particular, it allows to conveniently define the entry function.
$ecl
;;; Loading "/home/***/quicklisp/setup.lisp"
;;; Loading #P"/usr/local/lib/ecl-12.7.1/cmp.fas"
;;; Loading #P"/usr/local/lib/ecl-12.7.1/asdf.fas"
ASDF could not load sockets because
An error occurred during initialization:
Error while trying to load definition for system sockets from pathname
/usr/local/lib/ecl-12.7.1/sockets.asd:
No applicable method for SOURCE-FILE-TYPE with arguments of types COMPILED-FILE PREBUILT-SYSTEM.
$cat ~/.eclrc
;;; The following lines added by ql:add-to-init-file:
#-quicklisp
(let ((quicklisp-init (merge-pathnames "quicklisp/setup.lisp"
(user-homedir-pathname))))
(when (probe-file quicklisp-init)
(load quicklisp-init)))
Regards!
You do not provide any information about the version of quicklisp or the version of ECL you are using, what makes it hard to answer your question.
I presume you are using ECL 12.7.1, which is too old to work with recent versions of ASDF+quicklisp. Moreover, there was a problem with a recent quicklisp that shipped a version of ASDF that was incomplete: it did not load ASDF-bundle and support loading precompiled libraries.
All these problems have been solved in the CVS/git sources and I will produce a new release any time soon.
Juanjo