The trestrul Reference Manual

Table of Contents

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

The trestrul Reference Manual

This is the trestrul Reference Manual, version 0.0.7, generated automatically by Declt version 3.0 "Montgomery Scott" on Fri Jun 26 12:27:45 2020 GMT+0.


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

1 Introduction

TRESTRUL 0.0.6

What is this?

Tiny utilities for TREe-STRUctured-List.

Current lisp world

List is very flexible. It can be represented as tree too.

Issues

Although CL lacks operators for tree structured list.

IMO: Reason of lackness may it is tough to get consensus about tree operations. In lisp, list is constructed by CONS. Consider removing 1 from '(1 . 2). Additionally, if it is tree, we can represents nested list as node. If so '(nil) contains one node? or two node?

Proposal

TRESTRUL provides it.

Usage

From developer

Product's goal

merged by other utility libraries such as alexandria

License

Public Domain

Tested with

SBCL/2.0.2 CCL/1.12 CLISP/2.49 ECL/20.4.24


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 trestrul

Author

Shinichi Sato

License

Public Domain

Description

Tiny utilities for TREe-STRUctured-List.

Long Description

# TRESTRUL 0.0.6

## What is this?
Tiny utilities for TREe-STRUctured-List.

## Current lisp world
List is very flexible.
It can be represented as tree too.

## Issues
Although CL lacks operators for tree structured list.

IMO: Reason of lackness may it is tough to get consensus about tree operations. In lisp, list is constructed by CONS.
Consider removing 1 from ’(1 . 2).
Additionally, if it is tree, we can represents nested list as node.
If so ’(nil) contains one node? or two node?

## Proposal
TRESTRUL provides it.

## Usage

## From developer

### Product’s goal
merged by other utility libraries such as alexandria
### License
Public Domain

### Tested with
SBCL/2.0.2
CCL/1.12
CLISP/2.49
ECL/20.4.24

Version

0.0.7

Source

trestrul.asd (file)

Component

trestrul.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 trestrul.asd

Location

trestrul.asd

Systems

trestrul (system)


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

3.1.2 trestrul/trestrul.lisp

Parent

trestrul (system)

Location

trestrul.lisp

Packages

trestrul

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 trestrul

Source

trestrul.lisp (file)

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


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

5.1.1 Macros

Macro: dotree (VAR TREE &optional RETURN) &body BODY

# DOTREE

## Description:
iterate body with var bound by each leaf of TREE.

“‘lisp
#?(dotree (l ’(1 2 . 3))
(princ l))
:outputs "123"
“‘

### syntax
(DOTREE (var tree &optional return) &body body)
=> result

## Arguments and Values:
var := symbol which bound by each leaf. otherwise error.

“‘lisp
#?(dotree (0 ’(1 2 . 3))
(princ 0))
:signals error
“‘
tree := tree generate form. Not evaluated.
When the form does not generate tree structured list,
an error is signaled.

“‘lisp
#?(dotree (l ’tree)
(princ l))
:signals invalid-tree
, :ignore-signals
“‘
return := return form which evaluated only once after iteration.

“‘lisp
#?(dotree (l ’(1 2 . 3) :result)
(princ l))
=> :RESULT
, :stream
“‘
body := implicit progn
result := return value of RETURN. The default is nil.

“‘lisp
#?(dotree (l ’(1 2 . 3))
(1+ l))
=> NIL
“‘

## Affected By:
none

## Side-Effects:
none

## Notes:
can declare about VAR at top of BODY.

“‘lisp
#?(dotree (l ’(1 2 . 3))
(declare (type fixnum l))
(princ l))
:outputs "123"
“‘
VAR is able to see from RETURN form,
but VAR is bound NIL in such time.

“‘lisp
#?(dotree (l ’(1 2 . 3) (princ l))
(1+ l))
:outputs "NIL"
“‘
BLOCK named NIL is implicitly established.
So RETURN is able to be used.

“‘lisp
#?(dotree (l ’(1 2 3 4))
(if (= 3 l)
(return)
(princ l)))
:outputs "12"
“‘
When empty tree comes, only return form is evaluated.

“‘lisp
#?(dotree (l () :hoge)
(princ l))
=> :hoge
“‘
When CL:RETURN is called, RETURN form is not evaluated.

“‘lisp
#?(dotree (l ’(1 2 3 4) (princ l))
(if (= l 3)
(return)
(princ l)))
:outputs "12"
“‘
TAGBODY is implicitly established.
So GO is able to be used in body.

“‘lisp
#?(dotree (l ’(1 2 3 4))
(if (= 3 l)
(go 3)
(go :end))
3
(princ l)
:end
(princ l))
:outputs "12334"
“‘

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)


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

5.1.2 Compiler macros

Compiler Macro: mapleaf FUN TREE
Package

trestrul

Source

trestrul.lisp (file)

Compiler Macro: nmapleaf FUN TREE
Package

trestrul

Source

trestrul.lisp (file)

Compiler Macro: remove-leaf-if FUNCTION TREE &key KEY KEEP
Package

trestrul

Source

trestrul.lisp (file)


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

5.1.3 Functions

Function: ansubst SUBSTITUTER TARGET TREE &key TEST KEY

# ASUBST, ANSUBST

## Description:
Substitute tree with applying substituter.

“‘lisp
#?(op #’princ-to-string 1 ’(1 2 3 1 2 3))
=> ("1" 2 3 "1" 2 3)
, :test
“‘

### syntax
(OP substituter target tree &key (test #’eql) (key #’identity))
=> result

## Arguments and Values:
substituter := function-designator which designates the function which accepts one argument.
If it is not function-designator, an error is signaled.

“‘lisp
#?(op :not-function-designator 1 ’(1 2 3))
:signals (or undefined-function
error ; for ccl
)
“‘
target := any lisp object.
tree := tree structured list, or leaf.

“‘lisp
#?(op #’princ-to-string :leaf :leaf)
=> "LEAF"
, :test
“‘
test := function designator which designates the function which accepts two arguments to test equality.

“‘lisp
#?(op #’parse-integer "0" ’("1" "2" "3" "0")
:test #’equal)
=> ("1" "2" "3" 0)
, :test
“‘
If it is not function designator, an error is signaled.

“‘lisp
#?(op #’identity 0 ’(1 2 3)
:test :not-function-designator)
:signals (or undefined-function
error ; for ccl
)
“‘
key := function designator which designates the function which accepts one argument.

“‘lisp
#?(op (constantly :zero) 0 ’("1" "2" "3" "0")
:key #’(lambda(x)
(if (stringp x)
(parse-integer x)
x)))
=> ("1" "2" "3" :ZERO)
, :test
“‘
result := see below.

## Affected By:
none

## Side-Effects:
none

## Notes:

## Exceptional-Situations:
# ASUBST
result := may newly consed substituted value.

“‘lisp
#?(let ((tree ’(:a :b :c)))
(eq tree (asubst (constantly :hoge)
:a
tree)))
=> NIL
“‘
# ANSUBST
result := may destructively modified substituted value.

“‘lisp
#?(let ((tree ’(:a :b :c)))
(eq tree (ansubst (constantly :hoge)
:a
tree)))
=> T
“‘

Package

trestrul

Source

trestrul.lisp (file)

Function: ansubst-if SUBSTITUTER PREDICATE TREE &key KEY
Package

trestrul

Source

trestrul.lisp (file)

Function: asubst SUBSTITUTER TARGET TREE &key TEST KEY

# ASUBST, ANSUBST

## Description:
Substitute tree with applying substituter.

“‘lisp
#?(op #’princ-to-string 1 ’(1 2 3 1 2 3))
=> ("1" 2 3 "1" 2 3)
, :test
“‘

### syntax
(OP substituter target tree &key (test #’eql) (key #’identity))
=> result

## Arguments and Values:
substituter := function-designator which designates the function which accepts one argument.
If it is not function-designator, an error is signaled.

“‘lisp
#?(op :not-function-designator 1 ’(1 2 3))
:signals (or undefined-function
error ; for ccl
)
“‘
target := any lisp object.
tree := tree structured list, or leaf.

“‘lisp
#?(op #’princ-to-string :leaf :leaf)
=> "LEAF"
, :test
“‘
test := function designator which designates the function which accepts two arguments to test equality.

“‘lisp
#?(op #’parse-integer "0" ’("1" "2" "3" "0")
:test #’equal)
=> ("1" "2" "3" 0)
, :test
“‘
If it is not function designator, an error is signaled.

“‘lisp
#?(op #’identity 0 ’(1 2 3)
:test :not-function-designator)
:signals (or undefined-function
error ; for ccl
)
“‘
key := function designator which designates the function which accepts one argument.

“‘lisp
#?(op (constantly :zero) 0 ’("1" "2" "3" "0")
:key #’(lambda(x)
(if (stringp x)
(parse-integer x)
x)))
=> ("1" "2" "3" :ZERO)
, :test
“‘
result := see below.

