diff options
| author | s-ol <s+removethis@s-ol.nu> | 2025-08-04 21:25:01 +0000 |
|---|---|---|
| committer | s-ol <s+removethis@s-ol.nu> | 2025-08-04 21:35:25 +0000 |
| commit | 6c171eace49b3a78e7b6edd679f54a1ad16f15f0 (patch) | |
| tree | 4c22f6ba83180e90f7b40d89acd7f528b235df56 | |
| parent | fix repeated chars in symbol regex in docs and code (diff) | |
| download | alive-6c171eace49b3a78e7b6edd679f54a1ad16f15f0.tar.gz alive-6c171eace49b3a78e7b6edd679f54a1ad16f15f0.zip | |
builtins: add fmt
| -rw-r--r-- | alv/builtins.moon | 24 | ||||
| -rw-r--r-- | docs/gen/layout.moon | 4 |
2 files changed, 25 insertions, 3 deletions
diff --git a/alv/builtins.moon b/alv/builtins.moon index da8570f..7640ac8 100644 --- a/alv/builtins.moon +++ b/alv/builtins.moon @@ -5,7 +5,9 @@ -- documentation. -- -- @module builtins -import Builtin, Op, PureOp, T, FnDef, Input, const, sig, evt, any, Struct, Array +import + Builtin, Op, PureOp, FnDef, Input, Struct, Array + T, const, sig, evt, any, template_subst from require 'alv.base' import Constant from require 'alv.result' import Error from require 'alv.error' @@ -448,7 +450,8 @@ trace = Constant.meta @out = inputs[2].result tick: => - L\print "trace #{@inputs.prefix!}: #{@inputs.value.result}" + value = @inputs.value\type!\pp @inputs.value! + L\print "trace #{@inputs.prefix!}: #{value}" eval: (scope, tail) => L\trace "evaling #{@}" @@ -613,6 +616,22 @@ This is a pure op, so at most one !-stream input is allowed." pairs = @unwrap_all! @out\set {key, val for {:key, :val} in *pairs} +fmt = Constant.meta + meta: + name: 'fmt' + summary: "Perform string interpolation." + examples: { '$fmt"…"' } + description: "Evaluates substitutions and concatenates them as [string/str][] does. + +This is a pure op, so at most one !-stream input is allowed." + + value: class extends PureOp + pattern: const! + any!^0 + type: T.str + tick: => + values = [i\type!\pp i!, true for i in *@inputs[2]] + @out\set template_subst @inputs[1]!, values + loop = Constant.meta meta: name: 'loop' @@ -765,6 +784,7 @@ Constant.meta '->>': thread_last :mkarray, :mkstruct + :fmt :loop, :recur diff --git a/docs/gen/layout.moon b/docs/gen/layout.moon index 93a7851..f84d4cf 100644 --- a/docs/gen/layout.moon +++ b/docs/gen/layout.moon @@ -3,6 +3,8 @@ dom = require 'docs.gen.dom' cmark = require 'cmark' import opairs from require 'alv.util' +local autoref + compile = (md) -> doc = cmark.parse_string md, cmark.OPT_DEFAULT cmark.render_html doc, cmark.OPT_DEFAULT + cmark.OPT_UNSAFE @@ -15,7 +17,7 @@ render_meta = (meta) -> examples = p table.concat [code e for e in *meta.examples], ' ' table.insert contents, examples if meta.description - description = compile meta.description\match '^\n*(.+)\n*$' + description = compile autoref meta.description\match '^\n*(.+)\n*$' table.insert contents, description contents |
