Page MenuHomePhabricator

Improve access by functions to Persistent object labels (and other keys)
Open, LowPublicFeature

Description

Feature summary (what you would like to be able to do and where):

When evaluating a Wikifunctions function, it should be possible to return a Persistent object’s labels or the string for a specified language.

Some support for language fallback is highly desirable.

It should also be possible for a function to find an object given one of its labels (and perhaps its type).

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):

Currently, a function’s only access to a Persistent object is through the built-in function Fetch Persistent object (Z828). This can access a Persistent object only when supplied with a quoted reference (a Z99). A function cannot easily supply such an object.

A simple use-case is a date containing a Gregorian calendar month (which is standard on many Wikipedia editions). A function should be able to convert a numeric month to a literal month name (and vice versa) without having to amend the function for each additional language.

In general, it should be possible to convert between objects, references, quotes and literal strings (all referring to the same object). Currently:

  • A function cannot have a Reference as its return type or as an argument
  • Although it seems possible to have Quote as an argument, this does not work in practice (because the Argument reference is quoted)
  • A reference cannot be transformed into a string (or vice versa)
  • A reference extracted from an object is immediately de-referenced

(There are partial solutions for some of these but these are ignored for the sake of clarity.)

Because Z828 is a function, it cannot currently be accessed directly from an implementation in code. (Presumably re-entrancy will enable this?)

A user function should be able to access Persistent object keys in the same way and at the same time as other keys, without having regard to the technical distinction (an argument’s type and the type’s label(s), for example). Ideally, it should also be possible to specify a required key by using one of its labels.

Benefits (why should this be implemented?):
Some functions cannot be implemented successfully or can have only inefficient implementations that may be difficult to comprehend or adapt.

For example, the function “month label” is a (failing) attempt to provide a particular label for a Gregorian calendar month (see https://www.wikifunctions.org/wiki/Wikifunctions:Project_chat#Wikifunctions_labels_in_functions). This function should not be necessary because “object label” would work for any object if we could get from the object to its quoted reference.

The “object label” solution will probably not scale for a large number of labels, so it is worth considering how a language fallback approach can reduce the number of labels returned (from Z828 or its equivalent), with the expectation that the first such label will generally be the most acceptable (being the label for the requested language when such a label exists).

(Slightly off-topic, but note that “identity identity identity” (Z16372) would be much more efficient if we could get a string identity out of Z803. This would make “same month” redundant or (probably) more efficient and avoid the need for a separate equality function for each enumeration.)