Skip to content

Instantly share code, notes, and snippets.

@scymtym
Last active July 15, 2019 15:02
Show Gist options
  • Save scymtym/27ff09ffbb1b5a1b6dcbad6f13e96f6c to your computer and use it in GitHub Desktop.
Save scymtym/27ff09ffbb1b5a1b6dcbad6f13e96f6c to your computer and use it in GitHub Desktop.
Keyword arguments
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))
>>> 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