-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrying.lisp
More file actions
27 lines (22 loc) · 852 Bytes
/
Copy pathcurrying.lisp
File metadata and controls
27 lines (22 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
(defpackage :currying
(:use :cl)
(:export :enable-currying-syntax :disable-currying-syntax))
(in-package :currying)
(defun curry-function (exp)
(let ((name (car exp))
(used-args (cdr exp))
(remaining-args (gensym)))
`(lambda (&rest ,remaining-args)
(apply #',name ,@used-args ,remaining-args))))
(defun |#p-reader| (stream subchar arg)
(declare (ignore subchar arg))
(let ((exp (read stream)))
(curry-function exp)))
(defmacro enable-currying-syntax ()
`(eval-when (:compile-toplevel :load-toplevel :execute)
(defvar *previous-readtables* nil)
(push *readtable* *previous-readtables*)
(set-dispatch-macro-character #\# #\p #'|#p-reader|)))
(defmacro disable-currying-syntax ()
`(eval-when (:compile-toplevel :load-toplevel :execute)
(setf *readtable* (pop *previous-readtables*))))