freenode/#lisp - IRC Chatlog
Search
11:05:09
splittist
Given the string "/foo/bar/../baz/quux.lisp" I would like to obtain "/foo/baz/quux.lisp", and the obvious generalizations of this scheme. Because the string looks like a pathname I have been looking at various path-related things, but nothing and nobody seems to want to give me what I want. Am I just thinking about this wrong?
11:15:01
splittist
Except that I'm on SBCL (or CCL), and "NB: Since this function does not access the filesystem it will only remove :BACK elements from the path (not :UP elements). Since some lisps, ccl/sbcl/clisp convert ".." in pathnames to :UP, and not :BACK, the actual utility of the function is limited."
11:18:21
splittist
I'll implement it myself. (It is verging on the Left_Pad level of functionality...)
11:26:33
Colleen
splittist: Function pathname-utils:normalize-pathname https://shinmera.github.io/pathname-utils#FUNCTION%20PATHNAME-UTILS%3ANORMALIZE-PATHNAME
11:28:41
Shinmera
that library has been tested on a few implementations at least so I know the stuff is as correct as can be :)
11:37:30
Shinmera
one of the problems is that it can't convert :up, since :up's semantics can differ in the presence of symlinks
11:39:07
splittist
Sure. But since my strings aren't actually pathnames on an OS with symlinks I can treat '..' as :back. (Option would be good (: )
11:41:09
splittist
Odin- and phoe: Yes! I had actually looked at it a while ago but didn't think it would work on the basis of the description of dotdot. 0 for reading comprehension.
13:20:53
didi
What do I use to write a SETF variable that accepts a default value like `getf'? For example, (incf (getf foo :bar 0)) works even if FOO doesn't have the indicator :BAR.
13:35:36
phoe
for GETF, though, you might want to write a more elaborate SETF expansion. There is no #'(SETF GETF), for instance.
14:51:42
_death
didi: actually setf function would not work.. you'll need to use another mechanism (for example defmacro and get-setf-expansion) because FOO may be NIL and GETF will need to modify the binding in that case
14:57:15
didi
_death: I'm using a combination of `defsetf' and `defmethod'. Something like (defsetf getf (place indicator &optional default) (new-value) `(set-getf place indicator value &optional default)), and `set-getf' is a generic function so I can use different classes of PLACE.