diff options
author | the lemons <citrons@mondecitronne.com> | 2022-02-18 22:27:03 -0600 |
---|---|---|
committer | the lemons <citrons@mondecitronne.com> | 2022-02-18 22:27:03 -0600 |
commit | 9ebd8777928e175b5eabd3581a7c9ac70c584060 (patch) | |
tree | a2f7f71be0d5696c7b90d325d3681f787dde6695 | |
parent | dbcb41f92f41564ae2f6d31dfcecc559fd154c2a (diff) |
lambdas
-rw-r--r-- | readme.md | 31 |
1 files changed, 26 insertions, 5 deletions
@@ -12,13 +12,15 @@ an expression consists of a literal noun (expressed as a sequence of alphebetic "quotations" are a special type of literal noun which refer to statements or sequences of text themselves. there are two types of quotations. a bracket quotation is surrounded in square brackets, and must contain within it a syntactically valid CR document. a normal quotation is enclosed in double quotes and may contain anything of any syntactic validity or language. however, a normal quotation must be properly escaped. the only escape sequences available in a normal quotation are `\\` and `\"`. +lambdas are another special type of literal noun. they are first-class functions. they consist of a document enclosed in `{}`. + ### described in EBNF ``` alpha = ? [a-z][A-Z] ? ; num = ? [0-9] ? ; ws = { ? whitespace characters ? } ; -literal = alpha , { alpha } | num , { num } | quote ; +literal = alpha , { alpha } | num , { num } | quote | lambda ; binop = ? binary operator, see § binary operators ? ; unop = ? unary operator, see § unary operators ? ; @@ -36,13 +38,15 @@ normal quote = "\"" , { quote char } , "\"" bracket quote = "[" , document , "]" quote = normal quote | bracket quote + +lambda = "{" , document , "}" ``` ## the meaning of a noun the meaning of literal nouns (which are not quotations or numbers) is determined thusly (in this exact order): 1. if the meaning of the literal noun, is defined in this standard's noun list, then the meaning of the noun is according to the list. -2. if the meaning of the literal noun has been defined previously via the `::=` operator, then the meaning of the noun is according to that definition. +2. if the meaning of the literal noun has been defined previously via the `::=` operator, then the meaning of the noun is according to that definition. the scope of definition and usage must be considered. see § lambdas. 3. the meaning of the literal noun must be determined from context, e.g. it is the name of a person. it is recommended that nonstandard nouns (nouns defined via step #2 or #3) are initially capitalized to distinguish them from standard nouns, which will never be capitalized. however, this is just proposed convention and is not required to conform to the standard. @@ -57,13 +61,24 @@ CR makes no distinction between statements such as "the/a person who is thinking g>:f ``` +the meaning of a CR document is determined by evaluating its sentences in order. + ## lists a list is a special type of noun. they contain any amount of nouns in a specific order, including lists themselves. certain operators expect lists as operands. if a nonlist is passed to these operators, then the operand is treated as a list with that noun as its only element. lists can be composed with the `,` operator. it is similar to a "cons" operation. it appends the first operand to the second operand, which is assumed to be a list. lists can be interpreted semantically as meaning all of its elements in order. for example, the sentence `A,B,C` means that there exists `A`, then `B`, then `C`, which indicates that they happen in order. -## operator side-effects -some operators have **side-effects** which means that +## lambdas +a lambda is a special type of noun representing a CR document. the `@` operator is used to apply lambdas to arguments. to evaluate a lambda, the noun `X` is assigned to the argument within the scope of the lambda. the document is then evaluated. the last sentence of a lambda does not have the meaning of a normal sentence. instead, its expression is evaluated, and the lambda application evaluates to this result. + +lambdas are lexically scoped. scope affects the behavior of the `::=` operator. a noun's definition according to this operator is the definition or redefinition in the most inner scope that encloses its usage. a lambda's scope is that in which it is defined. lambdas are evaluated within the scope of their initial definition. + +this example illustrates the scoping behavior of lambdas: +``` +L::={Y::=X{Y}}((L@A)@B)=A +``` + +the inner lambda `{Y}` is able to access a definition from its outer lambda after it is applied to the argument `B`. ## binary operators the binary operators, when used, evaluate to their definitions below. @@ -72,6 +87,9 @@ the two operands are denoted as `x` and `y` in these definitions. they are the f ### `=` `x` which is the same thing as `y` +### `::=` +the noun `z`, as defined in the word list; *define or redefine* `x`*'s name in the present scope to have the value of* `y` + ### `>` `x` which causes `*_y` @@ -135,7 +153,7 @@ all instances of `x` nothing that is `x` or `*_x` ### `!!:` -`x`; *this operator has the* **side-effect** *of emphasizing* `x` *in the sentence*. +`x`; *this operator emphasizes* `x` *in the sentence* ### `?:` a hypothetical/possible `x` @@ -149,6 +167,9 @@ the amount of `x` which exist; *or, if* `x` *is a list*: the amount of items in ### `&,` all of the elements of list `x` +### `:_` +`z`, as defined in the word list; *this operator is equivalent to `x::=X` + ## clarification: the meaning of `*_x` the difference between `*_x` and `x` can be thought of like this: if `x` is "dog"/"dogs", then `*_x` is "some dogs" or "a dog". the difference becomes quite relevant when one performs definitions. |