Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: File Library for Coalton #1085

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Draft: File Library for Coalton #1085

wants to merge 1 commit into from

Conversation

Izaakwltn
Copy link
Collaborator

First draft of an IO library for Coalton. This allows for directory navigation, environmental/system information gathering, and simple file-reading.

  • This mostly repurposes UIOP and ASDF functions, with an intent to make things simple/streamlined without as much unfettered, lispy freedom. I'm focusing on what most users will need for most use-cases, as fringe edge cases can be hand-rolled with lisp.

  • The current working directory can be accessed with (cwd) and set with (chdir dir), with most file functions automatically operating in the context of the working directory. Note: This distinction is important because UIOP allows you to set the current working directory, but the default directory for operations is still the home directory.

Next steps, open thoughts:

  • I'm planning on approaching streams next, either built on top of CL streams or a new type with File and Buffer constructors.
  • File reading and writing, opening and closing streams, which I'm hoping to make straightforward at the expense of creativity.
  • Decide on a filepath system, though it should ideally just be strings on the user end.
  • It might be useful to set the current-working-directory, or at least a current-system-directory when loading a coalton project.asd or package.lisp.
  • I think file searching/managing might be friendliest with some sort of regex/string-matching library. Once such a library exists, I think a lot of the uiop stuff could be supplanted.

@Izaakwltn Izaakwltn force-pushed the io-library branch 2 times, most recently from 1fd1c2a to e43ce47 Compare April 5, 2024 23:25
Copy link
Collaborator

@eliaslfox eliaslfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take a more thorough look sometime this week

library/io.lisp Outdated Show resolved Hide resolved
@Izaakwltn Izaakwltn force-pushed the io-library branch 3 times, most recently from 29aa228 to 70eb2bf Compare April 16, 2024 05:51
@Izaakwltn
Copy link
Collaborator Author

@eliaslfox I think this is at a point that it could be reviewed.

Summary:

  1. system.lisp includes a variety of system/environmental variables, mostly gathered through uiop. (I think I'll probably drop the which- prefix)
  2. file.lisp contains most of the standard directory and file functions. They mostly follow common lisp naming and organization conventions, though also tend to be simplified.
  3. current-working-directory.lisp provides an interface for using do notation to work within a given directory (or to navigate in general). Most of the naming is tailored after shell commands. This should probably be renamed something like shell-nav or nav or be merged into file.lisp.

@Izaakwltn Izaakwltn changed the title Draft: IO Library for Coalton Draft: File Library for Coalton Apr 16, 2024
Copy link
Collaborator

@eliaslfox eliaslfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to finish the review

library/file.lisp Outdated Show resolved Hide resolved
library/system.lisp Outdated Show resolved Hide resolved
library/file.lisp Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
@Izaakwltn Izaakwltn force-pushed the io-library branch 3 times, most recently from 7df1a1b to d5a657a Compare May 3, 2024 00:02
@Izaakwltn
Copy link
Collaborator Author

Latest edit:

  • Most major file functions are implemented.
  • Result error handling across file operations. The constructors for FileError are not finalized yet.
  • Signal type class with methods error and warn. There is an instance for String so no existing code using error breaks, but it allows specialized error/warning formatting for specific error types, like this PR's FileError.
  • Parameterized FileStream type avoids unsafe/unnecessary stream options for incompatible stream types.

library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
Copy link
Collaborator

@eliaslfox eliaslfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some notes

@Izaakwltn
Copy link
Collaborator Author

(probably) dependent on #1101 and #1102.

@Izaakwltn
Copy link
Collaborator Author

The only files that are really exclusive to this PR are library/file.lisp and library/system.lisp and typical package updates.

The other edits have to do with #1101 and #1102 which will go away if those are merged or shot down.

Copy link
Collaborator

@eliaslfox eliaslfox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another pass. this is looking good

library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
library/file.lisp Show resolved Hide resolved
library/file.lisp Outdated Show resolved Hide resolved
@Izaakwltn Izaakwltn force-pushed the io-library branch 10 times, most recently from 6552cc3 to 75fbdce Compare May 9, 2024 17:59
@Izaakwltn
Copy link
Collaborator Author

All prerequisite merge requests have been assimilated, tests added. Ready for near-final review

library/file.lisp Show resolved Hide resolved
library/file.lisp Show resolved Hide resolved
library/file.lisp Show resolved Hide resolved
library/file.lisp Show resolved Hide resolved
(cl:format cl:nil "Captured Lisp Error:~%~%~a" c))))
((EOF)
(error (lisp String ()
(cl:format cl:nil "Error:~%~%End of File"))))))))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(error #.(cl:format cl:nil "...")) you can format at read time

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that that syntax would work instead of the whole lisp-coalton-bridge?


(coalton-toplevel

(declare append-file ((Into :p Pathname) (Streamable :a) => :p -> (iter:Iterator :a) -> (Result FileError Unit)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

append-to-file

(fn (stream)
(write-sequence stream data))))

(declare supersede-file ((Into :p Pathname) (Streamable :a) => :p -> (iter:Iterator :a) -> (Result FileError Unit)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write-to-file

(fn (stream)
(write-sequence stream data))))

(declare read-file-string ((Into :a Pathname) => :a -> (Result FileError String)))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read-file-to-string

@@ -222,6 +222,16 @@
(:export
#:Iterator)

(:import-from
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't put file stuff in the prelude.

@@ -6,7 +6,25 @@
(:export
#:gc
#:time
#:sleep))
#:sleep)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the system changes go in another pr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants