On 10/16/20 9:54 AM, Serj Kalichev wrote:
> Hello
> Do you have any ideas about following topic?
I have various ideas about it, but I haven't decided on a final
perspective yet. Sorry for the long mail.
To me this boils down to what clish tries to be. It can either stay a
"command templating engine" or develop into more of a "programming
system" - which really is a programming language in disguise.
By myself I would prefer the "programming" approach. I even implemented
a sort-of clish clone a while back in a language called Dylan [1].
Programmatic solutions are powerful. Dylan has extensible syntax, so
there is no need for XML or escaping. Internally this library is more
flexible than clish and can handle any Chomsky Type-3 language, even if
the language is dynamically defined by code.
But clish currently isn't so flexible, and I believe that is a good
thing too. Being just a command templating engine aligns with UNIX
philosophy: do one thing only and do it well. It would be pragmatic to
keep it this way.
[1]
https://github.com/dylan-lang/command-interface/blob/master/examples/demo/command-interface-demo.dylan
> On one hand I want to get rid of expanding in new klish. The reason is
> security. On the other hand I like advanced VARs with PARAMs and ACTIONs
> because them can be used as functions. For example completions are
> targets for using "functions". I don't know how to implement usage of
> such "functions" without unsecure expanding. I have some thoughts about
> it but ideas are not good enough.
>
== Need for Expansion
The idea of eliminating expansion also crossed my mind. The main need
for it definitely comes from the shell plugin. Unfortunately expansion
like that is hard to avoid in shell. The only way I know of would be to
embed an actual shell - and even then the shell language itself brings
its own related problems (safe quoting, strange characters in filenames).
And then there are the "other uses" such as composing viewid and prompt
as well as certain configuration actions. Those are hard to avoid given
the current structure of clish.
It should be possible to leave expansion off for all but those things
that actually require it. Python and Lua certainly don't need it except
for some special cases (evaluation commands), and even those can be
implemented using PARAMs if we decide on that as a convention. XML
writers will hardly ever need to do such things, so it shouldn't be a
problem that its not discoverable. It can be documented instead.
== Need for Functions and Programming
Relatively recent extensions have introduced several features that tend
towards making "clish XML" a programming language. One is the use of
PTYPE actions for completion. Another is the concept of dynamic vars.
==== Actions as a programming construct
Actions already have several properties of functions. They take
parameters, and through oactions they can also produce output.
The only problem with all that is that clish is missing all the rest of
a programming language. It has neither sequences nor loops, and there is
no mechanism for composing actions. This makes for a bad programming
language.
==== Expansion as a programming language
Using expansion and extending it into a programming language has
happened before. A very prominent example is "make", which is composed
of a "rule language" and an "expression language" as well as the
embedded "shell language".
Some such systems work well and are perfectly fine, but in my experience
programming languages are better if they were intended as such from the
start.
==== Using embedded languages instead
My preferred approach for making clish more "broad" is to allow using
the embedded interpreters as the main programming environment.
These interpreters are maintained and somewhat well-designed, tested in
production and are well-supported as programming environments.
How to go about this is still a partly open question to me. I would
imagine some improved hooking mechanism so that plugins can insert their
own functions into completion and other such extension points.
This approach would give clish the power of a real programming language
for free.