Keywords #2

wants to merge 7 commits into

1 participant


This branch implements the keyword datatype. Keywords live in the same namespace as regular symbols but unlike them they are self-quoting. They end in :, e.g. foo: (some Scheme implementations also allow prefix notation as in #:foo; this branch only implements suffix notation though). They can be used to implement keyword function arguments. Silly example ahead:

(define (greet name . args)
  (let-keywords args ((separator ", ") enthusiastic)
    (display "Hello")
    (display separator)
    (display name)
    (display (if enthusiastic "!" "."))

(greet "James")
Hello, James.
(greet "James" enthusiastic: #t)
Hello, James!
(greet "James" enthusiastic: #t separator: " ... ")
Hello ... James!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment