shr*_*dur 7 lisp common-lisp multiple-value
我想从字符串中得到三个数字
(parse-integer "12 3 6" :start 0 :junk-allowed t)
12 ;
2
Run Code Online (Sandbox Code Playgroud)
现在这2也会返回,这是可以解析的数字.所以我现在可以给
(parse-integer "12 3 6" :start 2 :junk-allowed t)
3 ;
4
Run Code Online (Sandbox Code Playgroud)
但我怎么保存的价值2和4它返回.如果我setq是到一个变量只12和3存储?
sds*_*sds 11
请在这里阅读"理论" .
简单地说,你可以绑定多个值有multiple-value-bind:
(multiple-value-bind (val pos) (parse-integer "12 3 6" :start 0 :junk-allowed t)
(list val pos))
==> (12 2)
Run Code Online (Sandbox Code Playgroud)
(setf (values val pos) (parse-integer "12 3 6" :start 0 :junk-allowed t))
val ==> 12
pos ==> 2
Run Code Online (Sandbox Code Playgroud)
PS.在您的特定情况下,您可能会这样做
(read-from-string (concatenate 'string
"("
"12 3 6"
")"))
Run Code Online (Sandbox Code Playgroud)
并获取列表(12 3 6).这不是最有效的方法(因为它分配了不必要的内存).
PPS参见: