This is the prompt-for Reference Manual, version 3.1.0, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 07:21:03 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
prompt-for
Type safe user input.
SATO Shinichi
(GIT git@github.com:hyotang666/prompt-for)
MIT
# PROMPT-FOR 2.0.0
## What is this?
Type safe user input.
## Alternatives and differences.
| | [duologue] | prompt-for |
| — | ———- | ———- |
| coloring | \* | |
| completion | \* | |
| choosing | \* | |
| email | \* | |
| url | \* | |
| datetime | \* | |
| secret | | sbcl with unix os only |
| types | integer pathname | any-lisp-types |
| interact | standard-io | query-io |
### See also.
* [query-repl]
* [text-query]
## Usage
“‘lisp
* (prompt-for:prompt-for ’integer "~&Input integer> ")
Input integer> not-integer
NOT-INTEGER is type of SYMBOL, not INTEGER
Input integer> 0
0
“‘
For detail, see [spec file.](spec/prompt-for.lisp)
### TIPS
PROMPT-FOR is a generic function.
If the first argument is a function, it checks user input with it.
“‘lisp
* (prompt-for:prompt-for #’evenp "~&Input even integer>> ")
Input even integer>> 1
1 is type of BIT, not satisfies #<FUNCTION EVENP>.
Input even integer>> 2
2
“‘
Note that the lambda function will be useless as a message for users when failed.
“‘lisp
* (prompt-for:prompt-for (lambda (x) (evenp x)) "~&Input even integer>> ")
Input even integer>> 1
1 is type of BIT, not satisfies #<FUNCTION (LAMBDA (X)) {...}>.
“‘
In such a case, the local function may help you.
“‘lisp
* (flet ((my-evenp (x) (evenp x)))
(prompt-for:prompt-for #’my-evenp "~&Input even integer>> "))
Input even integer>> 1
1 is type of BIT, not satisfies #<FUNCTION (FLET MY-EVENP) {...}>.
“‘
Note that these examples are in SBCL.
Other implementations may prints function in other ways.
If you want maximum portability, or customize the message,
you need to use the intermediate object and override method.
“‘lisp
(defstruct fun sym)
(defmethod prompt-for:prompt-for ((f fun) &rest args)
(loop :for input = (progn (apply #’uiop:format! *query-io* args)
(read *query-io*))
:when (funcall (fun-sym f) input)
:return input
:else :do (format *query-io* "~&WTF dude! It does not satisfy ~S!" (fun-sym f))))
* (prompt-for:prompt-for (make-fun :sym ’evenp) "~&Input even integer>> ")
Input even integer>> 1
WTF dude! It does not satisfy EVENP!
Input even integer>>
“‘
### TIPS
‘prompt-for‘ returns user input.
“‘lisp
* (prompt-for:prompt-for #’find-class "~&Input class name >> ")
Input class name >> stream
STREAM
“‘
If you want e.g. stream object rather than a name even if user input is a class name, you can use ‘prompt-for:*default-reader*‘.
“‘lisp
* (let ((prompt-for:*default-reader*
(lambda (input) (find-class (read input)))))
(prompt-for:prompt-for t "~&Input class name >> "))
Input class name >> stream
#<SB-PCL:SYSTEM-CLASS COMMON-LISP:STREAM>
“‘
## From developer
### Product’s goal
Already?
### License
MIT
### Tested with
* SBCL/2.2.4
* CCL/1.12
* CLISP/2.49
* ECL/21.2.1
* Allegro/10.1
* CMUCL/21D
* ABCL/1.9.0
<!– Links –>
[query-repl]:https://github.com/hyotang666/query-repl
[text-query]:https://www.cliki.net/text-query
[duologue]:https://github.com/mmontone/duologue/
3.1.0
sb-posix
(system)., required, for feature :sbcl
uiop
(system).
prompt-for.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
prompt-for/prompt-for.lisp
prompt-for
(system).
*default-reader*
(special variable).
do-with-prompt-input
(macro).
prompt-for
(generic function).
deprecated
(condition).
echo-off
(function).
echo-on
(function).
key
(reader method).
retrieve-keyword-arg
(function).
secret-reader
(function).
Packages are listed by definition order.
prompt-for
common-lisp
.
*default-reader*
(special variable).
do-with-prompt-input
(macro).
prompt-for
(generic function).
deprecated
(condition).
echo-off
(function).
echo-on
(function).
key
(generic reader).
retrieve-keyword-arg
(function).
secret-reader
(function).
Definitions are sorted by export status, category, package, and then by lexicographic order.
(DO-WITH-PROMPT-INPUT ((out { format-args }*) (var reader)) { body }*)
out := SYMBOL which will be bound by the output stream.
format-args := An expression to generate a list of format control and its arguments for prompt.
var := SYMBOL which will be bound by the return value of the READER.
reader := An expression to generate (FUNCTION (STREAM) T) to read user input.
body := implicit progn.
Achieving the context to handle any errors, especially about user input,
evaluate the body form iteratively until CL:RETURN is successfully called.
(eql :secret)
) &rest args) ¶Get user input string silently.
function
) &rest args) ¶Ensure user input satisfies PRED.
list
) &rest args) ¶Ensure user input is type of TARGET.
symbol
) &rest args) ¶Ensure user input is type of TARGET.
Return two values.
1. The value of the KEY in ARGS if exists, otherwise DEFAULT.
2. ARGS which is lacking the KEY value pair.
NOTE: Only check last two conses. Any KEY in front of it is ignored.
e.g. (retrieve-keyword-arg :by ’(:by 1 :by 2 :by 3)) => 3, (:by 1 :by 2)
deprecated
)) ¶key
.
Jump to: | D E F G K M P R S |
---|
Jump to: | D E F G K M P R S |
---|
Jump to: | *
K S |
---|
Index Entry | Section | ||
---|---|---|---|
| |||
* | |||
*default-reader* : | Public special variables | ||
| |||
K | |||
key : | Private conditions | ||
| |||
S | |||
Slot, key : | Private conditions | ||
Special Variable, *default-reader* : | Public special variables | ||
|
Jump to: | *
K S |
---|
Jump to: | C D F P S |
---|
Jump to: | C D F P S |
---|