Am Mo., 16. März 2020 um 16:38 Uhr schrieb Marc Feeley <xxxxxx@iro.umontreal.ca>:
The point of the foo: (or :foo) syntax for keywords and the self-evaluation is to provide a lightweight and “visually” agreable syntax for calling a procedure with keyword arguments.  In this respect I find the following visually disagreable:

   (bar 42 'foo: 88 'baz: 99)
   (bar 42 '#:foo 88 '#:baz 99)

Self-evaluating keywords make the code more lightweight:

   (bar 42 foo: 88 baz: 99)
   (bar 42 #:foo 88 #:baz 99)

And between the two I find the “sharp prefix” syntax for keyword disagreable visually.  I question the motivation for introducing it.

In terms of the language spec, it adds a new sharp syntax (which conflicts with the uses of that syntax by existing Scheme systems) and also a self-evaluation rule.  Similarly the more pleasing colon suffix (or prefix) syntax adds a self evaluation rule and a change to the syntax of symbols.  But many Scheme implementations already support the colon suffix (or prefix) syntax, so it would be ill-advised for a programmer to use symbols that begin or end with a colon if they have any interest in sharing code with others (and we shouldn’t forget this is the reason we are discussing this SRFI).

Can someone explain advantages of the #:foo syntax I may have missed?

My original post in this thread was not about the exact form of the lexical syntax, be it `foo:', `:foo', or `#:foo'.  (The latter, which you find visually less pleasant, has the advantage of not clashing with R7RS-small.)

My original post was about the semantics of an expression like:

(bar foo: 10)

There are two possibilities:

(1) This expression is an extension of the procedure call expression of section 4.1.3 of R7RS-small. The syntax expander recognizes that this is a call taking a keyword argument and expands into a calls of (the evaluation of) `bar' with no ordinary argument and one keyword argument `foo' taking the value 10.

(2) This expression is an ordinary procedure call expression of section 4.1.3 of R7RS-small. Thus (the evaluation of) `bar' will be called with two arguments, namely the keyword object with the name `foo' and the value 10. It is up to the procedure `bar' to scan its arguments for keyword values among them.

In the case of (1), lexical keyword syntax mustn't be self-evaluating. Otherwise, it will contradict the model in section 4.1.3 as I explained in my original post.

In the case of (2), lexical keyword syntax should be self-evaluating as otherwise you end up with ugly syntax like `(bar ':foo 10)'.

The options (1) and (2) to add keyword arguments to Scheme follow a different model each and we haven't yet discussed what model should underlie SRFI 177 or a future Scheme standards. The model (1) has the advantage that one can later extend it to procedures taking both arbitrary many arguments and keyword arguments.  The model (2) seems to be equivalent to using alists of keyword arguments as the rest argument of a procedure.

Marc


Marc



> On Mar 16, 2020, at 9:57 AM, Shiro Kawai <xxxxxx@gmail.com> wrote:
>
>
> On Mon, Mar 16, 2020 at 3:54 AM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:
> In that case
>
> (bar :foo x)
>
> and
> (bar ':foo x)
>
> would be equivalent.  The would forbid any extension of SRFI 177 to allow procedures taking keyword arguments and a variable number of arguments at the same time as the code of `bar' wouldn't be able to distinguish a keyword introducing an keyword argument from a regular argument, which happens to evaluate to a keyword.
>
>
> If we take semantics similar to Common Lisp, you don't need to distinguish them.  Actually you don't *want* to distinguish them.


>
> It doesn't conflict with R7RS-small.  The drawback is that it can't be implemented portably.
>
>
> On Mon, Mar 16, 2020 at 3:09 AM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:
> Some Schemes have native keywords objects and a lexical syntax for keywords.  Commonly used lexical syntaxes are `:foo', `foo:' and `#:foo'.
>
> In some systems, keywords are self-evaluating like numbers or strings.  In other words, `:foo' or `foo:' are expressions evaluating to the keyword with name `foo'. 
>
> In other systems, keywords are not self-evaluating.  For example, `#:key' is not a valid expression, but `(quote #:key)' is, evaluating to the keyword with name `foo'.
>
> I want to argue that the second alternative is the much better one because it leads to a simpler and more uniform semantics.
>
> In an ordinary procedure call, the procedure and the arguments are evaluated and then the (evaluation of the) procedure is called with the (values of the) arguments.
>
> If the keyword lexical syntax `:foo' is self-evaluating, the base case of the procedure call `(bar :foo x)' is therefore to evaluate `bar' , `:foo' and `x' and to do the call with the corresponding values.
>
> As soon as procedures with keyword arguments are introduced, the R7RS-small rule of how `(bar :foo x)' is to be evaluated has to be changed.  In a strict sense, the resulting language is no more compatible with R7RS-small.
>
> In the other case when `#:foo' is not self-evaluating, there is no clash with the semantics of R7RS-small.  In that case, `(bar #:foo x)' is new syntax (not existing in R7RS-small) and section 4.1.3 of R7RS-small has just to be extended without overriding previous behavior.
>
> The conclusion is: If R7RS-large eventually gets lexical syntax for keywords, it should follow the `#:foo' and not the `:foo' model. SRFI-177 should be specified in a way that makes a smooth transition to the `#:foo' model possible.
>
> Marc
>
>
> --
> Prof. Dr. Marc Nieper-Wißkirchen

> Universität Augsburg
> Institut für Mathematik
> Universitätsstraße 14
> 86159 Augsburg

> Tel: 0821/598-2146
> Fax: 0821/598-2090

> E-Mail: xxxxxx@math.uni-augsburg.de
> Web: www.math.uni-augsburg.de/alg/mitarbeiter/mnieper/