The cl-cut Reference Manual

Table of Contents

Next: , Previous: , Up: (dir)   [Contents][Index]

The cl-cut Reference Manual

This is the cl-cut Reference Manual, version 1.0.0, generated automatically by Declt version 2.3 "Robert April" on Wed Mar 14 03:14:02 2018 GMT+0.


Next: , Previous: , Up: Top   [Contents][Index]

1 Introduction

cl-cut

Build Status Quicklisp

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)))

Similar projects

Dependencies

Unit tests depend on prove.

Installation

Cl-cut can be installed via Quicklisp:

(ql:quickload :cl-cut)

License

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: , Previous: , Up: Top   [Contents][Index]

2 Systems

The main system appears first, followed by any subsystem dependency.


Previous: , Up: Systems   [Contents][Index]

2.1 cl-cut

Author

Cromachina

License

MIT

Description

Macros for partial application of expressions in the spirit of SRFI 26.

Version

1.0.0

Source

cl-cut.asd (file)

Component

cl-cut.lisp (file)


Next: , Previous: , Up: Top   [Contents][Index]

3 Files

Files are sorted by type and then listed depth-first from the systems components trees.


Previous: , Up: Files   [Contents][Index]

3.1 Lisp


Next: , Previous: , Up: Lisp files   [Contents][Index]

3.1.1 cl-cut.asd

Location

/home/quickbuilder/quicklisp/dists/quicklisp/software/cl-cut-20180131-git/cl-cut.asd

Systems

cl-cut (system)


Previous: , Up: Lisp files   [Contents][Index]

3.1.2 cl-cut/cl-cut.lisp

Parent

cl-cut (system)

Location

cl-cut.lisp

Packages

cl-cut

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

4 Packages

Packages are listed by definition order.


Previous: , Up: Packages   [Contents][Index]

4.1 cl-cut

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

Source

cl-cut.lisp (file)

Nickname

cut

Use List

common-lisp

Exported Definitions
Internal Definitions

Next: , Previous: , Up: Top   [Contents][Index]

5 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


Next: , Previous: , Up: Definitions   [Contents][Index]

5.1 Exported definitions


Previous: , Up: Exported definitions   [Contents][Index]

5.1.1 Macros

Macro: cut SLOT-OR-EXPR &rest SLOT-OR-EXPR*

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))

Package

cl-cut

Source

cl-cut.lisp (file)

Macro: cut* SLOT-OR-EXPR &rest SLOT-OR-EXPR*

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))

Package

cl-cut

Source

cl-cut.lisp (file)

Macro: cute SLOT-OR-EXPR &rest SLOT-OR-EXPR*

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)))

Package

cl-cut

Source

cl-cut.lisp (file)

Macro: cute* SLOT-OR-EXPR &rest SLOT-OR-EXPR*

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)))

Package

cl-cut

Source

cl-cut.lisp (file)


Previous: , Up: Definitions   [Contents][Index]

5.2 Internal definitions


Next: , Previous: , Up: Internal definitions   [Contents][Index]

5.2.1 Special variables

Special Variable: *rest-slot-name*
Package

cl-cut

Source

cl-cut.lisp (file)

Special Variable: *slot-name*
Package

cl-cut

Source

cl-cut.lisp (file)


Previous: , Up: Internal definitions   [Contents][Index]

5.2.2 Functions

Function: cut-internal FUNCTION ARGUMENTS FUNCALLP
Package

cl-cut

Source

cl-cut.lisp (file)

Function: cute-internal FUNCTION ARGUMENTS FUNCTION-AS-VALUE
Package

cl-cut

Source

cl-cut.lisp (file)

Function: rest-slotp FORM
Package

cl-cut

Source

cl-cut.lisp (file)

Function: slotp FORM
Package

cl-cut

Source

cl-cut.lisp (file)

Function: symbol-name-eq FORM NAME
Package

cl-cut

Source

cl-cut.lisp (file)


Previous: , Up: Top   [Contents][Index]

Appendix A Indexes


Next: , Previous: , Up: Indexes   [Contents][Index]

A.1 Concepts

Jump to:   C   F   L  
Index Entry  Section

C
cl-cut.asd: The cl-cut<dot>asd file
cl-cut/cl-cut.lisp: The cl-cut/cl-cut<dot>lisp file

F
File, Lisp, cl-cut.asd: The cl-cut<dot>asd file
File, Lisp, cl-cut/cl-cut.lisp: The cl-cut/cl-cut<dot>lisp file

L
Lisp File, cl-cut.asd: The cl-cut<dot>asd file
Lisp File, cl-cut/cl-cut.lisp: The cl-cut/cl-cut<dot>lisp file

Jump to:   C   F   L  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.2 Functions

Jump to:   C   F   M   R   S  
Index Entry  Section

C
cut: Exported macros
cut*: Exported macros
cut-internal: Internal functions
cute: Exported macros
cute*: Exported macros
cute-internal: Internal functions

F
Function, cut-internal: Internal functions
Function, cute-internal: Internal functions
Function, rest-slotp: Internal functions
Function, slotp: Internal functions
Function, symbol-name-eq: Internal functions

M
Macro, cut: Exported macros
Macro, cut*: Exported macros
Macro, cute: Exported macros
Macro, cute*: Exported macros

R
rest-slotp: Internal functions

S
slotp: Internal functions
symbol-name-eq: Internal functions

Jump to:   C   F   M   R   S  

Next: , Previous: , Up: Indexes   [Contents][Index]

A.3 Variables

Jump to:   *  
S  
Index Entry  Section

*
*rest-slot-name*: Internal special variables
*slot-name*: Internal special variables

S
Special Variable, *rest-slot-name*: Internal special variables
Special Variable, *slot-name*: Internal special variables

Jump to:   *  
S  

Previous: , Up: Indexes   [Contents][Index]

A.4 Data types

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