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

Add namespaces to lisp #511

Merged
merged 14 commits into from
Jul 2, 2023
Merged

Add namespaces to lisp #511

merged 14 commits into from
Jul 2, 2023

Conversation

vinc
Copy link
Owner

@vinc vinc commented Jun 29, 2023

This PR introduces a lower level file namespace to the lisp allowing reading (file:read) and writing (file:write) directly from a file handle to have a better print function so the output of a script can now be redirected to a file from the shell for example.

This wasn't possible before:

lisp /tmp/lisp/pi.lsp 100 => pi.txt

The new notation using a dot . to group functions within a namespace will also be used for number, string, and regex with number.type, string.trim, and regex.match? for example.

@vinc
Copy link
Owner Author

vinc commented Jun 29, 2023

New escaped tab \t and carriage return \r with the existing newline \n:

> (print "Hello,\tWorld!")
Hello,	World!
()

> (print "Hello,\rWorld!")
World!
()

> (print "Hello,\nWorld!")
Hello,
World!
()

@vinc vinc changed the title Add modules to lisp Add namespaces to lisp Jun 30, 2023
@vinc
Copy link
Owner Author

vinc commented Jun 30, 2023

> (mod -1 3)
2

> (rem -1 3)
-1

> (% -1 3)
-1

@vinc
Copy link
Owner Author

vinc commented Jun 30, 2023

There are a few options for the namespace separator:

  1. file::open
  2. file:open
  3. file.open
  4. file/open

The first option :: is very common but so far I was thinking about using the second one : that is shorter. Both could be slightly confusing if I introduce keywords starting with a colon like :foo though.

A slash / would borrow the directory metaphor but might be confusing if the language is used as a shell whereas a dot . would work like it does for hostnames and filenames, for example: http.get "example.com/foo.txt".

@vinc
Copy link
Owner Author

vinc commented Jul 1, 2023

If the language is used as a shell it might be interesting to rename read-file, write-file, and append-file to read, write, and append but the latter already exists.

@vinc vinc marked this pull request as ready for review July 2, 2023 07:20
@vinc vinc merged commit f806c3a into trunk Jul 2, 2023
@vinc vinc deleted the feature/lisp-refactor branch July 2, 2023 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant