Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let APPLY take keyword arguments #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shawwn
Copy link
Contributor

@shawwn shawwn commented Oct 6, 2019

This PR adds the following tests (which now pass):

  (let f (fn (a :b) (+ (or a 1) b))
    (test= 3 (apply f b: 2))
    (test= 3 (apply f '(1) b: 2))
    (test= 3 (apply f '(1 b: 42) b: 2))
    (test= 3 (apply f 1 '(b: 42) b: 2))
    (test= 3 (apply f 1 '(b: 2))))

Letting apply take keyword arguments is a handy way to forward arguments while overriding keyword values:

(define-global foo (args :name)
  (list name: name args: args))

(define-global bar args
  (apply foo name: 'bar (list args)))
> (bar 1 2)
(name: "bar" args: (1 2))
> (bar 1 2 name: "ignored")
(name: "bar" args: (1 2 name: "ignored"))

@shawwn
Copy link
Contributor Author

shawwn commented Oct 6, 2019

Sorry, I messed up the forwarding example. I meant:

(define-global foo (args :name)
  (list name: name args: args))

(define-global bar args
  (apply foo name: 'bar args))
> (bar 1)
(name: "bar" args: 1)
> (bar 1 name: 'ignored)
(name: "bar" args: 1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant