[plt-scheme] keywords (a possible alternative?)
Where in time, the generalized form could even support typed arguments
and/or default values:
(define (function (: sum <number> 0) (: values (<list> <number> ...))
(let (loop (sum sum) (value (if (pair? values) (car values) #f)))
(if value (loop (+ sum value) (cdr values)) sum)))
(function (: values 1 2 3 4) (:sum 0))
=> 10
(function (: values 1 2 3 4))
=> 10
(function (: values 1 2 'a))
=> <void>
;; error "values" argument expected (<list> <number>), received <symbol> "a"
> Personally I dislike colon prefix keywords, as to me colons tend to imply
> an association between elements, therefore a postfix positioning seems most
> visually natural (but of course subject to the same incompatibilities).
>
> However, wonder if something along the line of:
>
> (function (: keyword expression) ...)
>
> Might be both more syntactically consistent with the language; and enable
> keywords to be bound to argument expression lists, which a pre/post-fixed
> keyword association couldn't syntactically naturally support.
>
> (function (: keyword expression ...) ...)
>
> As just a thought ???