literal - pannous/warp GitHub Wiki

A literal is text taken literally, uninterpreted (vocabulary: charged). Unevaluated code is a block; unevaluated content never meant to run is data.

Strings are the extreme form of literals, in which every character is literally uninterpreted. Templates are strings in which some parts ($values) are interpreted: "I am ${age} years old". There is a historic reason why strings are denoted with double-quotes: "example".

Literals are strings without quotes. They occur where no code is expected, after auto-quoting keywords and functions:

# sketch: import forms
import "test.h"
import test.h
import graphics
import github:pannous/angle

The arguments of import are read literally (letter by letter instead of interpreted), without semantic connection to the program's references and symbols such as variables: even if graphics is a variable declared before, import graphics does not refer to it.

A function becomes auto-quoting through the literal parameter type: import package:literal := download(package) and interpret result Depending on the signature of download, the literal is converted, e.g. to a string: download package:string := curl(package, cache=/tmp)

A more structured definition of import would be import package:path, where path is a literal of a specific form such as github:pannous/angle (protocol : domain / resource).

The literal parameter type also differs from the block parameter type: a literal argument is text, a block argument is code the function runs with ! when it wants to (if condition:block then:block else:block).

The literal type keyword forces uninterpreted reading of each character when parsing, near identical to the contents of a double-quoted string. The difference between import literal package = … and import string package = … is that the string needs to be double-quoted and can be provided via a reference.