\chapter{Interning strings}
\hypertarget{md_post-scarcity_2docs_2_interning-strings}{}\label{md_post-scarcity_2docs_2_interning-strings}\index{Interning strings@{Interning strings}}
\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md72}%
\Hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md72}%
 I\textquotesingle{}m trying to understand what it means to intern a name in an environment with a messy and possibly shifting graph of namespaces.

My current thinking is that in data terms a name is just a string. In evaluation terms, an unquoted string (in lexical terms one unprotected by enclosing quotation marks) is a name, while a quoted string is \textquotesingle{}a string\textquotesingle{}. So, supposing the name {\bfseries{froboz}} is not bound in the current environment, \begin{DoxyVerb}(eval froboz)
\end{DoxyVerb}
 causes an unbound variable exception to be thrown, while \begin{DoxyVerb}(eval "froboz")
\end{DoxyVerb}
 returns the value \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}"{}froboz"{}\texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}. This begs the question of whether there\textquotesingle{}s any difference between \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}"{}froboz"{}\texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*} and \texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}\textquotesingle{}froboz\texorpdfstring{$\ast$}{*}\texorpdfstring{$\ast$}{*}, and the answer is that at this point I don\textquotesingle{}t know.

There will be a concept of a root \href{Namespace.html}{\texttt{ namespace}}, in which other namespaces may be bound recursively to form a directed graph. Because at least some namespaces are mutable, the graph is not necessarily acyclic. There will be a concept of a current namespace, that is to say the namespace in which the user is currently working.

There must be some notation to say distinguish a request for the value of a name in the root namespace and the value of a name in the current namespace. For now I\textquotesingle{}m proposing that\+: \begin{DoxyVerb}(eval froboz)
\end{DoxyVerb}
 will return the value that {\bfseries{froboz}} is bound to in the current namespace; \begin{DoxyVerb}(eval .froboz)
\end{DoxyVerb}
 will return the value that {\bfseries{froboz}} is bound to in the root namespace; \begin{DoxyVerb}(eval foobar.froboz)
\end{DoxyVerb}
 will return the value that {\bfseries{froboz}} is bound to in a namespace which is the value of the name {\bfseries{foobar}} in the current namespace; and that \begin{DoxyVerb}(eval .system.users.simon.environment.froboz)
\end{DoxyVerb}
 will return the value that {\bfseries{froboz}} is bound to in the environment of the user of the system called {\bfseries{simon}}.

The exact path separator syntax may change, but the principal that when interning a symbol it is broken down into a path of tokens, and that the value of each token is sought in a namespace bound to the previous token, is likely to remain.

Obviously if {\bfseries{froboz}} is interned in one namespace it is not necessarily interned in another, and vice versa. There\textquotesingle{}s a potentially nasty problem here that two lexically identical strings might be bound in different namespaces, so that there is not one canonical interned {\bfseries{froboz}}; if this turns out to cause problems in practice there will need to be a separate canonical \href{Hashtable.html}{\texttt{ hashtable}} of individual path elements.

