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.
15:16:16
phoe
GETF might want to modify a lexical variable. A function is unable to do that; a macro is needed.
15:16:49
phoe
(let ((x 2)) (mutate x) ...) ; in here, MUTATE must be a macro, since a function is unable to affect the binding of lexivar X.
15:17:43
didi
phoe: Ah, interesting. I guess it doesn't affect me in my use case, but I didn't think of that.
15:23:10
jmercouris
pjb: I just want to push their contents to a file as my program is running when launched via spotlight so I can have some hope of discerning *why* it crashed
15:23:10
minion
jmercouris, memo from pjb: stdout/stderr are directed to the same file descriptor as the parent process. So, what does the parent process do to them? (It may redirect them to /dev/null). Inside the child, you can reopen or dup them. What do you want to do?
15:23:39
jmercouris
pjb: because (as I'm sure you know) when you launch via spotlight there is not an easy way to gather stdout of a running program
15:24:30
phoe
didi: if that's the case, then everything's good. DEFUN SETF is going to work well if you do not mutate the binding itself, but e.g. mutate some slots in an instance, or the contents of some cons cell.
15:26:51
pjb
jmercouris: the program itself can reopen its stdout and stderr to a file if that's what you want.