Error importing the Levenshtein package in Racket - racket

I am trying to use the Levenshtein package in Racket.
However, even using the "require" command, I still have problems:
#lang racket
(require levenshtein)
>> standard-module-name-resolver: collection not found
for module path: levenshtein
collection: "levenshtein"
in collection directories:
/home/pedro/.racket/6.6/collects
/usr/share/racket/collects
... [156 additional linked and package directories] in: levenshtein
no packages suggestions are available .
I have already used other packages before, with (require racket/trace) or (require rackunit).
Why this package does not work? What should I do?

The packages racket/trace and rackunit are included in the distribution.
The package levenshtein needs to be installed first. An easy way to do this:
1) Open DrRacket
2) In the menu choose "Package Manager..."
3) Choose the tab "Available from catalog"
4) Find your package and install it

Related

ASDF not finding package in custom directory

I'm new to Common Lisp, I'm using Emacs/SLIME on Windows 10, and I'm trying to wrap my head around how CL and ASDF/packaging works.
I have a custom package 'my-pack' in a directory 'D:\Dropbox\my-packages'.
I have created a .conf file in:
%LOCALAPPDATA%\config\common-lisp\source-registry.conf.d\
And added this line:
(:tree "D:\\Dropbox\\my-packages\\")
I opened Emacs, started SLIME and made the project via the REPL:
(cl-project:make-project #p"D:/Dropbox/my-packages/my-pack)
I verified that the project is in the directory and then loaded the system with asdf (version 3.3.1):
(asdf:load-system :my-pack)
And it worked fine.
But when I quit and restart Emacs, I get the following error when trying to the load the system:
Component :MY-PACK not found
[Condition of type ASDF/FIND-COMPONENT:MISSING-COMPONENT]
As far as I can tell I've followed the steps in the manual. Any help appreciated.
cl-project's make-project ends with this line:
(push dir asdf:*central-registry*)
it adds your new project's directory to this list that tells ASDF where to look for projects. What is its value when you restart CL?
2.
\config\common-lisp\
Shouldn't it be .config?
However, I don't encourage to use this conf file with :tree. The doc says:
tell ASDF to recursively scan all the subdirectories
So, imagine that just once, you try yourself at web development and you install, for example, JavaScript dependencies with npm or equivalent, you'll end up with a gigantic node_modules/ and your Lisp will now take a few seconds to start up.
I suggest to put your projects under ~/common-lisp/ or ~/quicklisp/local-projects, or to create symlinks, or to add yourself your projects in asdf:*central-registry* from your Lisp startup file:
;; .sbclrc
(pushnew "/home/me/projects/ciel/" asdf:*central-registry* :test #'equal)

Requiring a module using its path from the project's root?

I'm making a web application. Consider such structure
ProjectName/racket/Servlet.rkt
ProjectName/racket/chart/barchart/BarChart.rkt
ProjectName/template/barchart.svg
How can I inside the BarChart.rkt module require the Barchart.svg template, without using any ..? Ideally, if the application is launched from ProjectName (i.e. cd ProjectName; racket racket/Servlet.rkt), the require part would resemble (require "template/barchart.svg"), but use ProjectName as a root instead of the relative ProjectName/racket/barchart.
1) Naive method
You can use (define-runtime-path):
ProjectName/chart/barchart/BarChart.rkt:
#lang racket/base
(provide barchart-template)
(require
racket/runtime-path
racket/file)
(define-runtime-path barchart.svg "../../template/barchart.svg")
(define (barchart-template)
(file->string barchart.svg))
ProjectName/Servlet.rkt:
#lang racket/base
(require ProjectName/chart/barchart/Barchart)
(displayln (barchart-template)) ;; prints the content of the SVG file, wherever you are
2) Better method
Registering your package
From my experience, the best way to handle paths when developing a Racket application is making a package, then use the classic (require my-package/my-module) syntax instead of using relative paths.
For example, if you have a project like this:
ProjectName/Servlet.rkt
ProjectName/chart/barchart/BarChart.rkt
ProjectName/template/barchart.svg
By adding an info.rkt file at the root of your project, you transform it into a package.
echo "#lang info" > ProjectName/info.rkt
Then call cd ProjectName; raco pkg install.
Then you can require BarChart.rkt in any file with (require ProjectName/chart/BarChart).
Why am I telling you all this? Because now, you can start your application from any folder:
racket -l ProjectName/Servlet
Which will allow you to test easily if your paths are handled whatever the directory you are running the program in.
Getting rid of ../..
Now that your package is registered in your local database, you can easily find it's root directory using (pkg-directory) from pkg/lib:
ProjectName/chart/barchart/BarChart.rkt:
#lang racket/base
(provide barchart-template)
(require
racket/file
pkg/lib)
(define (barchart-template)
(define template.svg (build-path (pkg-directory "ProjectName")
"template/barchart.svg"))
(file->string template.svg))

How can I use an older version of package gregor?