Obviously this means there may be arbitrarily many paths which reference the same data item. This is intended.\hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md73}{}\doxysection{\texorpdfstring{Related functions}{Related functions}}\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md73}
\hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md74}{}\doxysubsection{\texorpdfstring{(intern! string)}{(intern! string)}}\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md74}
Binds {\itshape string}, considered as a path, to {\bfseries{NIL}}. If some namespace along the path doesn\textquotesingle{}t exist, throws an exception. Obviously if the current user is not entitled to write to the terminal namespace, also throws an exception.\hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md75}{}\doxysubsection{\texorpdfstring{(intern! string T)}{(intern! string T)}}\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md75}
Binds {\itshape string}, considered as a path, to {\bfseries{NIL}}. If some namespace along the path doesn\textquotesingle{}t exist, create it as the current user with both read and write \href{Access-control.html}{\texttt{ access control}} lists taken from the current binding of {\bfseries{friends}} in the current environment. Obviously if the current user is not entitled to write to the last pre-\/existing namespace, throws an exception.\hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md76}{}\doxysubsection{\texorpdfstring{(intern! string T write-\/access-\/list)}{(intern! string T write-access-list)}}\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md76}
Binds {\itshape string}, considered as a path, to {\bfseries{NIL}}. If some namespace along the path doesn\textquotesingle{}t exist, create it as the current user with the read \href{https://www.journeyman.cc/blog/posts-output/2006-02-20-postscarcity-software/}{\texttt{ access control}} list taken from the current binding of {\bfseries{friends}} in the current environment, and the write access control list taken from the value of {\itshape write-\/access-\/list}. Obviously if the current user is not entitled to write to the last pre-\/existing namespace, throws an exception.\hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md77}{}\doxysubsection{\texorpdfstring{(set! string value)}{(set! string value)}}\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md77}
Binds {\itshape string}, considered as a path, to {\itshape value}. If some namespace along the path doesn\textquotesingle{}t exist, throws an exception. Obviously if the current user is not entitled to write to the terminal namespace, also throws an exception.\hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md78}{}\doxysubsection{\texorpdfstring{(set! string value T)}{(set! string value T)}}\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md78}
Binds {\itshape string}, considered as a path, to {\itshape value}. If some namespace along the path doesn\textquotesingle{}t exist, create it as the current user with both read and write \href{Access-control.html}{\texttt{ access control}} lists taken from the current binding of {\bfseries{friends}} in the current environment. Obviously if the current user is not entitled to write to the last pre-\/existing namespace, throws an exception.\hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md79}{}\doxysubsection{\texorpdfstring{(set! string value T write-\/access-\/list)}{(set! string value T write-access-list)}}\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md79}
Binds {\itshape string}, considered as a path, to {\itshape value}. If some namespace along the path doesn\textquotesingle{}t exist, create it as the current user with the read \href{Access-control.html}{\texttt{ access control}} list taken from the current binding of {\bfseries{friends}} in the current environment, and the write access control list taken from the value of {\itshape write-\/access-\/list}. Obviously if the current user is not entitled to write to the last pre-\/existing namespace, throws an exception.\hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md80}{}\doxysubsection{\texorpdfstring{(put! string token value)}{(put! string token value)}}\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md80}
Considers {\itshape string} as the path to some namespace, and binds {\itshape token} in that namespace to {\itshape value}. {\itshape Token} should not contain any path separator syntax. If the namespace doesn\textquotesingle{}t exist or if the current user is not entitled to write to the namespace, throws an exception.\hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md81}{}\doxysubsection{\texorpdfstring{(string-\/to-\/path string)}{(string-to-path string)}}\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md81}
Behaviour as follows\+: (string-\/to-\/path "{}foo.\+bar.\+ban"{}) =\texorpdfstring{$>$}{>} ("{}foo"{} "{}bar"{} "{}ban"{}) (string-\/to-\/path "{}.\+foo.\+bar.\+ban"{}) =\texorpdfstring{$>$}{>} ("{}"{} "{}foo"{} "{}bar"{} "{}ban"{})

Obviously if the current user can\textquotesingle{}t read the string, throws an exception.\hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md82}{}\doxysubsection{\texorpdfstring{(path-\/to-\/string list-\/of-\/strings)}{(path-to-string list-of-strings)}}\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md82}
Behaviour as follows\+: (path-\/to-\/string \textquotesingle{}("{}foo"{} "{}bar"{} "{}ban"{})) =\texorpdfstring{$>$}{>} "{}foo.\+bar.\+ban"{} (path-\/to-\/string \textquotesingle{}("{}"{} "{}foo"{} "{}bar"{} "{}ban"{})) =\texorpdfstring{$>$}{>} "{}.\+foo.\+bar.\+ban"{}

Obviously if the current user can\textquotesingle{}t read some element of {\itshape list-\/of-\/strings}, throws an exception.\hypertarget{md_post-scarcity_2docs_2_interning-strings_autotoc_md83}{}\doxysubsection{\texorpdfstring{(interned? string)}{(interned? string)}}\label{md_post-scarcity_2docs_2_interning-strings_autotoc_md83}
Returns a string lexically identical to {\itshape string} if {\itshape string}, considered as a path, is bound (i.\+e.
\begin{DoxyEnumerate}
\item all the non-\/terminal elements of the path are bound to namespaces,
\item all these namespaces are readable by the current user;
\item the terminal element is bound in the last of these;
\end{DoxyEnumerate}

Returns nil if {\itshape string} is not so bound, but all namespaces along the path are readable by the current user.

I\textquotesingle{}m not certain what the behaviour should be if some namespace on the path is not readable. The obvious thing is to throw an access control exception, but there are two possible reasons why not\+:
\begin{DoxyEnumerate}
\item It may turn out that this occurs too often, and this just becomes a nuisance;
\item From a security point of view, is evidence that there is something there to which you don\textquotesingle{}t have access (but that is in a sense an argument against ever throwing an access exception at all). 
\end{DoxyEnumerate}