This is the mail archive of the guile@sources.redhat.com mailing list for the Guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C-like identity?


On Sun, Jul 30, 2000 at 03:37:53PM +0200, Marius Vollmer wrote:
> > Closures: 
> >   lambda (x, y) {...body...}
> > [seems fine]
> 
> Yep.  But as you say, for for-each you might want to provide something
> more concise.  Maybe simply
> 
>     { arg_list: body ... }
> 
> (see definition of arg_list below) However, this would maybe clash
> with list constructors that might also want to use `{' and '}'.

This looks kind of nice -- I really don't like the word "lambda" at
all.  One mathematician chose an arbitrary greek letter, and then it
became syntax...

> > Symbols: 
> >   #asymbol                     
> > [#? 'asymbol ? This is completely arbitrary, but I don't really want
> > to use ' because it is a false-cognate for characters]
> 
> Hmm, I agree that 'asymbol will probably not fit into the rest of the
> grammar.  There should be a general purpose way of escaping to Scheme
> and something like
> 
>     #.any-scheme-expr
> 
> might do it (where any-scheme-expr is read using the regualr Scheme
> `read' function.  Scheme expressions are self-delimiting, so you don't
> need a closing indicator.)

I wonder if #scheme any-scheme-expr might be better, as it's much
easier to read.  Then there could be other # expressions (like
include).  (What syntax does C++ use for modules...?  #include still,
right?)  Symbols should really have some representation, though,
because they get used a lot.  @ and $ seem to be syntactically unused,
but @ would be odd, and $ might confuse people from a perl/shell
background.  Another operator could be used as a prefix operator...
& and * won't do, since they already were used that way.  ^ might be
reasonable, because who really uses bitwise-xor that often?  It would
be a novel operator to many people anyway.  ` is also a possibility,
though it could be confused with Scheme's `.  (Though, perhaps, 
quasiquote is more general and more important than normal quote)...

> > Constant lists: 
> >   #(a b c)              
> > [Should there be commas inbetween items?]
> 
> Hmm, is this a list of symbols?  I think it would make more wothwhile
> to have a special syntax for constructing lists, vectors (and
> structs).
> 
> My first try would be to have
> 
>     ( e1, e2, ... )
> 
> which translates to (list t1 t2 ...) where ti is the translation of
> expression ei.  You could also have
> 
>     ( e1, e2, ...; en )

Well, list(1, 2, 3) already works fine and looks fine syntactically.
The semicolon might be a good idea... but at the same time it also 
seems potentially confusing.  vector(1, 2, 3) as well.  And, in the
particular case of initializing variables there's {1, 2, 3}, which
is the only place that syntax seems to be allowed in C.

It's really the complicated alists and other forms that this syntax is
intended for.  In many cases the quasiquote is called for in these
cases anyway, so maybe that should be the supported syntax.

> which translates to (list* t1 t2 ... tn).  If this doesn't work out,
> because the parentheses and the comma is already used too much, I
> would probably use bruces instead of parens, errm braces instead of
> parens.
> 
> For vectors, I would use square brackets:
> 
>     [ a, b, c ]
> 
> I think that people who are attracted by a C-like syntax are more
> comfortable with vectors than with lists, so maybe we should make
> vectors easy and visually clean to use.  On the other hand, we might
> want to encourage them to use lists.

I think they are more comfortable with vectors because they are easier
in C.  I definately want x[10] to work if x is a vector *or* a list.
Lists are called for more often in Scheme than vectors, and even in
a C-like language people are going to be constructing more lists than
vectors.

> > Functions that take variable number of arguments:
> >   function foo(arg1, arg_rest*) ...
> 
> What about
> 
>     foo (arg1, arg2; arg_rest)
>     {
>       // arg_rest is a list of all rest arguments here
>     }
> 
> that is, deliminate the rest argument with a semicolon.  This would
> rhyme with the use of the semicolon above, but it is not very visible
> when browsing code.

This just feels like packing too much meaning into ";" that isn't
typically there.

> > Keyword arguments (and function definitions): ??
> 
> What about using a keyword to signify keyqord arguments?
> 
>     foo (arg1 = def1; key key2 = def2, key3 = def3; rest arg_rest)
>     {
>       ...
>     }
> 
> translates to
> 
>     (define* (foo :optional (arg1 def1) :key (key2 def2) (key3 def3)
>                   :rest arg_rest)
>       ...)
> 
> and
> 
>     foo (val1, key3: val3)
> 
> translates to
> 
>     (foo val1 :key3 val3)
> 
> 
> The complete specification of function arguments could be
> 
>     function_definition ::= identifier (arg_list) '{' ... '}'
> 
>     arg_list ::= <empty>
>                | arg_list_part ( ';' arg_list_part ) *
> 
>     arg_list_part ::= arg ( ',' arg ) *
>                    | 'key' arg ( ',' arg ) *
>                    | 'rest' identifier                 
> 
>     arg ::= identifier { '=' expression }
> 
> With the following additional rules
> 
>     arg_list_parts after the first one must either be `key' or `rest'
>     parts.
> 
>     There can be at most one `key' part and at most one `rest' part.

It seems like it would be clearer to make people use `key' for each
keyword.  I'd probably also use `keyword' instead of `key', since I
don't want to steal the use of `key' as a variable name.  The other
thing is that it is potentially unambiguous if it was just

  function foo(x, y, bar=10) {...}
  foo(10, 20, bar: 10)

This is what Python does.  OTOH, unlike Python the call on the function
has to include the keyword arguments with a `:' (as opposed to
foo(10, 20, bar=10)) because assignment is a proper expression.  This
detracts from the value of this syntax significantly.

A mysterious part of the C syntax I found was `...', which apparently
can come at the end of a function definition, as in:

  int foo(x, y, ...) {...}

I've never seen this used, so I don't know what it is.  Maybe something
like `rest'...?

>     When the last part is just a single identifier, and there are more
>     than one part, that last part is treated as a `rest' part.

I'm not clear what you mean here.


  -- Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]