## Affected By:
none

## Side-Effects:
none

## Notes:

## Exceptional-Situations:
# ASUBST
result := may newly consed substituted value.

“‘lisp
#?(let ((tree ’(:a :b :c)))
(eq tree (asubst (constantly :hoge)
:a
tree)))
=> NIL
“‘
# ANSUBST
result := may destructively modified substituted value.

“‘lisp
#?(let ((tree ’(:a :b :c)))
(eq tree (ansubst (constantly :hoge)
:a
tree)))
=> T
“‘

Package

trestrul

Source

trestrul.lisp (file)

Function: asubst-if SUBSTITUTER PREDICATE TREE &key KEY

# ASUBST-IF

## Description:
substitute leaf which satisfies PREDICATE.

“‘lisp
#?(asubst-if #’princ-to-string
(lambda(x)
(unless (listp x)
(evenp x)))
’(1 2 3 4 5))
=> (1 "2" 3 "4" 5)
, :test
“‘

### syntax
(ASUBST-IF substituter predicate tree &key (key #’identity))
=> result

## Arguments and Values:
substituter := function designator which designates the function which accepts one argument. if it is not function designator, an error is signaled.

“‘lisp
#?(asubst-if :not-function-designator
(lambda(x)
(unless(listp x)
(numberp x)))
’(1 2 3 4 5))
:signals (or undefined-function
error ; for ccl
)
“‘
predicate := function designator which desigates the function which accepts one argument. if it is not funciton designator, an error is signaled.

“‘lisp
#?(asubst-if #’identity :not-function-designator ’(1 2 3))
:signals (or undefined-function
error ; for ccl
)
“‘
tree := leaf or tree structured list.

“‘lisp
#?(asubst-if #’symbol-name #’symbolp :hoge)
=> "HOGE"
, :test
“‘
key := function designator which designates the function which accepts one argument.
if it is not function designator, an error is signaled.

“‘lisp
#?(asubst-if ’string (complement #’symbol-package)
’(hoge :hoge #:hoge "HOGE")
:key #’(lambda(x)
(and (symbolp x)
x)))
=> (hoge :hoge "HOGE" "HOGE")
, :test
“‘

“‘lisp
#?(asubst-if #’string #’null ’(hoge :hoge #:hoge nil)
:key :not-function-designator)
:signals undefined-function
“‘
result := substituted leaf or tree.

## Affected By:
none

## Side-Effects:
none

## Notes:
Top level node (i.e. root) is also tested.

“‘lisp
#?(asubst-if (constantly :hoge) #’listp ’(:a :b :c))
=> :hoge
“‘

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)

Function: collect-node TARGET TREE &key KEY TEST RECURSIVE-P

# COLLECT-NODE

## Description:
collect node from TREE.

“‘lisp
#?(collect-node :export ‘(defpackage :hoge (:use :cl)
(:export :a :b :c)
(:export :d :e :f))
:key #’car)
=> ((:export :a :b :c) (:export :d :e :f))
, :test
“‘

### syntax
(COLLECT-NODE target tree &key (key #’identity) (test #’eql) recursive-p)
=> result

## Arguments and Values:
target := T
tree := tree structured list. Otherwise error.

“‘lisp
#?(collect-node :hoge :not-tree)
:signals invalid-tree
“‘
key := function designator which designates the function which accepts one node as argument. The default is CL:IDENTITY.
If it is not function designator, an error is signaled.

“‘lisp
#?(collect-node :use ’((:use :cl) (:export :a :b :c))
:key :not-function-designator)
:signals undefined-function
“‘
test := function designator which designates the function which accepts two arguments. The default is CL:EQL.
if it is not function-designator, an error is signaled.

“‘lisp
#?(collect-node ’(:use :cl) ’((:use :cl) (:export :a :b :c))
:test :not-function-designator)
:signals undefined-function
“‘
recursive-p := boolean which control whether call collect-node recursively or not.

“‘lisp
#?(collect-node :tag ’((:tag recursively (:tag)))
:key #’car)
=> ((:tag recursively (:tag)))
, :test
“‘

“‘lisp
#?(collect-node :tag ’((:tag recursively (:tag second)))
:key #’car
:recursive-p T)
=> ((:tag recursively (:tag second))
(:tag second))
, :test
“‘
result := list which may contains node.

## Affected By:
none

## Side-Effects:
none

## Notes:
When both :key and :test are not specified,
return form is always nil unless target is nil.

“‘lisp
#?(collect-node :tag ’((:tag 1 (:tag 2))))
=> NIL
“‘

