Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > pt.comp.programacao > #185

Re: sobre common lisp e o sistema de arquivos

From Patricia Ferreira <pferreira@example.com>
Newsgroups pt.comp.programacao
Subject Re: sobre common lisp e o sistema de arquivos
Date 2024-01-22 16:14 -0300
Organization A noiseless patient Spider
Message-ID <878r4h9o4m.fsf@example.com> (permalink)
References <87v87la7zs.fsf@example.com>

Show all headers | View raw


Patricia Ferreira <pferreira@example.com> writes:

> Tenho lido vários pedaços de documentação Common Lisp por aí, livros
> incluindo.  Antes de falar com o sistema de arquivos, vale a pena ler o
> capítulo 14 de Peter Seibel ``Practical Common Lisp''.
>
>   Files and File I/O
>   https://gigamonkeys.com/book/files-and-file-io.html
>
>   ``When pathnames were designed, the set of file systems in general use
>   was quite a bit more variegated than those in common use today.
>   Consequently, some nooks and crannies of the pathname abstraction make
>   little sense if all you're concerned about is representing Unix or
>   Windows filenames.''

Eis o tipo de armadilha contras as quais estamos.

--8<---------------cut here---------------start------------->8---
NNTPD> (rename-file (make-pathname :name "1" :type "tmp") (make-pathname :name "2" :type "txt"))
Failed to find the TRUENAME of "c:\\[...]\\quicklisp\\local-projects\\nntp\\groups\\1.tmp":
--8<---------------cut here---------------end--------------->8---

Lol.  Não consigo nem renomear um arquivo.

--8<---------------cut here---------------start------------->8---
NNTPD> *default-pathname-defaults*
#P"c:/[...]/quicklisp/local-projects/nntp/groups/local.test"

NNTPD> (sb-posix:getcwd)
"c:\\[...]\\quicklisp\\local-projects\\nntp\\groups\\local.test"
--8<---------------cut here---------------end--------------->8---

Em outras palavras---rename-file deveria operar nesse diretório aí e não
em groups/.  O que poderia estar errado?  Veja que sei o que estou
fazendo---sei renomear um arquivo e tenho curso *superior* e tal.

--8<---------------cut here---------------start------------->8---
* *default-pathname-defaults*
#P"c:/sys/emacs/usr/quicklisp/local-projects/nntp/groups/local.test/"
* (rename-file "1.tmp" "1.txt")
#P"c:/[...]/quicklisp/local-projects/nntp/groups/local.test/1.txt"
#P"c:/[...]/quicklisp/local-projects/nntp/groups/local.test/1.tmp"
#P"c:/[...]/quicklisp/local-projects/nntp/groups/local.test/1.txt"
--8<---------------cut here---------------end--------------->8---

Isso prova.

Onde está o problema?  O problema está no fato de que aí na segunda
tentativa, o diretório termina com uma barra.  No primeiro caso, onde a
falha ocorre, não há uma barra.  Common Lisp assume que aquilo então é
um arquivo e não um diretório.  ``Ele'' então pega o diretório daquele
arquivo, que é groups/.  

Peter Seibel me avisou disso, mas iniciantes são assim.  Como disse a
USENET uma vez---even if you dip a user in an ocean of clues, it will
comes out clueless.  Lol.

--8<---------------cut here---------------start------------->8---
    When dealing with pathnames that name directories, you need to be
    aware of one wrinkle. Pathnames separate the directory and name
    components, but Unix and Windows consider directories just another
    kind of file. Thus, on those systems, every directory has two
    different pathname representations.

    One representation, which I'll call file form, treats a directory
    like any other file and puts the last element of the namestring into
    the name and type components. The other representation, directory
    form, places all the elements of the name in the directory
    component, leaving the name and type components NIL.

    When you create pathnames with MAKE-PATHNAME, you can control which
    form you get, but you need to be careful when dealing with
    namestrings. All current implementations create file form pathnames
    unless the namestring ends with a path separator. But you can't rely
    on user-supplied namestrings necessarily being in one form or
    another. For instance, suppose you've prompted the user for a
    directory to save a file in and they entered "/home/peter". If you
    pass that value as the :defaults argument of MAKE-PATHNAME like
    this:

    (make-pathname :name "foo" :type "txt" :defaults user-supplied-name)

    you'll end up saving the file in /home/foo.txt rather than the
    intended /home/peter/foo.txt because the "peter" in the namestring
    will be placed in the name component when user-supplied-name is
    converted to a pathname. -- Peter Seibel, capítulo 14.
--8<---------------cut here---------------end--------------->8---

Back to pt.comp.programacao | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

sobre common lisp e o sistema de arquivos Patricia Ferreira <pferreira@example.com> - 2024-01-22 09:05 -0300
  Re: sobre common lisp e o sistema de arquivos Patricia Ferreira <pferreira@example.com> - 2024-01-22 16:14 -0300
    Re: sobre common lisp e o sistema de arquivos Patricia Ferreira <pferreira@example.com> - 2024-01-23 14:30 -0300
      Re: sobre common lisp e o sistema de arquivos Patricia Ferreira <pferreira@example.com> - 2024-01-23 15:42 -0300
        Re: sobre common lisp e o sistema de arquivos Daniel Cerqueira <dan.list@brilhante.top> - 2024-01-24 14:02 +0000
          Re: sobre common lisp e o sistema de arquivos Patricia Ferreira <pferreira@example.com> - 2024-01-24 14:52 -0300
    Re: sobre common lisp e o sistema de arquivos Patricia Ferreira <pferreira@example.com> - 2024-01-25 01:01 -0300
      Re: sobre common lisp e o sistema de arquivos Daniel Cerqueira <dan.list@brilhante.top> - 2024-01-27 12:05 +0000
        Re: sobre common lisp e o sistema de arquivos Patricia Ferreira <pferreira@example.com> - 2024-01-27 14:21 -0300
          Re: sobre common lisp e o sistema de arquivos Daniel Cerqueira <dan.list@brilhante.top> - 2024-01-27 19:03 +0000

csiph-web