Вопрос

I'm attempting to save the output of (ql:system-apropos "regex") to a variable by using multiple-value-bind, but I only the nil. However, it seems that this command only prints text to REPL and does not return any variables, so doesn't seem to work. In that case, is there any way to get the output of ql:system-apropos as a list or as an array, especially the package names returned by it.

This basic multiple-value-bind code works:

* (multiple-value-bind (first-var second-var) (floor 5 3) (defparameter *first-var* first-var) (defparameter *second-var* second-var))

*SECOND-VAR*
* *first-var*

1
* *second-var*

2
*

But this does not (if there is nothing to bind for multiple-value-bind ?) :

* (multiple-value-bind (first-var second-var) (ql:system-apropos "regex") (defparameter *first-var* first-var) (defparameter *second-var* second-var))
#<SYSTEM com.informatimago.common-lisp.regexp / com.informatimago-20120407-git / quicklisp 2012-04-07>
#<SYSTEM lispbuilder-regex / lispbuilder-20110619-svn / quicklisp 2012-04-07>
#<SYSTEM recursive-regex / recursive-regex-20120407-git / quicklisp 2012-04-07>
#<SYSTEM recursive-regex-test / recursive-regex-20120407-git / quicklisp 2012-04-07>
#<SYSTEM regex / regex-1 / quicklisp 2012-04-07>
*SECOND-VAR*
* *first-var*

NIL
* *second-var*

NIL
*

So it seems that ql:system-apropos only prints text on screen by using format or some other printing command?

The purpose of this would be to extract the package names of output by using some string handling commands (probably some regex) and automate the installing or re-installing of all packages returned by ql:system-apropos, for example:

(defparameter *package-name-string* "lispbuilder")
(multiple-value-bind (lispbuilder-packages-list) (ql:system-apropos *package-name-string*) (defparameter *lispbuilder-packages-list* lispbuilder-packages-list))

Any other way to get quicklisp package names using partial names or some regex as input would also be a working solution (even getting the current complete list of packages would be useful). Is there any viable solution to do this?

Это было полезно?

Решение

Your interaction with Common Lisp looks much too complicated.

You ask: storing the package names returned by ql:system-apropos into a variable.

Does it actually return anything? Or does it only print something?

You can easily find out. I'm using in my example CL:APROPOS:

CL-USER 141 > (apropos "plist" "CL")
SYMBOL-PLIST (defined)
MAPLIST (defined)

Just describe the return value:

CL-USER 142 > (describe (apropos "plist" "CL"))
SYMBOL-PLIST (defined)
MAPLIST (defined)
NIL is a NULL
NAME          "NIL"
VALUE         NIL
FUNCTION      #<unbound function>
PLIST         (TYPE::DIRECT-TYPE-PREDICATE TYPE::RETURN-FALSE)
PACKAGE       #<The COMMON-LISP package, 2/4 internal, 978/1024 external>

There is nothing. APROPOS just prints something.

Common Lisp uses output streams. Just rebind the variable which holds the output stream:

CL-USER 143 > (with-output-to-string (*standard-output*)
                (apropos "plist" "CL"))
"SYMBOL-PLIST (defined)
MAPLIST (defined)"

Now you got a string, which you can parse.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top