Keywords #2

Open
wants to merge 7 commits into
from

1 participant

@DerGuteMoritz

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 "!" "."))
    (newline)))

(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