From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:37671) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iyxtu-0003DS-SW for gwl-devel@gnu.org; Tue, 04 Feb 2020 08:06:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iyxtr-0007Cq-4z for gwl-devel@gnu.org; Tue, 04 Feb 2020 08:05:58 -0500 Received: from sender4-of-o51.zoho.com ([136.143.188.51]:21169) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iyxtq-00073q-Lr for gwl-devel@gnu.org; Tue, 04 Feb 2020 08:05:55 -0500 From: Ricardo Wurmus Subject: objections to short syntax for code snippets? Date: Tue, 04 Feb 2020 14:05:46 +0100 Message-ID: <871rrasdsl.fsf@elephly.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gwl-devel-bounces+kyle=kyleam.com@gnu.org Sender: "gwl-devel" To: gwl-devel@gnu.org Hello there! I=E2=80=99d like to prepare a new release for the GWL soon to more official= ly commit to the changes that happened in the past year. So I think now is a good time for some last minute objections :) For some time now we have a reader extension that provides support for embedded code snippets like this: --8<---------------cut here---------------start------------->8--- process run-sh inputs . "a" . mine: "b" . "c" . yours: "d" # { echo "This is mine: {{inputs:mine}}, and this is yours: {{inputs:yours}= }." } --8<---------------cut here---------------end--------------->8--- Here we=E2=80=99ve got a process with four inputs, two of them tagged, and a shell snippet that refers to the inputs. The snippet is introduced with =E2=80=9C# {=E2=80=9D and ends on =E2=80=9C}= =E2=80=9D. Within the snippet {{=E2=80=A6}} is used to embed variable references. {{variable:tag= }} is used to refer to tagged variables, so that in the example above {{inputs:mine}} is replaced with the input tagged with the keyword =E2=80=9C#:mine=E2=80=9D (or =E2=80=9Cmine:=E2=80=9D due to SRFI-88), i.e. = the string =E2=80=9Cb=E2=80=9D. =E2=80=9C# {=E2=80=9D is the easiest way of declaring a code snippet; optio= nally, a user may provide an interpreter, so that # /bin/foo { =E2=80=A6 } runs /bin/foo in the process environment and uses it to interpret the snippet between the curly braces. I think this syntax is pretty okay and avoids all sorts of conflicts, such as conflicts with curly braces in the code snippet. It is flexible as you can specify any interpreter as long as it is provided by a declared package. It has two minor downsides, though: 1) it installs a reader extension, a token reader, on the space after #. That=E2=80=99s okay, but some people think that transforming the read text = so radically is excessive and not what reader macros should be used for. Oh well. 2) the simplest case of a shell snippet is very close to Guile=E2=80=99s sy= ntax for extended symbols. The syntax for extended symbols is =E2=80=9C#{the sy= mbol name}#=E2=80=9D. I don=E2=80=99t think it is very common to use this synta= x in day to day Scheme code =E2=80=94 the Guile manual discourages its use in the diabo= lical section 6.6.6.6. But this means that it=E2=80=99s possible for inexperienc= ed users to accidentally specify an extended symbol when they want to specify a shell snippet. Consider this: --8<---------------cut here---------------start------------->8--- process run-sh inputs "hello" #{ echo "I just want to say: {{inputs}}." } --8<---------------cut here---------------end--------------->8--- This is a syntax error because =E2=80=9C#{=E2=80=9D is not terminated with = =E2=80=9C}#=E2=80=9D. We can catch this error and suggest a fix. Easy. But what about this? --8<---------------cut here---------------start------------->8--- process run-sh inputs "hello" #{ function { echo "I just want to say something." }# this is not a comment } --8<---------------cut here---------------end--------------->8--- This would print this confusing error message: In procedure read_inner_expression: /home/rekado/dev/gx/gwl/doc/example= s/run-sh.w:7:4: unexpected "}" This is the only case where this would be problematic. In this very similar case we can catch the error and suggest a fix: --8<---------------cut here---------------start------------->8--- process run-sh inputs "hello" #{ function { echo "I just want to say something." } # this is not a comment } --8<---------------cut here---------------end--------------->8--- This prints: /home/rekado/dev/gx/gwl/doc/examples/run-sh.w:11:1: Unterminated extend= ed symbol. Did you mean to use "# {" instead of "#{"? (Annoyingly, the error location here is still wrong.) Anyway, do you have any objections to this optional syntax? Any requests for changing it? Note that it will always start with =E2=80=9C#= =E2=80=9D as that=E2=80=99s the only character where we can register reader macros. I d= on=E2=80=99t see a way to achieve any of this without a reader macro. Maybe there=E2=80= =99s a way to do something smart with the Guile Reader library=E2=80=A6? Your comments are welcome! -- Ricardo