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

Shared variables and functions #15

Closed
xiaq opened this issue Jun 17, 2014 · 6 comments
Closed

Shared variables and functions #15

xiaq opened this issue Jun 17, 2014 · 6 comments

Comments

@xiaq
Copy link
Member

xiaq commented Jun 17, 2014

Persistent variables and persistent functions are shared across multiple sessions and preserved on shell exits. They are useful for passing data or code between concurrent sessions without (explicit) serialization/deserialization. In particular, they are ideal for configuration variables and functions and may serve as a more advanced clipboard facility.

The ideas are taken from fish, which has universal variable and autoload functions, with quite different implementations. All universal variables are stored into one file, and fish instances talk to an agent, fishd, to access them. In the case of autoload functions, however, each function is stored into a separate file and there is no agent to coordinate the access. Users are encouraged to manage autoload functions manually.

Open questions:

  1. Is unifying persistent variables and functions necessarily a good idea?
  2. How to statically check persistent variables and functions?
  3. Is an agent needed to coordinate access? If so, how should the protocol be? (Note: The elvished package already includes a prototype of the agent.)
@xiaq xiaq changed the title Persistent/universal variables and functions Shared variables and functions Jan 23, 2015
@xiaq
Copy link
Member Author

xiaq commented Jan 23, 2015

I have settled on the terminology of "shared" variable and function. Updates to the design:

shared: requires mandatory qualification

Shared variables (including functions which are also variables) reside in the special shared: namespace (as per #8), which is deliberately not in the scoping rule of unqualified variable access, since it is hard (impossible?) to check access to the shared namespace statically - both the existence of a variable and its static type cannot be determined statically if variables can be added and deleted from shared: at any shell session.

This means that all accesses to shared: must be qualified. They are still suitable for storing global configuration and as a clipboard, but the case with autoload functions is now more difficult.

Storage mechanism ✔

There will be no agents; all clients access the SQLite database directly. According to the FAQ, SQLite handles process-level concurrency well.

@xiaq
Copy link
Member Author

xiaq commented Feb 11, 2016

We can implement a predefined shared module.

@xiaq xiaq closed this as completed in 92fb6e5 Feb 26, 2016
@tfga
Copy link

tfga commented May 22, 2020

Was this shared module ever implemented?
How can I define my own shared variables?

@krader1961
Copy link
Contributor

Was this shared module ever implemented?

Yes, see commit 92fb6e5 that appears as a link directly above your question. It was removed two years later in commit c1b433d.

@tfga
Copy link

tfga commented May 22, 2020

@krader1961 Is there any alternative today?

@xiaq
Copy link
Member Author

xiaq commented May 22, 2020

Shared variables have more complex semantics than simple variables. Notably, reading a shared variable can fail while reading a normal variable never fails.

The underlying store API is still there. This is in scope for #1032.

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

No branches or pull requests

3 participants