libera/#commonlisp - IRC Chatlog
Search
0:31:31
hayley
With regards to masinter saying "CDR-coding was for when RAM was expensive", cache misses are also expensive.
9:40:54
McParen
hello, i'm looking for a way to destructuring-bind a string, does somebody know if there is known library for that? essentially I want to bind (a b &rest c) to "foo bar baz qux", to get a "foo" b "bar" and c "baz qux".
9:48:51
_death
the analogy doesn't quite hold up, and there are various implicit choices so it's doubtful that there's a library that does just that
9:52:14
McParen
I think it will be some combination of split-sequence and subseq, or cl-ppcre, but it is always better to check if there is a common solution to that.
10:04:17
McParen
I'd like to (re)use the lambda list parsing of destructuring-bind, including the &rest, &optional keywords and such.
10:07:45
McParen
what I essentially want is to pars user input (read as a single string), to be able to have a command, some parameters in between and then the free content at the end of the string.
10:07:54
_death
well, when I read "destructuring-bind a string" I imagined something like (destructuring-bind (a b &rest c) (coerce string 'list) (setf c (coerce c 'string)) body) but you're looking for something more elaborate with regards to atoms or tokens
10:09:19
McParen
I dont theink it is more elaborate, when i write it it looks kinda simple: (destructuring-bind-string (a b &rest c) "foo bar baz qux" (list a b c)) => ("foo" "bar" "baz qux")
10:11:58
_death
that's one way.. it could be something that expands to (destructuring-bind (a b c) (coerce (nth-value 1 (ppcre:scan-to-strings "([^ ]*) ([^ ]*) (.*)" "foo bar baz qux")) 'list) (list a b c)) .. of course you need to define &optional semantics (and &key? what would that mean..)
10:12:31
pjb
McParen: you can also read a string. (read-from-string (concatenate 'string "(" "foo bar baz qux" ")")) #| --> (foo bar baz qux) ; 18 |#
10:13:24
pjb
McParen: but reading opens a whole another can of worms. Such as syntax error, or upcasing the symbol names.
10:13:59
McParen
pjb: reading the string is not what I tried to do, because that would parse the user input I want to keep unchanged (including spaces, etc).
10:17:11
McParen
i guess that is what i will have to do, but since i do not know ppcre well, i was trying to avoid dealing with regexps...
10:19:31
_death
another thing is that d-bind can be deeper, so (destructuring-string-bind ((a b) c) "\"foo bar\" zot" (list a b c)) => ("foo" "bar" "zot") ?
11:18:39
pjb
McParen: then you may parse yourself. eg. (destructuring-bind (a b c) (split-sequence:split-sequence #\space "foo bar baz") (list a b c)) #| --> ("foo" "bar" "baz") |#
11:37:06
McParen
pjb, I've come that far already, what i was looking for was: (destructuring-bind (a b &rest c) (split-sequence:split-sequence #\space "foo bar baz qux") (list a b c)) #| --> ("foo" "bar" "baz qux")