Skip to content

Commit

Permalink
Turn Python keyword arguments into Lisp keyword arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
scymtym committed Jul 15, 2019
1 parent c4f8a30 commit bd40f9a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ modules, like this:
>>> cl.cons(5, None)
List(5)
>>> cl.remove(5, [1, 5, 2, 7, 5, 9])
>>> cl.remove(5, [1, -5, 2, 7, 5, 9], key=cl.abs)
[1, 2, 7, 9]
# Higher-order functions work, too!
Expand Down
8 changes: 6 additions & 2 deletions cl4py/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,9 @@ def __del__(self):
except:
pass

def __call__(self, *args):
return self.lisp.eval(List(Symbol('FUNCALL', 'CL'), Quote(self), *[Quote(arg) for arg in args]))
def __call__(self, *args, **kwargs):
restAndKeys = [ Quote(arg) for arg in args ]
for key, value in kwargs.items():
restAndKeys.append(Keyword(key.upper()))
restAndKeys.append(Quote(value))
return self.lisp.eval(List(Symbol('FUNCALL', 'CL'), Quote(self), *restAndKeys))

0 comments on commit bd40f9a

Please sign in to comment.