From 76bea994b9428ddfc71fa54acb2c0679cc9311f0 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 31 Jan 2022 22:42:19 -0500 Subject: =?UTF-8?q?Example=20of=20making=20an=20executable=20from=20a=20?= =?UTF-8?q?=E2=80=A2ReBQN=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/doc/rebqn.html | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'docs/doc') diff --git a/docs/doc/rebqn.html b/docs/doc/rebqn.html index 932a647f..a3d0c97e 100644 --- a/docs/doc/rebqn.html +++ b/docs/doc/rebqn.html @@ -76,3 +76,20 @@

Above, ^ becomes a 1-modifier, so that it modifies % rather than being called directly on 12 as a function.

The glyph can be any character that's not being used by BQN already. Characters like c or or : will result in an error, as they'd break BQN syntax. Other than that, the sky's the limit! Or rather, the Unicode consortium is the limit. If they don't recognize your symbol, you're going to have to petition to make it an emoji or something. Oh well.

+

Run as an executable

+

Of course, calling a function on a string isn't a great interface for programming. But BQN has the facilities to turn such a function into a proper script, which can then be run much like the BQN executable. The following example takes a filename followed by the •args to be passed in, or runs as a REPL if given no arguments.

+
#! /usr/bin/env bqn
+calcFns  '+'+, '-'-, '*'×, '/'(÷)
+calc  •ReBQN {primitivescalcFns, repl"loose"}
+{
+  # Run on a file
+  0 < •args ?
+    f  •wdpath •file.At •args
+    pathname  (`'/')f
+    path,name,1•args Calc •file.Chars f
+
+  # Run as REPL
+  ; _while_  {𝔽𝔾𝔽_𝕣_𝔾𝔽𝔾𝕩}
+    •GetLine•ShowCalc _while_ (@) •GetLine@
+}
+
-- cgit v1.2.3