Email list hosting service & mailing list manager

SRFI-177 vs. chibi's let-keywords Amirouche Boubekki (25 Oct 2019 11:53 UTC)
Re: SRFI-177 vs. chibi's let-keywords Marc Nieper-Wißkirchen (25 Oct 2019 12:00 UTC)
Re: SRFI-177 vs. chibi's let-keywords Lassi Kortela (25 Oct 2019 15:20 UTC)

Re: SRFI-177 vs. chibi's let-keywords Marc Nieper-Wißkirchen 25 Oct 2019 12:00 UTC

Am Fr., 25. Okt. 2019 um 13:54 Uhr schrieb Amirouche Boubekki
<xxxxxx@gmail.com>:
>
> What is the advantage of SRFI-177 compared to chibi's let-keywords.
>
> Here is the documentation that I found in the code:
>
> ;;> \macro{(let-keywords ls ((var [keyword] default) ... [rest]) body ...)}

Here, the matching definitely happens at runtime except for when you
have a good optimizing compiler.

The point is that the dispatching happens solely at the callee's site,
while the call itself is an ordinary procedure call.

> ;;>
> ;;> Analogous to \scheme{let-optionals}, except instead of binding the
> ;;> \var{var}s by position they are bound by name, by searching in
> ;;> \var{ls} with \scheme{keyword-ref*}. If an optional \var{keyword}
> ;;> argument is provided it must be an identifier to use as the name,
> ;;> otherwise \var{var} is used, appending a ":" (colon). If the name
> ;;> is not found, \var{var} is bound to \var{default}, even if unused
> ;;> names remain in \var{ls}.
> ;;>
> ;;> If an optional trailing identifier \var{rest} is provided, it is
> ;;> bound to the list of unused arguments not bound to any \var{var}.
> ;;>
> ;;> Note R7RS does not have a disjoint keyword type or auto-quoting
> ;;> syntax for keywords - they are simply identifiers. Thus when
> ;;> passing keyword arguments they must be quoted (or otherwise
> ;;> dynamically evaluated).
> ;;>
> ;;> \emph{Example:}
> ;;> \example{
> ;;> (define (make-person . o)
> ;;> (let-keywords o ((name "John Doe")
> ;;> (age 0)
> ;;> (occupation job: 'unemployed))
> ;;> (vector name age occupation)))
> ;;>
> ;;> (list (make-person)
> ;;> (make-person 'name: "Methuselah" 'age: 969)
> ;;> (make-person 'name: "Dr. Who" 'job: 'time-lord 'age: 1500))
> ;;> }
> ;;>
> ;;> \emph{Example:}
> ;;> \example{
> ;;> (let-keywords '(b: 2 a: 1 other: 9)
> ;;> ((a 0) (b 0) (c 0) rest)
> ;;> (list a b c rest))
> ;;> }
>
> Thanks!
>
> ref: https://github.com/ashinn/chibi-scheme/blob/master/lib/chibi/optional.scm