How do I run an equivalent of this Python command in Lisp
from lib import func
For example, I want to use the split-sequence package, and in particular I only want the split-sequence method from that package.
Currently, I have to use it as (split-sequence:split-sequence #\Space "this is a string").
But I what I want to do is (split-sequence #\Space "this is a string").
How do I get access to the function directly without qualifying it with the package name?
What you want to do is simply:
(import 'split-sequence:split-sequence)
This works fine in a REPL, but if you want to organize your symbols, you'd better rely on packages.
(defpackage #:my-package
(:use #:cl)
(:import-from #:split-sequence
#:split-sequence))
The first ̀split-sequence is the package, followed by all the symbols that should be imported. In DEFPACKAGE forms, people generally use either keywords or uninterned symbols like above in order to avoid interning symbols in the current package. Alternatively, you could use strings, because only the names of symbols are important:
(defpackage "MY-PACKAGE"
(:use "CL")
(:import-from "SPLIT-SEQUENCE" "SPLIT-SEQUENCE"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With