“‘lisp
#?(collect-node nil ’((:tag 1 () (:tag 2 ()))))
=> (NIL NIL NIL NIL NIL)
“‘

#### i.e. ((:tag 1 NIL (:tag 2 NIL . NIL) . NIL) . NIL)

Works fine even if :recirsive-p T is specified (i.e. never infinite loop).

“‘lisp
#?(collect-node nil ’((:tag 1 NIL(:tag 2 NIL)))
:recursive-p T)
=> (NIL NIL NIL NIL NIL)
, :test
“‘

“‘lisp
#?(collect-node nil ’())
=> (NIL)
“‘
remember tree is one kind of node.

“‘lisp
#?(collect-node nil ’() :recursive-p t)
=> (NIL)
, :test
“‘

“‘lisp
#?(collect-node nil ’(NIL))
=> (NIL NIL)
“‘
remember (NIL) is (NIL . NIL)

“‘lisp
#?(collect-node nil ’(NIL) :recursive-p t)
=> (NIL NIL)
, :test
“‘

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)

Function: find-leaf TARGET TREE &key TEST KEY

# FIND-LEAF

## Description:
Find target from tree.

### syntax
(FIND-LEAF target tree &key (test #’eql) (key #’identity))
=> result

“‘lisp
#?(find-leaf 0 ’(1 (2 . 3) ((0))))
=> 0
“‘

## Arguments and Values:
target := T
tree := Tree, otherwise error.

“‘lisp
#?(find-leaf 0 0)
:signals error
“‘
test := Function as ‘(FUNCTION(T T)BOOLEAN)‘, the default is #’EQL. key := Function as ‘(FUNCTION(T)T)‘, the default is #’IDENTITY. result := T

## Affected By:
none

## Side-Effects:
none

## Notes:
Same as ‘CL:FIND‘, ‘FIND-LEAF‘ can not find ‘NIL‘.

“‘lisp
#?(find-leaf nil ’(()))
=> NIL
“‘

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)

Function: find-leaf-if PRED TREE &key KEY

# FIND-LEAF-IF

## Description:
Find element which satisfies PRED from TREE.

### syntax
(FIND-LEAF-IF pred tree &key (key #’identity))
=> result

“‘lisp
#?(find-leaf-if #’oddp ’(2 (3 . 4) 5))
=> 3
“‘

## Arguments and Values:
pred := function designator as (function(T)T).

“‘lisp
#?(find-leaf-if ’oddp ’(1 2 3))
=> 1
“‘
otherwise error

“‘lisp
#?(find-leaf-if "NOT-FUNCTION" ’(1 2 3))
:signals error
“‘
tree := tree structured list.
atom is not acceptable.

“‘lisp
#?(find-leaf-if #’oddp 1)
:signals error
“‘
key := function designator as (function(T)T).

“‘lisp
#?(find-leaf-if #’oddp ’("1" "2" "3") :key #’parse-integer) => "1"
, :test
“‘

“‘lisp
#?(find-leaf-if #’oddp ’("1" "2" "3") :key ’parse-integer) => "1"
, :test
“‘
otherwise error.

“‘lisp
#?(find-leaf-if #’oddp ’("1" "2" "3") :key "NOT-FUNCTION") :signals error
“‘
result := T

## Affected By:
none

## Side-Effects:
none

## Notes:

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)

Function: find-node-if PRED TREE &key COUNT RECURSIVE-P

# FIND-NODE-IF

## Description:
Find node which satisfies ‘PRED‘ from ‘TREE‘.

### syntax
(FIND-NODE-IF pred tree &key (count 1) recursive-p)
=> result

## Arguments and Values:
pred := Function designator as (function (list) boolean), otherwise error.

“‘lisp
#?(find-node-if "not function designator" ’(:dummy))
:signals error
“‘
tree := Tree, which include atom.

“‘lisp
#?(find-node-if #’identity "atom")
=> NIL
“‘
count := (integer 1 *), otherwise error.

“‘lisp
#?(find-node-if #’identity nil :count "not (integer 1 *)")
:signals error
“‘
‘COUNT‘ specify Nth value. The default is 1.

“‘lisp
#?(find-node-if (lambda(x) (typep x ’(cons (eql :a) *)))
’((:a 1) (:a 2) (:a 3)))
=> (:a 1)
, :test
“‘

“‘lisp
#?(find-node-if (lambda(x) (typep x ’(cons (eql :a) *)))
’((:a 1) (:a 2) (:a 3))
:count 2)
=> (:A 2)
, :test
“‘

