Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the cl-cut Reference Manual, version 1.0.0, generated automatically by Declt version 3.0 "Montgomery Scott" on Tue Dec 22 12:12:03 2020 GMT+0.
• Introduction | What cl-cut is all about | |
• Systems | The systems documentation | |
• Files | The files documentation | |
• Packages | The packages documentation | |
• Definitions | The symbols documentation | |
• Indexes | Concepts, functions, variables and data types |
This package provides a set of macros for partially applying functions and expressions like in SRFI 26. In addition to the two macros that the Scheme document specifies, two more are added for Common Lisp to accomodate the separate function and value namespaces.
This is best explained by examples (modified from the SRFI 26 document):
(cut cons (+ a 1) <>) => (lambda (x2) (cons (+ a 1) x2))
(cut list 1 <> 3 <> 5) => (lambda (x2 x4) (list 1 x2 3 x4 5))
(cut list) => (lambda () (list))
(cut list 1 <> 3 <...>) => (lambda (x2 &rest xs) (apply #'list 1 x2 3 xs))
(cut <> a b) => (lambda (f) (funcall f a b))
Special forms like IF
can work too, but only when in the function positon and without a rest argument.
(cut if <> a b) => (lambda (x2) (if x2 a b))
CUT*
treats the function argument as a value holding a function.
(cut* cons (+ a 1) <>) => (lambda (x2) (funcall cons (+ a 1) x2))
(cut* list 1 <> 3 <> 5) => (lambda (x2 x4) (funcall list 1 x2 3 x4 5))
(cut* list) => (lambda () (funcall list))
(cut* list 1 <> 3 <...>) => (lambda (x2 &rest xs) (apply list 1 x2 3 xs))
(cut* <> a b) => (lambda (f) (funcall f a b))
CUTE
evaluates arguments of the application only once, except the function argument.
(cute cons (+ a 1) <>) => (let ((z1 (+ a 1))) (lambda (x2) (cons z1 x2)))
(cute list 1 <> 3 <> 5) => (let ((z1 1) (z2 3) (z3 5)) (lambda (x2 x4) (list z1 x2 z2 x4 z3)))
(cute list) => (lambda () (list))
(cute list 1 <> 3 <...>) => (let ((z1 1) (z2 3)) (lambda (x2 &rest xs) (apply #'list z1 x2 z2 xs)))
(cute <> a b) => (let ((z1 a) (z2 b)) (lambda (f) (funcall f z1 z2)))
CUTE*
is like CUTE
but treats the function argument as a value as well.
(cute* cons (+ a 1) <>) => (let ((f1 cons) (z1 (+ a 1))) (lambda (x2) (funcall f1 z1 x2)))
(cute* list 1 <> 3 <> 5) => (let ((f1 list) (z1 1) (z2 3) (z3 5)) (lambda (x2 x4) (funcall f1 z1 x2 z2 x4 z3)))
(cute* list) => (let ((f1 list)) (lambda () (funcall f1)))
(cute* list 1 <> 3 <...>) => (let ((f1 list) (z1 1) (z2 3)) (lambda (x2 &rest xs) (apply f1 z1 x2 z2 xs)))
(cute* <> a b) => (let ((z1 a) (z2 b)) (lambda (f) (funcall f z1 z2)))
Unit tests depend on prove.
Cl-cut can be installed via Quicklisp:
(ql:quickload :cl-cut)
Copyright (c) 2015 Cromachina
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE
Next: Files, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The cl-cut system |
Cromachina
MIT
Macros for partial application of expressions in the spirit of SRFI 26.
1.0.0
cl-cut.asd (file)
cl-cut.lisp (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files |
• The cl-cut.asd file | ||
• The cl-cut/cl-cut.lisp file |
Next: The cl-cut/cl-cut․lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
/home/quickref/quicklisp/dists/quicklisp/software/cl-cut-20180131-git/cl-cut.asd
cl-cut (system)
Previous: The cl-cut․asd file, Up: Lisp files [Contents][Index]
cl-cut (system)
cl-cut.lisp
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The cl-cut package |
Utilities to partially apply functions or expressions in the spirit of ‘Scheme SRFI 26: Notation for Specializing Parameters without Currying’ http://srfi.schemers.org/srfi-26/srfi-26.html
cl-cut.lisp (file)
cut
common-lisp
Definitions are sorted by export status, category, package, and then by lexicographic order.
• Exported definitions | ||
• Internal definitions |
Next: Internal definitions, Previous: Definitions, Up: Definitions [Contents][Index]
• Exported macros |
Previous: Exported definitions, Up: Exported definitions [Contents][Index]
CUT partially applies its first argument, which can be a symbol (which is
treated as a function) or an expression that evaluates to a function. Any
argument of CUT that appears as a slot ‘<>’ will be a positional argument
of the resulting partially applied function, even for the first argument (the
function position). A special slot ‘<...>’ can be the last argument of CUT
which is then treated as a REST argument for the partial application.
Example expansions:
(mapcar (cut member <> (list a b c) :test ’equal) things-to-find)
=>
(MAPCAR (LAMBDA (#:SLOT-1)
(MEMBER #:SLOT-1 (LIST A B C) :TEST ’EQUAL))
THINGS-TO-FIND)
(cut + <> (+ x 1) <>)
=>
(LAMBDA (#:SLOT-1 #:SLOT-2)
(+ #:SLOT-1 (+ X 1) #:SLOT-2))
(cut <> 1 2 3 <>)
=>
(LAMBDA (#:SLOT-1 #:SLOT-2)
(FUNCALL #:SLOT-1 1 2 3 #:SLOT-2))
(cut + 1 x <...>)
=>
(LAMBDA (&REST #:REST-SLOT-1)
(APPLY #’+ 1 X #:REST-SLOT-1))
(cut <> 1 x <...>)
=>
(LAMBDA (#:SLOT-1 &REST #:REST-SLOT-2)
(APPLY #:SLOT-1 1 X #:REST-SLOT-2))
(cut (if (= 0 (random 10)) #’+ #’-) 10 <...>)
=>
(LAMBDA (&REST #:REST-SLOT-1)
(APPLY
(IF (= 0 (RANDOM 10))
#’+
#’-)
10 #:REST-SLOT-1))
(cut (cut <> <>) <> <>)
=>
(LAMBDA (#:SLOT-1 #:SLOT-2)
(FUNCALL (LAMBDA (#:SLOT-3 #:SLOT-4) (FUNCALL #:SLOT-3 #:SLOT-4))
#:SLOT-1 #:SLOT-2))
cl-cut.lisp (file)
Like CUT, but treats a non-slot symbol in the first argument as a value
instead of a function. Examples:
(mapcar (cut* member <> (list a b c) :test ’equal) things-to-find)
=>
(MAPCAR (LAMBDA (#:SLOT-1195)
(FUNCALL MEMBER #:SLOT-1195 (LIST A B C) :TEST ’EQUAL))
THINGS-TO-FIND)
(let ((some-func (lambda (x y) (- x y))))
(cut* some-func <> 1))
=>
(LET ((SOME-FUNC (LAMBDA (X Y) (- X Y))))
(LAMBDA (#:SLOT-1) (FUNCALL SOME-FUNC #:SLOT-1 1)))
(cut* list ’a <...>)
=>
;; Notice LIST and not #’LIST, which may cause an error.
(LAMBDA (&REST #:REST-SLOT-1)
(APPLY LIST ’A #:REST-SLOT-1))
(cut* <> ’a ’b)
=>
;; Same as (cut <> ’a ’b).
(LAMBDA (#:SLOT-1)
(FUNCALL #:SLOT-1 ’A ’B))
cl-cut.lisp (file)
Like CUT, but evaluates all arguments except the first. Examples:
(mapcar (cute member <> (list a b c) :test ’equal) things-to-find)
=>
(MAPCAR (LET ((#:LET-BINDING-1 (LIST A B C))
(#:LET-BINDING-2 :TEST)
(#:LET-BINDING-3 ’EQUAL))
(LAMBDA (#:SLOT-4)
(MEMBER #:SLOT-1199 #:LET-BINDING-1196 #:LET-BINDING-1197
#:LET-BINDING-1198)))
THINGS-TO-FIND)
(cute list (if flag ’a ’b) <...>)
=>
(LET ((#:LET-BINDING-1
(IF FLAG ’A ’B)))
(LAMBDA (&REST #:REST-SLOT-2)
(APPLY #’LIST #:LET-BINDING-1 #:REST-SLOT-2)))
(cute <> 1 (complex-computation))
=>
(LET ((#:LET-BINDING-1 1)
(#:LET-BINDING-2 (COMPLEX-COMPUTATION)))
(LAMBDA (#:SLOT-3)
(FUNCALL #:SLOT-3 #:LET-BINDING-1 #:LET-BINDING-2)))
cl-cut.lisp (file)
Like CUTE, but evaluates all arguments as values, including the first
argument. Examples:
(mapcar (cute* member <> (list a b c) :test ’equal) things-to-find)
=>
(MAPCAR (LET ((#:LET-BINDING-1 MEMBER) ;; Notice how MEMBER is bound here.
(#:LET-BINDING-2 (LIST A B C))
(#:LET-BINDING-3 :TEST)
(#:LET-BINDING-4 ’EQUAL))
(LAMBDA (#:SLOT-5)
(FUNCALL #:LET-BINDING-1 #:SLOT-5 #:LET-BINDING-2 #:LET-BINDING-3
#:LET-BINDING-4)))
THINGS-TO-FIND)
(cute* some-value <> 10 <...>)
=>
(LET ((#:LET-BINDING-1 SOME-VALUE)
(#:LET-BINDING-2 10))
(LAMBDA (#:SLOT-3 &REST #:REST-SLOT-4)
(APPLY #:LET-BINDING-1 #:SLOT-3 #:LET-BINDING-2 #:REST-SLOT-4)))
(cute* <> ’foo <>)
=>
(LET ((#:LET-BINDING-1 ’FOO))
(LAMBDA (#:SLOT-2 #:SLOT-3)
(FUNCALL #:SLOT-2 #:LET-BINDING-1 #:SLOT-3)))
cl-cut.lisp (file)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal special variables | ||
• Internal functions |
Next: Internal functions, Previous: Internal definitions, Up: Internal definitions [Contents][Index]
cl-cut.lisp (file)
cl-cut.lisp (file)
Previous: Internal special variables, Up: Internal definitions [Contents][Index]
cl-cut.lisp (file)
cl-cut.lisp (file)
cl-cut.lisp (file)
cl-cut.lisp (file)
cl-cut.lisp (file)
Previous: Definitions, Up: Top [Contents][Index]
• Concept index | ||
• Function index | ||
• Variable index | ||
• Data type index |
Next: Function index, Previous: Indexes, Up: Indexes [Contents][Index]
Jump to: | C F L |
---|
Jump to: | C F L |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | C F M R S |
---|
Jump to: | C F M R S |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Jump to: | *
S |
---|
Jump to: | *
S |
---|
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | C P S |
---|
Index Entry | Section | ||
---|---|---|---|
| |||
C | |||
cl-cut : | The cl-cut system | ||
cl-cut : | The cl-cut package | ||
| |||
P | |||
Package, cl-cut : | The cl-cut package | ||
| |||
S | |||
System, cl-cut : | The cl-cut system | ||
|
Jump to: | C P S |
---|