::= :
key | /
regexp /
regexp-env? | data-type
A selector offers access inside an atom, such as selecting its metadata or the results of a regular expression. A data type selector can also indicate the type of data a value represents.
The most important selector is the metadata selector. Metadata is a list of keys and values belonging to an atom. It can be set or recalled with the :metadata-key
syntax. The space before the colon is optional and can be omitted when only one metadata-key is being set or retrieved.
Metadata is often used to store factual information that's associated with the atom. An atom representing a person might have metadata for his birthday, for example. Here are some sample atoms that represent elements in the periodic table with four pieces of data stored for each. The first parameter is the atom value and the others are metadata:
(@H hydrogen :no 1 :symbol H :weight 1.008)
(@Li lithium :no 3 :symbol Li :weight 6.94)
(@Na sodium :no 11 :symbol Na :weight 22.990)
We can recall any part of the metadata:
(@H) ⇒ hydrogen
(@H:symbol) ⇒ H
(@Na :weight) ⇒ 22.990
(@Li) #(@Li:no) ⇒ Lithium #3
This next example is factually incorrect since we know the atomic number of lithium is 3, not 7. Values like this which are known to be factually correct can be protected by a canon expression.
(@Li:no 7) ⇒ 7
Setting a metadata value changes the value in that expression and going forward:
1. (@tokyo-disneyland :rides (@pooh Pooh's Hunny Hunt) (@nemo …))
2. (@tokyo-disneyland :rides) ⇒ Pooh's Hunny Hunt ...
The following definition of (@ENGELBART)
relies on the existence of (@NLS)
and (@Portland)
inside the same containing expression, in this case (v ui-paper)
.
(v ui-paper
(@NLS NLS)
(@Portland Portland)
(@ENGELBART Douglas Engelbart :birthplace (@Portland) :software (@NLS)))
It results in the atom's value becoming Douglas Engelbart, his :birthplace
becoming Portland, and his :software
becoming NLS from this expression going forward.
(@DOUGLASENGELBART :software) ⇒ NLS
The full definition of (@ENGELBART) contains both a value and metadata selectors. Atoms like these can be viewed in several ways by the same viewer, allowing editing of metadata in a property sheet, for example. The viewer has full access to the atom's value and the values of all its metadata, but in narrative text a single value is returned according to the following rules:
(@ key) ⇒ return the value of the atom
(@ key value) ⇒ set the atom&'s value and return it
(@ key selector) ⇒ return the result of the selector on the atom
(@ key selector value) ⇒ set the selector to the value and return it
(@ key value selector value) ⇒ set the atom's value and the selector's value and return the atom's value
These examples show all five varieties of rendering in reverse order because 5 is the defining type used to fully define an atom.
Example 5 above contains three selectors and values for each of them. It also contains a value for the atom so that is what it returns:
//example 5
(@miss-clairol-27 Lightly Blonde :no 27 :family blonde :box [file:///c:/box/clairol/miss-clairol/27.jpg]) ⇒ Lightly Blonde
Example 4 contains a selector and its value. It also contains a value for the atom so that is what it returns:
//example 4
(@miss-clairol-27 Lightly Blonde :no 27) ⇒ Lightly Blonde
Example 3 contains only a selector, so it returns the selector value, in this case, a photo:
//example 3
(@miss-clairol-27 :box) ⇒ file:///c:/box/clairol/miss-clairol/27.jpg
Example 2 contains only a value, so it returns the value. This is an example of how any paragraph text can be linked to an atom:
//example 2
(@miss-clairol-27 blonder than Bond) ⇒ blonder than Bond
Example 1 contains only a key so it retrieves the last value. The atom was recently redefined to this value. If the atom were wrapped in canon, however, this would not be the case. Canon protects atoms against incidental changes, always providing a fallback value.
//example 1
(@miss-clairol-27) ⇒ blonder than Bond
Attribution is the process of keeping track of who wrote the contents of an MSL expression, when, in what language, and what URL or file it came from. These values can be stored in metadata and will often result in more than one value for the same metadata key within the same atom, such as the two :author values in this atom:
(@DOUBLEHELIX Molecular Structure of Nucleic Acids: A Structure for Deoxyribose Nucleic Acid :author Francis Crick :author James D. Watson :language en)
Time and date values can be used to indicate the date or dates of original publication of the content of the MSL expression and to show when the expression was added to the MSL text.
(@DOUBLEHELIX :pub-date 1953-4-25 :edit-date 2019-8-20))
A format expression can be used to show how a partial date should be displayed.
(@ANIMALFARM Animal Farm :author George Orwell :pub-date Aug 1945 (f date month year))
A regular expression or regex selector can be used to extract partial values from an atom or its metadata. When followed by a value, a regex selector can perform a search and replace function on the value returned from the atom or metadata.
(@WALT Walt Disney :fullname Walter Elias Disney)
(@WALT:fullname /\w+\s/) ⇒ Walter
(@WALT:fullname /\w+\s\w+/ Mr.) ⇒ Mr. Disney
When a regex selector appears without a replacement value, only the matches from the selector are returned.
(@CHICAGO Chicago, IL /[^,]+/) ⇒ Chicago
When a replacement value follows a regex selector, the entire previous value is returned with the matches replaced by the replacement value.
(@BOULDER-DAM The Boulder Dam was proposed as a water reclamation and electricity generation project over the Colorado river at the border of Arizona and Nevada. /Boulder/ Hoover)
(@BOULDER-DAM) ⇒ The Hoover Dam was proposed as a water reclamation and electricity generation project over the Colorado river at the border of Arizona and Nevada.
A regex selector can end with an optional regex-env
or flag, such as /g
which selects a global match. A selector like this followed by a value returns the full original value with the match(es) replaced by the second supplied value.
(@p1 It is not well known that the Disneyland Monorail System and Disneyland Railroad were owned by a separate business, WED Enterprises, which Walt controlled. Later renamed Retlaw Enterprises ("Walter" in reverse), the business was sold by Disney's heirs to the Walt Disney Company in 1982.)
(@p1 /business/g company) ⇒ It is not well known that the Disneyland Monorail System and Disneyland Railroad were owned by a separate company, WED Enterprises, which Walt controlled. Later renamed Retlaw Enterprises ("Walter" in reverse), the company was sold by Disney's heirs to the Walt Disney Company in 1982.
When an expression contains multiple regex selectors, each resulting value is curried to the next selector in left-to-right order.
(@WINDY-CITY Chicago, IL /[^,]+/ /cago/ -Town)
(@WINDY-CITY) ⇒ Chi-Town
Selectors persist in the atom's subatomic space until the atom's value is set again. Setting an atom's value removes all existing regex selectors.
(@SCROOGE Uncle Scrooge)
(@SCROOGE /Uncle/ Unca)
(@SCROOGE) ⇒ Unca Scrooge
(@SCROOGE Uncle Scrooge McDuck) ⇒ Uncle Scrooge McDuck
While it is not possible to directly remove a selector from an atom, the atom can be rewritten without the undesired selector, which achieves the same effect while preserving the previous value in the hybrid database.
(@OMNIMOVER Omnimover :developed-for (@ATIS Adventure Thru Inner Space) :opened 1967)
(@OMNIMOVER Omnimover :opened 1967)
(@OMNIMOVER) ⇒ (@OMNIMOVER Omnimover :opened 1967) ⇒ Omnimover
By rewriting the expression as a setter with the same value and including only the metadata we want going forward, we can effectively remove the :developed-for
metadata.
Data types can indicate how data should be stored, especially for non-text data. They can also provide a fallback for viewer formatting in lieu of a format expression.