“‘lisp
#?(find-node-if (lambda(x) (typep x ’(cons (eql :a) *)))
’((:a 1) (:a 2) (:a 3))
:count 3)
=> (:A 3)
, :test
“‘

“‘lisp
#?(find-node-if (lambda(x) (typep x ’(cons (eql :a) *)))
’((:a 1) (:a 2) (:a 3))
:count 4)
=> NIL
“‘
recursive-p := Generalized boolean. The default is ‘NIL‘.

“‘lisp
#?(find-node-if (lambda(x) (eq :a (car x)))
’((:a 1 :a 2 :a 3) (:a 4))
:count 2)
=> (:A 4)
, :test
“‘

“‘lisp
#?(find-node-if (lambda(x) (eq :a (car x)))
’((:a 1 :a 2 :a 3) (:a 4))
:count 2
:recursive-p t)
=> (:A 2 :A 3)
, :test
“‘
result := T

## Affected By:
none

## Side-Effects:
none

## Notes:

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)

Function: follow PATH TREE

# FOLLOW

## Description:

### syntax
(FOLLOW path tree)
=> result

“‘lisp
#?(let ((tree ’(1 (2 . 3) ((((4) . 5)))))) (follow (path-to 5 tree)
tree))
=> 5
“‘

## Arguments and Values:
path := ((function(list)T)*)
Expects return value of ‘PATH-TO‘.
When null, TREE is returned.

“‘lisp
#?(follow nil :a)
=> :A
“‘

“‘lisp
#?(follow nil ’(:a . :b))
=> (:A . :B)
, :test
“‘
tree := Tree structured list, include atom. i.e. T.

“‘lisp
#?(follow (list #’car) ’(:a . :b))
=> :A
“‘
result := T

## Affected By:

## Side-Effects:

## Notes:

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)

Function: mapleaf FUN TREE

# MAPLEAF, NMAPLEAF

### syntax
(OP fun tree)
=> result

## Description:
Apply FUN to every leaf of TREE.

“‘lisp
#?(op #’1+ ’(1 (2 . 3) . 4))
=> (2 (3 . 4) . 5)
, :test
“‘

## Arguments and Values:
fun := function which accepts one argument. Otherwise error.

“‘lisp
#?(op 0 ’(1 2 3 4))
:signals error
, :lazy
“‘
tree := tree structured list. Otherwise error.

“‘lisp
#?(op #’1+ 1)
:signals error
, :lazy
“‘
result := see below.

## Affected By:
none

## Side-Effects:
none

## Notes:

## Exceptional-Situations:
# MAPLEAF
result := newly consed tree structured list.