Here's how to simulate it.
$ cat t1.rkt
#lang racket/base
(require gregor)
(display "hello")
I'm running Racket 6.12. But the same happens to Racket 7.2.
$ racket t1.rkt
explode-path: contract violation
expected: (or/c path-for-some-system? path-string?)
given: #f
context...:
/usr/share/racket/collects/racket/path.rkt:116:0: do-explode-path
/usr/share/racket/collects/racket/path.rkt:126:0: find-relative-path7
/home/me/.racket/6.12/pkgs/tzinfo/tzinfo/private/zoneinfo.rkt:118:2: for-loop
/home/me/.racket/6.12/pkgs/tzinfo/tzinfo/private/zoneinfo.rkt:108:0: read-tzids
/home/me/.racket/6.12/pkgs/tzinfo/tzinfo/private/zoneinfo.rkt:71:0: make-zoneinfo-source
/usr/share/racket/collects/racket/contract/private/arrow-val-first.rkt:388:18
/home/me/.racket/6.12/pkgs/tzinfo/tzinfo/main.rkt:63:0: system-tzid
/usr/share/racket/collects/racket/contract/private/arrow-val-first.rkt:388:18
/home/me/.racket/6.12/pkgs/gregor-lib/gregor/private/moment.rkt: [running body]
/home/me/.racket/6.12/pkgs/gregor-lib/gregor/private/generics.rkt: [traversing imports]
/home/me/.racket/6.12/pkgs/gregor-lib/gregor/private/clock.rkt: [traversing imports]
/home/me/.racket/6.12/pkgs/gregor-lib/gregor/main.rkt: [traversing imports]
/home/me/issue-gregor/t1.rkt: [traversing imports]
$ racket --version
Welcome to Racket v6.12.
How could I go back to an older version of gregor? I installed it this one with raco pkg install gregor and installed all its dependencies.
I'm the author of Gregor. (I don't normally post on Stack Overflow, or even use it much, but John Clements brought this to my attention.)
There's a bit of an unfortunate naming issue here, since tzdata appears to be the name of an Ubuntu package that provides the normal zoneinfo files, as well as being the name of a Racket package that also provides those files.
gregor depends on a package called tzinfo. tzinfo, in turn, conditionally depends on tzdata (the Racket one, not the Ubuntu one). Specifically, it only depends on tzdata on Windows systems. This is because I assumed that all Unix systems would have the zoneinfo files. (It never occurred to be that anyone would run a Unix without them these days.) But it is certainly the case that tzinfo (and thus gregor) will not work unless it can find zoneinfo files.
Maybe I should update the documentation with a conspicuous warning. I'd rather not make tzinfo unconditionally depend on tzdata (again, the Racket one), because most Unix systems will already have the necessary files, and it could be unduly confusing for gregor to use a version of them different from the one the system is using.

How to install a package with quicklisp

I tried to install Lisplab with asdf and quicklisp but they all turned out to fail.
I use sbcl and slime.
Anyone can help me with installation. And I just want to manipulate matrix within lisp:)
Thanks, lisper!
The first thing to do about installing a lisp library using quicklisp, is see if it is available via quicklisp:
(Note for this answer I'm using the configuration roswell slime sbcl on antergos)
CL-USER> (ql:system-apropos "lisplab")
; No value
In this case the project it is not included, you can update your quicklisp, but in this case it is not necessary. this project is not in quicklisp and maybe will not be in the future. then you can choose to continue installing it or search for an atertnative for this thake a look a quickdocs this is a search about math
Let's try to install this quicklisp says this:
Can I load a local project that isn't part of Quicklisp? Yes. The
easiest way is to put the project's directory in Quicklisp's
local-projects directory. For example:
$ cd ~/quicklisp/local-projects/
$ git clone git://github.com/xach/format-time.git
The project will then be loadable via (ql:quickload "format-time")
Also, any system file that can be found via ASDF's source registry
system can be loaded with ql:quickload.
For example, if you have a system file my-project.asd in
/projects/my-project/, you can do something like this:
(push #p"/projects/my-project/" asdf:*central-registry*)
(ql:quickload "my-project")
If my-project depends on systems that are available via Quicklisp that
are not already installed, they will be automatically installed.
so for this project I will download the tarball and extract or download the repository in the local-projects folder, like it is suggested in a comment. In my case is ./roswell/local-projects but in your case should be cd ~/quicklisp/local-projects/
After that you "can" load with quicklisp, but I believe that since this library is not maintained, it will have errors,
If you want to manipulate matrix with lisp I recommend you to use lisp-matrix be sure to have installed lapack in your computer and read the documentaaion carefully especcilay the code at the end of the readme and also the tests.
CL-USER> (ql:quickload :lisp-matrix)
To load "lisp-matrix":
Load 1 ASDF system:
lisp-matrix
; Loading "lisp-matrix"
(:LISP-MATRIX)
CL-USER> (in-package :lisp-matrix-user)
#<PACKAGE "LISP-MATRIX-USER">
LISP-MATRIX-USER> (M* (ones 2 2 :implementation :lisp-array)
(ones 2 2 :implementation :lisp-array))
#<LA-SIMPLE-MATRIX-DOUBLE 2 x 2
2.0d0 2.0d0
2.0d0 2.0d0>
(be aware that foreign-array doesn't work for integers)

Cannot open module file: net/sendmail

I'm trying to compile this simple racket sendmail code:
#lang racket
(require net/sendmail)
(send-mail-message
"sender#somewhere.com" "Some Subject"
'("recipient#elsewhere.com" "recipient2#elsewhere.com")
'("cc#elsewhere.com")
'("bcc#elsewhere.com")
(list "Some lines of text" "go here."))
But when I compile:
racket email.rkt
I get this error:
cannot open module file
module path: net/sendmail
I thought the sendmail library was builtin? What am I doing wrong?
Perhaps you installed "minimal racket", rather than the full "racket" package. This library is part of the "net-lib" package.
To see what packages you have installed, run raco pkg show -a.
Here's what I get:
hardy:lements> raco pkg show -a | grep net-lib
net-lib* 053ca45b223c5... clone...=net-lib
planet-lib* 0110246c9c547... catalog...et-lib
EDIT: if it turns out you don't have net-lib installed, you probably want to install the net package, per Alexis King's excellent suggestion below:
hardy:lements> raco pkg install net