Last active
July 15, 2019 15:02
-
-
Save scymtym/27ff09ffbb1b5a1b6dcbad6f13e96f6c to your computer and use it in GitHub Desktop.
Keyword arguments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LispWrapper (LispObject): | |
def __init__(self, lisp, handle): | |
self.lisp = lisp | |
self.handle = handle | |
def __del__(self): | |
try: | |
self.lisp.eval('#{}!'.format(self.handle)) | |
except: | |
pass | |
def __call__(self, *args, **kwargs): | |
restAndKeys = [] | |
for arg in args: | |
restAndKeys.append(Quote(arg)) | |
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> cl.find(1, [1,2,3,4], test=cl.eql, key=cl.identity) | |
1 | |
>>> cl.find(1, [2,3,4], test=cl.eql, key=cl.constantly(1)) | |
2 | |
>>> cl.find(1, [2,3,4], test=cl.eql, key=cl.abs) | |
() | |
>>> cl.find(1, [-1,2,3,4], test=cl.eql, key=cl.abs) | |
-1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment