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?


Ian Bicking <bickiia@cs.earlham.edu> writes:

> 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 '}'.

> 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.)

> 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 )

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.

> 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.

> 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.

    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'll comment on the rest later.

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