“‘lisp
#?(let ((tree ’(1 . 2)))
(eq tree (mapleaf #’identity tree)))
=> NIL
“‘
# NMAPLEAF

## Side-Effects:
argument TREE is destructively modified.

“‘lisp
#?(let ((tree ’(1 2 3)))
(eq tree (nmapleaf #’1+ tree)))
=> T
“‘

Package

trestrul

Source

trestrul.lisp (file)

Function: nmapleaf FUN TREE

# MAPLEAF, NMAPLEAF

### syntax
(OP fun tree)
=> result

## Description:
Apply FUN to every leaf of TREE.

“‘lisp
#?(op #’1+ ’(1 (2 . 3) . 4))
=> (2 (3 . 4) . 5)
, :test
“‘

## Arguments and Values:
fun := function which accepts one argument. Otherwise error.

“‘lisp
#?(op 0 ’(1 2 3 4))
:signals error
, :lazy
“‘
tree := tree structured list. Otherwise error.

“‘lisp
#?(op #’1+ 1)
:signals error
, :lazy
“‘
result := see below.

## Affected By:
none

## Side-Effects:
none

## Notes:

## Exceptional-Situations:
# MAPLEAF
result := newly consed tree structured list.

“‘lisp
#?(let ((tree ’(1 . 2)))
(eq tree (mapleaf #’identity tree)))
=> NIL
“‘
# NMAPLEAF

## Side-Effects:
argument TREE is destructively modified.

“‘lisp
#?(let ((tree ’(1 2 3)))
(eq tree (nmapleaf #’1+ tree)))
=> T
“‘

Package

trestrul

Source

trestrul.lisp (file)

Function: path-to ITEM TREE &key TEST

# PATH-TO

## Description:
Return list of function-names, which guide you to target item in the tree. Secondary value is foundp.

“‘lisp
#?(path-to 1 1)
:values (NIL T)
“‘

“‘lisp
#?(path-to 1 ’(1))
:values ((CAR) T)
“‘

“‘lisp
#?(path-to 1 ’(2))
:values (NIL NIL)
“‘

“‘lisp
#?(path-to 2 ’(1 . 2))
:values ((CDR) T)
“‘

### syntax
(PATH-TO item tree &key (test #’eql))
=> result

## Arguments and Values:
item := T
tree := Tree structured list, include atom. i.e. T.
test := (function(t t)generalized-boolean).
result := (values (function*) boolean)

## Affected By:
none

## Side-Effects:
none

## Notes:

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)

Function: proper-treep ARG

# PROPER-TREEP

## Description:
Tests arg is proper-tree.

“‘lisp
#?(proper-treep :leaf) => NIL
“‘

“‘lisp
#?(proper-treep ())
=> T
“‘

“‘lisp
#?(proper-treep ’(:a :b)) => T
“‘

“‘lisp
#?(proper-treep ’(:a . :b)) => NIL
“‘

### syntax (PROPER-TREEP arg)
=> result

## Arguments and Values: arg := any lisp object result := boolean

## Affected By:
none

## Side-Effects:
none

## Notes:

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)

Function: remove-leaf ITEM TREE &key TEST KEY KEEP

# REMOVE-LEAF

## Description:
remove specified LEAF from TREE.

“‘lisp
#?(remove-leaf 4 ’(1 2 3 (4)))
=> (1 2 3 ())
, :test
“‘

### syntax
(REMOVE-LEAF item tree &key (test #’eql) (key #’identity) (keep t))
=> result

## Arguments and Values:
item := non NIL atom, otherwise unspecified.

“‘lisp
#?(remove-leaf () ’(() 1 2))
=> unspecified
“‘
tree := tree structured list, otherwise error.

“‘lisp
#?(remove-leaf 1 1)
:signals invalid-tree
“‘
test := function-designator which designate the function which accepts two arguments. Otherwise error.
The default is CL:EQL.

“‘lisp
#?(remove-leaf (princ-to-string 1) (list "2" "1" "0"))
=> ("2" "1" "0")
, :test
“‘

“‘lisp
#?(remove-leaf "1" ’("2" "1" "0") :test ’string=)
=> ("2" "0")
, :test
“‘

“‘lisp
#?(remove-leaf "1" ’("2" "1" "0") :test :not-function-designator)
:signals undefined-function
“‘
key := function-designator which designates the function which accepts one argument. Otherwise error.
The default is CL:IDENTITY.

“‘lisp
#?(remove-leaf 1 ’("2" "1" "0"))
=> ("2" "1" "0")
, :test
“‘

“‘lisp
#?(remove-leaf 1 ’("2" "1" "0") :key #’parse-integer)
=> ("2" "0")
, :test
“‘

“‘lisp
#?(remove-leaf "1" ’("2" "1" "0") :key :not-function-designator)
:signals undefined-function
“‘
keep := boolean
control flag, whether keep empty node (i.e. NIL) or not.
The default it T.

“‘lisp
#?(remove-leaf 1 ’(1 2 (1) 2))
=> (2 () 2)
, :test
“‘

“‘lisp
#?(remove-leaf 1 ’(1 2 (1) 2) :keep nil)
=> (2 2)
, :test
“‘
result := newly consed tree structured list.

“‘lisp
#?(let ((tree ’(1 2 3 4 5)))
(eq tree (remove-leaf 0 tree)))
=> NIL
“‘

## Affected By:
none

## Side-Effects:
none

## Notes:
TREE must be proper tree. See PROPER-TREE for detail.

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)

Function: remove-leaf-if FUNCTION TREE &key KEY KEEP

# REMOVE-LEAF-IF

## Description:
Remove leaf which satisfies FUNCTION.

“‘lisp
#?(remove-leaf-if #’evenp ’(1 (2 3) 4))
=> (1 (3))
, :test
“‘

### syntax
(REMOVE-LEAF-IF function tree &key (key #’identity) (keep t))
=> result

## Arguments and Values:
function := function-designator which designates the function which accepts one argument. Otherwise error.

“‘lisp
#?(remove-leaf-if ’oddp ’(1 (2 3) 4))
=> ((2)4)
, :test
“‘

“‘lisp
#?(remove-leaf-if :not-function-designator ’(1 (2 3) 4))
:signals undefined-function
“‘
tree := tree structured list, otherwise error.

“‘lisp
#?(remove-leaf-if #’evenp 0)
:signals (or invalid-tree
type-error ; for sbcl
warning ; for ccl
)
“‘
key := function-desinator which designates the function which accepts one argument.

“‘lisp
#?(remove-if #’evenp ’("1" "2" "3"))
:signals type-error
“‘

“‘lisp
#?(remove-if #’evenp ’("1" "2" "3") :key #’parse-integer)
=> ("1" "3")
, :test
“‘
keep := boolean which control whether keep empty node or not.
The default is T.

“‘lisp
#?(remove-leaf-if #’evenp ’(1 (2) 3))
=> (1 () 3)
, :test
“‘

“‘lisp
#?(remove-leaf-if #’evenp ’(1 (2) 3) :keep nil)
=> (1 3)
, :test
“‘
result := newly consed tree structured list.

“‘lisp
#?(let ((tree ’(1 2 3)))
(eq tree (remove-leaf-if #’evenp tree)))
=> NIL
“‘

## Affected By:
none

## Side-Effects:
none

## Notes:

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)

Function: traverse FUNCTION TREE

# TRAVERSE

## Description:
Traverse TREE with doing FUNCTION.
This is ‘MAPC‘ like operator.

### syntax
(TRAVERSE function tree)
=> result

“‘lisp
#?(traverse #’print ’(1 (2 . 3) 4))
:outputs "
(1 (2 . 3) 4)
1
((2 . 3) 4)
(2 . 3)
2
3
(4)
4
NIL "
“‘

## Arguments and Values:
function := Function as (FUNCTION(T)T).
Otherwise error.

“‘lisp
#?(traverse "NOT-FUNCTION" ’(1 2 3))
:signals error
“‘
This function’s return value is discarded.
tree := Tree structured list.
Atom is acceptable.

“‘lisp
#?(traverse #’print :atom)
:outputs "
:ATOM "
“‘
result := NIL

“‘lisp
#?(traverse #’print :atom)
=> NIL
, :stream
“‘

## Affected By:
none

## Side-Effects:
none

## Notes:
‘TRAVERSE‘ dinamically construct ‘CATCH‘ tag named ‘TRAVERSE‘. You can use it to skip traversing.

“‘lisp
#?(traverse (lambda(x)
(if (and (listp x)
(eql 2 (car x)))
(throw ’traverse nil)
(print x)))
’(1 (2 . 3) 4))
:outputs "
(1 (2 . 3) 4)
1
((2 . 3) 4)
(4)
4
NIL "
“‘

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)

Function: treep ARG

# TREEP

## Description:
Tests arg is tree.

“‘lisp
#?(treep :leaf)
=> NIL
“‘

“‘lisp
#?(treep ())
=> T
“‘

“‘lisp
#?(treep ’(:a :b))
=> T
“‘

“‘lisp
#?(treep ’(:a . :b)) => T
“‘

### syntax
(TREEP arg)
=> result

## Arguments and Values: arg := any lisp object. result := boolean

## Affected By:
none

## Side-Effects:
none

## Notes:

## Exceptional-Situations:

Package

trestrul

Source

trestrul.lisp (file)


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

5.1.4 Conditions

Condition: invalid-tree ()

# INVALID-TREE

## Description:

## Class Precedence List: (case in SBCL)
invalid-tree simple-type-error simple-condition type-error error serious-condition condition slot-object t

## Effective Slots:
FORMAT-CONTROL [Type] T
[READER] simple-condition-format-control
FORMAT-ARGUMENTS [Type] T
[READER] simple-condition-format-arguments
DATUM [Type] T
[READER] type-error-datum
EXPECTED-TYPE [Type] T
[READER] type-error-expected-type

## Notes:

Package

trestrul

Source

trestrul.lisp (file)

Direct superclasses

simple-type-error (condition)


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

5.1.5 Types

Type: proper-tree ()

# PROPER-TREE

## Description:
Tree structured list but without dotted pair.

“‘lisp
#?(typep () ’proper-tree)
=> T
“‘

“‘lisp
#?(typep ’(:a . :b) ’proper-tree)
=> NIL
“‘

“‘lisp
#?(typep ’(:a :b) ’proper-tree)
=> T
“‘

“‘lisp
#?(typep :atom ’proper-tree)
=> NIL
“‘

“‘lisp
#?(typep ’((:a :b)) ’proper-tree)
=> T
“‘

“‘lisp
#?(typep ’((:a . :b) :c) ’proper-tree)
=> NIL
“‘

## Compound Type Specifier Kind:
none

## Compound Type Specifier Syntax:

## Compound Type Specifier Arguments:

## Compound Type Specifier Description:

Package

trestrul

Source

trestrul.lisp (file)

Type: tree ()

# TREE

## Description:
Tree structured list which includes NIL and dotted pair.

“‘lisp
#?(typep nil ’tree)
=> T
“‘

“‘lisp
#?(typep ’(:a . :b) ’tree)
=> T
“‘

“‘lisp
#?(typep :atom ’tree)
=> NIL
“‘

## Compound Type Specifier Kind:
none

## Compound Type Specifier Syntax:

## Compound Type Specifier Arguments:

## Compound Type Specifier Description:

Package

trestrul

Source

trestrul.lisp (file)


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

5.2 Internal definitions


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

5.2.1 Functions

Function: %mapleaf FUN TREE
Package

trestrul

Source

trestrul.lisp (file)

Function: %nmapleaf FUN TREE
Package

trestrul

Source

trestrul.lisp (file)

Function: %remove-leaf-if FUNCTION TREE KEY KEEP
Package

trestrul

Source

trestrul.lisp (file)

Function: ensure-function FORM
Package

trestrul

Source

trestrul.lisp (file)


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

5.2.2 Types

Type: function-designator ()
Package

trestrul

Source

trestrul.lisp (file)


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

Appendix A Indexes


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

A.1 Concepts

Jump to:   F   L   T  
Index Entry  Section

F
File, Lisp, trestrul.asd: The trestrul․asd file
File, Lisp, trestrul/trestrul.lisp: The trestrul/trestrul․lisp file

L
Lisp File, trestrul.asd: The trestrul․asd file
Lisp File, trestrul/trestrul.lisp: The trestrul/trestrul․lisp file

T
trestrul.asd: The trestrul․asd file
trestrul/trestrul.lisp: The trestrul/trestrul․lisp file

Jump to:   F   L   T  

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

A.2 Functions

Jump to:   %  
A   C   D   E   F   M   N   P   R   T  
Index Entry  Section

%
%mapleaf: Internal functions
%nmapleaf: Internal functions
%remove-leaf-if: Internal functions

A
ansubst: Exported functions
ansubst-if: Exported functions
asubst: Exported functions
asubst-if: Exported functions

C
collect-node: Exported functions
Compiler Macro, mapleaf: Exported compiler macros
Compiler Macro, nmapleaf: Exported compiler macros
Compiler Macro, remove-leaf-if: Exported compiler macros

D
dotree: Exported macros

E
ensure-function: Internal functions

F
find-leaf: Exported functions
find-leaf-if: Exported functions
find-node-if: Exported functions
follow: Exported functions
Function, %mapleaf: Internal functions
Function, %nmapleaf: Internal functions
Function, %remove-leaf-if: Internal functions
Function, ansubst: Exported functions
Function, ansubst-if: Exported functions
Function, asubst: Exported functions
Function, asubst-if: Exported functions
Function, collect-node: Exported functions
Function, ensure-function: Internal functions
Function, find-leaf: Exported functions
Function, find-leaf-if: Exported functions
Function, find-node-if: Exported functions
Function, follow: Exported functions
Function, mapleaf: Exported functions
Function, nmapleaf: Exported functions
Function, path-to: Exported functions
Function, proper-treep: Exported functions
Function, remove-leaf: Exported functions
Function, remove-leaf-if: Exported functions
Function, traverse: Exported functions
Function, treep: Exported functions

M
Macro, dotree: Exported macros
mapleaf: Exported compiler macros
mapleaf: Exported functions

N
nmapleaf: Exported compiler macros
nmapleaf: Exported functions

P
path-to: Exported functions
proper-treep: Exported functions

R
remove-leaf: Exported functions
remove-leaf-if: Exported compiler macros
remove-leaf-if: Exported functions

T
traverse: Exported functions
treep: Exported functions

Jump to:   %  
A   C   D   E   F   M   N   P   R   T  

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

A.3 Variables


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

A.4 Data types

Jump to:   C   F   I   P   S   T  
Index Entry  Section

C
Condition, invalid-tree: Exported conditions

F
function-designator: Internal types

I
invalid-tree: Exported conditions

P
Package, trestrul: The trestrul package
proper-tree: Exported types

S
System, trestrul: The trestrul system

T
tree: Exported types
trestrul: The trestrul system
trestrul: The trestrul package
Type, function-designator: Internal types
Type, proper-tree: Exported types
Type, tree: Exported types

Jump to:   C   F   I   P   S   T