Skip to content
This repository was archived by the owner on Mar 16, 2025. It is now read-only.

Commit e783c86

Browse files
committed
make descriptions less prominent
1 parent b4a2cda commit e783c86

2 files changed

Lines changed: 62 additions & 58 deletions

File tree

pkg/builtin/functions.go

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,39 @@ var (
1616
humaneCoalescer = coalescing.NewHumane()
1717

1818
CoreFunctions = types.Functions{
19-
"default": native.NewFunction("returns the default value if the first argument is empty", defaultFunction),
19+
"default": native.NewFunction(defaultFunction).WithDescription("returns the default value if the first argument is empty"),
2020
"delete": deleteFunction{},
21-
"do": native.NewFunction("eval a sequence of statements where only one expression is valid", doFunction),
22-
"empty?": native.NewFunction("returns true when the given value is empty-ish (0, false, null, \"\", ...)", isEmptyFunction).WithCoalescer(humaneCoalescer),
23-
"error": native.NewFunction("returns an error", errorFunction),
24-
"has?": native.NewFunction("returns true if the given symbol's path expression points to an existing value", hasFunction),
25-
"if": native.NewFunction("evaluate one of two expressions based on a condition", ifElseFunction, ifFunction),
26-
"set": native.NewFunction("set a value in a variable/document, only really useful with ! modifier (set!)", setFunction),
27-
"try": native.NewFunction("returns the fallback if the first expression errors out", tryWithFallbackFunction, tryFunction),
21+
"do": native.NewFunction(doFunction).WithDescription("eval a sequence of statements where only one expression is valid"),
22+
"empty?": native.NewFunction(isEmptyFunction).WithCoalescer(humaneCoalescer).WithDescription("returns true when the given value is empty-ish (0, false, null, \"\", ...)"),
23+
"error": native.NewFunction(errorFunction).WithDescription("returns an error"),
24+
"has?": native.NewFunction(hasFunction).WithDescription("returns true if the given symbol's path expression points to an existing value"),
25+
"if": native.NewFunction(ifElseFunction, ifFunction).WithDescription("evaluate one of two expressions based on a condition"),
26+
"set": native.NewFunction(setFunction).WithDescription("set a value in a variable/document, only really useful with ! modifier (set!)"),
27+
"try": native.NewFunction(tryWithFallbackFunction, tryFunction).WithDescription("returns the fallback if the first expression errors out"),
2828
}
2929

3030
LogicFunctions = types.Functions{
31-
"and": native.NewFunction("returns true if all arguments are true", andFunction),
32-
"or": native.NewFunction("returns true if any of the arguments is true", orFunction),
33-
"not": native.NewFunction("negates the given argument", notFunction),
31+
"and": native.NewFunction(andFunction).WithDescription("returns true if all arguments are true"),
32+
"or": native.NewFunction(orFunction).WithDescription("returns true if any of the arguments is true"),
33+
"not": native.NewFunction(notFunction).WithDescription("negates the given argument"),
3434
}
3535

3636
ComparisonFunctions = types.Functions{
37-
"eq?": native.NewFunction("equality check: return true if both arguments are the same", eqFunction),
38-
"identical?": native.NewFunction("like `eq?`, but always uses strict coalecsing", identicalFunction),
39-
"like?": native.NewFunction("like `eq?`, but always uses humane coalecsing", likeFunction),
40-
41-
"lt?": native.NewFunction("returns a < b", ltCoalescer),
42-
"lte?": native.NewFunction("returns a <= b", lteCoalescer),
43-
"gt?": native.NewFunction("returns a > b", gtCoalescer),
44-
"gte?": native.NewFunction("returns a >= b", gteCoalescer),
37+
"eq?": native.NewFunction(eqFunction).WithDescription("equality check: return true if both arguments are the same"),
38+
"identical?": native.NewFunction(identicalFunction).WithDescription("like `eq?`, but always uses strict coalecsing"),
39+
"like?": native.NewFunction(likeFunction).WithDescription("like `eq?`, but always uses humane coalecsing"),
40+
41+
"lt?": native.NewFunction(ltCoalescer).WithDescription("returns a < b"),
42+
"lte?": native.NewFunction(lteCoalescer).WithDescription("returns a <= b"),
43+
"gt?": native.NewFunction(gtCoalescer).WithDescription("returns a > b"),
44+
"gte?": native.NewFunction(gteCoalescer).WithDescription("returns a >= b"),
4545
}
4646

4747
// aliases to make bang functions nicer (add! vs +!)
48-
addRudiFunction = native.NewFunction("returns the sum of all of its arguments", numberAddFunction, integerAddFunction)
49-
subRudiFunction = native.NewFunction("returns arg1 - arg2 - .. - argN", numberSubFunction, integerSubFunction)
50-
multiplyRudiFunction = native.NewFunction("returns the product of all of its arguments", numberMultFunction, integerMultFunction)
51-
divideRudiFunction = native.NewFunction("returns arg1 / arg2 / .. / argN", numberDivFunction, integerDivFunction)
48+
addRudiFunction = native.NewFunction(numberAddFunction, integerAddFunction).WithDescription("returns the sum of all of its arguments")
49+
subRudiFunction = native.NewFunction(numberSubFunction, integerSubFunction).WithDescription("returns arg1 - arg2 - .. - argN")
50+
multiplyRudiFunction = native.NewFunction(numberMultFunction, integerMultFunction).WithDescription("returns the product of all of its arguments")
51+
divideRudiFunction = native.NewFunction(numberDivFunction, integerDivFunction).WithDescription("returns arg1 / arg2 / .. / argN")
5252

5353
MathFunctions = types.Functions{
5454
"+": addRudiFunction,
@@ -63,11 +63,11 @@ var (
6363
"div": divideRudiFunction,
6464
}
6565

66-
lenRudiFunction = native.NewFunction("returns the length of a string, vector or object", stringLenFunction, vectorLenFunction, objectLenFunction)
67-
appendRudiFunction = native.NewFunction("appends more strings to a string or arbitrary items into a vector", appendToVectorFunction, appendToStringFunction)
68-
prependRudiFunction = native.NewFunction("prepends more strings to a string or arbitrary items into a vector", prependToVectorFunction, prependToStringFunction)
69-
reverseRudiFunction = native.NewFunction("reverses a string or the elements of a vector", reverseVectorFunction, reverseStringFunction)
70-
containsRudiFunction = native.NewFunction("returns true if a string contains a substring or a vector contains the given element", stringContainsFunction, vectorContainsFunction)
66+
lenRudiFunction = native.NewFunction(stringLenFunction, vectorLenFunction, objectLenFunction).WithDescription("returns the length of a string, vector or object")
67+
appendRudiFunction = native.NewFunction(appendToVectorFunction, appendToStringFunction).WithDescription("appends more strings to a string or arbitrary items into a vector")
68+
prependRudiFunction = native.NewFunction(prependToVectorFunction, prependToStringFunction).WithDescription("prepends more strings to a string or arbitrary items into a vector")
69+
reverseRudiFunction = native.NewFunction(reverseVectorFunction, reverseStringFunction).WithDescription("reverses a string or the elements of a vector")
70+
containsRudiFunction = native.NewFunction(stringContainsFunction, vectorContainsFunction).WithDescription("returns true if a string contains a substring or a vector contains the given element")
7171

7272
StringsFunctions = types.Functions{
7373
// these ones are shared with ListsFunctions
@@ -77,15 +77,15 @@ var (
7777
"reverse": reverseRudiFunction,
7878
"contains?": containsRudiFunction,
7979

80-
"concat": native.NewFunction("concatenates items in a vector using a common glue string", concatFunction),
81-
"split": native.NewFunction("splits a string into a vector", splitFunction),
82-
"has-prefix?": native.NewFunction("returns true if the given string has the prefix", hasPrefixFunction),
83-
"has-suffix?": native.NewFunction("returns true if the given string has the suffix", hasSuffixFunction),
84-
"trim-prefix": native.NewFunction("removes the prefix from the string, if it exists", trimPrefixFunction),
85-
"trim-suffix": native.NewFunction("removes the suffix from the string, if it exists", trimSuffixFunction),
86-
"to-lower": native.NewFunction("returns the lowercased version of the given string", toLowerFunction),
87-
"to-upper": native.NewFunction("returns the uppercased version of the given string", toUpperFunction),
88-
"trim": native.NewFunction("returns the given whitespace with leading/trailing whitespace removed", trimFunction),
80+
"concat": native.NewFunction(concatFunction).WithDescription("concatenates items in a vector using a common glue string"),
81+
"split": native.NewFunction(splitFunction).WithDescription("splits a string into a vector"),
82+
"has-prefix?": native.NewFunction(hasPrefixFunction).WithDescription("returns true if the given string has the prefix"),
83+
"has-suffix?": native.NewFunction(hasSuffixFunction).WithDescription("returns true if the given string has the suffix"),
84+
"trim-prefix": native.NewFunction(trimPrefixFunction).WithDescription("removes the prefix from the string, if it exists"),
85+
"trim-suffix": native.NewFunction(trimSuffixFunction).WithDescription("removes the suffix from the string, if it exists"),
86+
"to-lower": native.NewFunction(toLowerFunction).WithDescription("returns the lowercased version of the given string"),
87+
"to-upper": native.NewFunction(toUpperFunction).WithDescription("returns the uppercased version of the given string"),
88+
"trim": native.NewFunction(trimFunction).WithDescription("returns the given whitespace with leading/trailing whitespace removed"),
8989
}
9090

9191
ListsFunctions = types.Functions{
@@ -102,34 +102,34 @@ var (
102102
}
103103

104104
HashingFunctions = types.Functions{
105-
"sha1": native.NewFunction("return the lowercase hex representation of the SHA-1 hash", sha1Function),
106-
"sha256": native.NewFunction("return the lowercase hex representation of the SHA-256 hash", sha256Function),
107-
"sha512": native.NewFunction("return the lowercase hex representation of the SHA-512 hash", sha512Function),
105+
"sha1": native.NewFunction(sha1Function).WithDescription("return the lowercase hex representation of the SHA-1 hash"),
106+
"sha256": native.NewFunction(sha256Function).WithDescription("return the lowercase hex representation of the SHA-256 hash"),
107+
"sha512": native.NewFunction(sha512Function).WithDescription("return the lowercase hex representation of the SHA-512 hash"),
108108
}
109109

110110
EncodingFunctions = types.Functions{
111-
"to-base64": native.NewFunction("apply base64 encoding to the given string", toBase64Function),
112-
"from-base64": native.NewFunction("decode a base64 encoded string", fromBase64Function),
111+
"to-base64": native.NewFunction(toBase64Function).WithDescription("apply base64 encoding to the given string"),
112+
"from-base64": native.NewFunction(fromBase64Function).WithDescription("decode a base64 encoded string"),
113113
}
114114

115115
DateTimeFunctions = types.Functions{
116-
"now": native.NewFunction("returns the current date & time (UTC), formatted like a Go date", nowFunction),
116+
"now": native.NewFunction(nowFunction).WithDescription("returns the current date & time (UTC), formatted like a Go date"),
117117
}
118118

119119
TypeFunctions = types.Functions{
120-
"type-of": native.NewFunction(`returns the type of a given value (e.g. "string" or "number")`, typeOfFunction),
120+
"type-of": native.NewFunction(typeOfFunction).WithDescription(`returns the type of a given value (e.g. "string" or "number")`),
121121

122122
// these functions purposefully always uses humane coalescing
123-
"to-bool": native.NewFunction("try to convert the given argument losslessly to a bool", toBoolFunction).WithCoalescer(humaneCoalescer),
124-
"to-float": native.NewFunction("try to convert the given argument losslessly to a float64", toFloatFunction).WithCoalescer(humaneCoalescer),
125-
"to-int": native.NewFunction("try to convert the given argument losslessly to an int64", toIntFunction).WithCoalescer(humaneCoalescer),
126-
"to-string": native.NewFunction("try to convert the given argument losslessly to a string", toStringFunction).WithCoalescer(humaneCoalescer),
123+
"to-bool": native.NewFunction(toBoolFunction).WithCoalescer(humaneCoalescer).WithDescription("try to convert the given argument losslessly to a bool"),
124+
"to-float": native.NewFunction(toFloatFunction).WithCoalescer(humaneCoalescer).WithDescription("try to convert the given argument losslessly to a float64"),
125+
"to-int": native.NewFunction(toIntFunction).WithCoalescer(humaneCoalescer).WithDescription("try to convert the given argument losslessly to an int64"),
126+
"to-string": native.NewFunction(toStringFunction).WithCoalescer(humaneCoalescer).WithDescription("try to convert the given argument losslessly to a string"),
127127
}
128128

129129
CoalescingContextFunctions = types.Functions{
130-
"strictly": native.NewFunction("evaluates the child expressions using strict coalescing", doFunction).WithCoalescer(strictCoalescer),
131-
"pedantically": native.NewFunction("evaluates the child expressions using pedantic coalescing", doFunction).WithCoalescer(pedanticCoalescer),
132-
"humanely": native.NewFunction("evaluates the child expressions using humane coalescing", doFunction).WithCoalescer(humaneCoalescer),
130+
"strictly": native.NewFunction(doFunction).WithCoalescer(strictCoalescer).WithDescription("evaluates the child expressions using strict coalescing"),
131+
"pedantically": native.NewFunction(doFunction).WithCoalescer(pedanticCoalescer).WithDescription("evaluates the child expressions using pedantic coalescing"),
132+
"humanely": native.NewFunction(doFunction).WithCoalescer(humaneCoalescer).WithDescription("evaluates the child expressions using humane coalescing"),
133133
}
134134

135135
AllFunctions = types.Functions{}.

pkg/eval/util/native/function.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,32 @@ type Function struct {
2020

2121
var _ types.Function = &Function{}
2222

23-
func NewFunction(description string, funcs ...any) *Function {
24-
forms := make([]form, len(funcs))
23+
func NewFunction(forms ...any) *Function {
24+
funcForms := make([]form, len(forms))
2525

26-
for i := range funcs {
27-
funcForm, err := newForm(funcs[i])
26+
for i := range forms {
27+
funcForm, err := newForm(forms[i])
2828
if err != nil {
2929
panic(fmt.Sprintf("Form #%d is invalid: %v", i, err))
3030
}
3131

32-
forms[i] = funcForm
32+
funcForms[i] = funcForm
3333
}
3434

3535
return &Function{
36-
forms: forms,
37-
description: description,
36+
forms: funcForms,
3837
}
3938
}
4039

4140
func (f *Function) Description() string {
4241
return f.description
4342
}
4443

44+
func (f *Function) WithDescription(s string) *Function {
45+
f.description = s
46+
return f
47+
}
48+
4549
func (f *Function) WithCoalescer(c coalescing.Coalescer) *Function {
4650
f.coalescer = c
4751
return f

0 commit comments

Comments
 (0)