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

with_ better names #1149

Open
axch opened this issue Nov 7, 2022 · 0 comments
Open

with_ better names #1149

axch opened this issue Nov 7, 2022 · 0 comments
Labels
libraries Libraries written in Dex

Comments

@axch
Copy link
Collaborator

axch commented Nov 7, 2022

The <- binding syntax introduced by PR #1147 makes with_ names less nice. While

with_state init \x.
  ...

read reasonably ok, the new style

x <- with_state init
...

reads pretty poorly.

The fundamental reason for this is that when the continuation is indented and the function is first, it's fairly clear that the name refers to what it does to the continuation as a whole; whereas when the continuation is not indented and the binder is first, there is a pretty strong message that the function's name is about the kind of object it produces, and its effect on the continuation isn't very important --- fades into the background, takes care of itself.

Therefore, I think it's worth thinking about new names for those functions. Particularly the ones whose names currently start with with_ all have the flavor of introducing some resource, and maybe some type-level restrictions on how that resource is to be used, and then cleaning the resource up when the block ends. This means they will probably be used predominantly with the <- syntax. Here are all the with_ functions in the current Dex corpus:

  • with_state
  • with_reader
  • with_dynamic_buffer
  • with_alloc
  • with_file
  • with_temp_file
  • with_temp_files
  • with_c_string
  • with_table_ptr

The name of with_state I currently dislike pretty substantially, because it names the (ahem) effect it has on the continuation rather than the resource it provides. It's also used a great deal, so its name matters to the feel of the language. (Aside: It also annoys me that the binder is almost everywhere named ref instead of being named after its contents, but I can fix that along the way.) How about these other names for with_state:

  • var
  • variable
  • reference
  • new_reference
  • new_variable
  • new
  • box

Thoughts? The only down-side I can see is obscuring the relationship between with_state and its cousins yield_state and run_state. But run_state is almost completely unused in the corpus (except to implement with_state and yield_state), so we can call it anything we want, and we could reconsider the name yield_state as well.

I dislike with_reader for the same reason as with_state but it doesn't matter because it's unused.

The others are all of the same flavor: they provide some resource in the IO effect, and then clean it up when the continuation ends, returning the value of the continuation unchanged. Ergo, they will likely be used exclusively with <- syntax, so should read well in it. We could reasonably

  • Just remove the with_ prefix, leaving x <- dynamic_buffer ..., x <- c_string "foo", etc.
  • Change with_ to new_ to emphasize that something is being created or provided
  • Perhaps auto_, following C++ auto-pointers, which are auto-freed when they leave scope?

Thoughts?

@axch axch added the language / concrete syntax String -> AST label Nov 7, 2022
@dougalm dougalm added libraries Libraries written in Dex and removed language / concrete syntax String -> AST labels Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libraries Libraries written in Dex
Projects
None yet
Development

No branches or pull requests

2 participants