
Just a thought experiment—very likely this has been discussed multiple times already: How do you feel about replacing . rest
arguments in function headers and calls with a special #:rest
keyword?

That would avoid the special syntax treatment of dot notation, leaving its used to constructing quoted data

but what if I want to use a keyword #:rest
?!?!?

I always hate dotted pair, but it’s so tightly integrated (at the reader level) that I don’t think it’s possible to take them out.

Then you’re doooooomed :stuck_out_tongue:


Here’s a recent question on StackOverflow asking why (quasiquote (1 unquote 2))
produces '(1 . 2)

Yeah, these can easily get tricky indeed

But I’m okayish with it for data dsl, as it can be very useful, in particular splicing ,@

(admittedly this is not strictly dot notation)

My general thought on this matter is that I like Python’s function application a lot.

You don’t need a special apply
or keyword-apply

There’s only function application

And that suffices for everything

I like it too

*args
and **kwargs
could easily be mimicked with special keywords #:args
and #:kwargs
(in an even more unified interface that python’s special syntax with *
and **
)

#:args
or #:pos-args
would be the the whole list of positional arguments, while #:rest
would be the remaining ones after given positional arguments

These can appear both in a function header and in a function call. But if giving #:args
in a call, then no other positional argument should be specified—something like that.

Of course having #:args
and such in calls would require redefining #%app
(at least to have good error messages)

What about this?

#lang racket
(define (f a [b] [c 'c] [d 'd] #:args args #:kwargs kwargs)
(list a b c d args kwargs))
(f 'a 'args0 'args1 #:b 'b #:c 'c* #:e 'kwargs0 #:f 'kwargs1)
; 'a 'b 'c* 'd '(args0 args1) (hash 'e 'kwargs0 'f 'kwargs1)

Doesn’t support positional optional argument. Keyword and its corresponding variable name coincide.

Coerce keyword to symbol in kwargs (users should not need to deal with keyword?
at all… unless they write a macro that manipulates keywords)

I think one reason Racket’s app and function definition are the way they are is that they want to maintain symmetry between the definition site and application site

which I think is nice, but not terribly useful

I was thinking something a little different, but breaking a little the symmetry.

positional arguments don’t have names in function calls (like it is now)

I’m waiting to hear “de Bruijn index” from you :wink:

let me google it again :smile:

haha yeah, no :smile:

By names I meant keyword names

So (define (f a b)...)
cannot be called with (f #:a 'a #:b 'b)
.

#lang racket
(define (f a b [c 'c] [d 'd] #:args args #:kwargs kwargs)
(list a b c d args kwargs))
(f 'a 'b 'c #:d 'dd)
; (f 'a 'b 'c 'd #:args '(a b c d) #:kwargs '((d . dd)))
(edit [b] -> b)

and #lang racket
(define (f a [b] [c 'c] [d 'd] #:args args #:kwargs kwargs #:rest rest)
(list a b c d args kwargs rest))
(f 'a 'b 'c 'd2 'e 'f #:d 'dd)
; (f 'a 'b 'c 'd2 #:args '(a b c d2 e f) #:kwargs '((d . dd)) #:rest '(e f))

No kw-rest
?

yes, sounds good

If #:kwargs
is used in a call, then no other keyword argument (including #:kwrest
) can be used. Similarly to #:args

If #:kwrest
is used in a call, then the other mandatory keyword arguments must be still be provided

The nice thing about this design is that it should be almost entirely backward compatible with Racket (except for the special keyword names) and can easily revert to Racket’s calls and definitions when the special keywords are not used

That means it keeps Racket’s efficiency, unless you need more flexibility

(define (f a [b 'b] #:rest r)
(list a b r))
(f 'a #:rest '(x y)) ; = (f 'a 'b #:rest '(x y))
(f 'a 'x 'y) ; = (f a x #:rest '(y))
Is this sensible?

You want to support optional positional arg, right? If so, then yeah, this makes sense

Yes, mostly for backward compatibility though. You got me thinking that they’re often not that great.

Instead of a #:rest
keyword, my lang has ...
after a rest argument. (I still need to implement kw...
for kwargs). It was easy to translate it into apply
, just a short #%app
extension.

(On account of that, my lang doesn’t even provide apply
.)

I’m definitely a fan of using ellipses for this