Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

common lisp equivalent of a python idiom

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?

like image 502
saq7 Avatar asked Dec 08 '25 14:12

saq7


1 Answers

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"))
like image 143
coredump Avatar answered Dec 10 '25 05:12

coredump



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!