Skip to content

Commit b27225b

Browse files
committed
utilities: has thunk, thunk*, some documentation
1 parent 88add81 commit b27225b

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,20 @@ Logging to pathnames rather than explicitly-managed streams may be a little slow
24352435
### Package, module
24362436
`slog` lives in and provides `:org.tfeb.hax.slog`.
24372437

2438+
## Utilities
2439+
This is used both by other hax and by other code I've written. Things in this system *may not be stable*: it should be considered mostly-internal. However, changes to it *are* reflected in the version number of things, since other systems can depend on things in it.
2440+
2441+
Here is what it currently provides.
2442+
2443+
- `parse-docstring-body` parses the body of a function with possible documentation and declarations into three values: docstring, list of declarations and remaining forms.
2444+
- `parse-simple-body` is like `parse-docstring-body` but it does not handle docstrings & only returns two values.
2445+
- `with-names` binds variables to uninterned symbols with the same name by default: `(with-names (<foo>) ...)`will bind `<foo>` to a fresh uninterned symbol with name `"<FOO>"`. `(with-names ((<foo> foo)) ...)` will bind `<foo>` to a fresh uninterned symbol with name `"FOO"`.
2446+
- `thunk` makes anonymous functions with no arguments: `(thunk ...)` is `(lambda () ...)`.
2447+
- `thunk*` makes anonymous functions which take an arbitrary number of arguments and ignore them all.
2448+
2449+
### Package, module
2450+
The utilities live in and provide `:org.tfeb.hax.utilities`.
2451+
24382452
---
24392453

24402454
The TFEB.ORG Lisp hax are copyright 1989-2024 Tim Bradshaw. See `LICENSE` for the license.

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
8.5.0
1+
8.6.0

utilities.lisp

+20-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
(:export
77
#:parse-docstring-body
88
#:parse-simple-body
9-
#:with-names))
9+
#:with-names
10+
#:thunk
11+
#:thunk*))
1012

1113
(in-package :org.tfeb.hax.utilities)
1214

@@ -51,3 +53,20 @@ Optionally you can specify the name by giving a clause as (var <string-designato
5153
`(,name (make-symbol (string ,sd)))))))
5254
clauses)
5355
,@forms))
56+
57+
;;; Because it's time
58+
;;;
59+
60+
(defmacro thunk (&body body)
61+
"Function of no arguments"
62+
`(lambda ()
63+
,@body))
64+
65+
(defmacro thunk* (&body body)
66+
;; Can't use WITH-NAMES yet
67+
"Function of any number of ignored arguments"
68+
(let ((<args> (make-symbol "<ARGS>")))
69+
`(lambda (&rest ,<args>)
70+
(declare (dynamic-extent ,<args>)
71+
(ignore ,<args>))
72+
,@body)))

0 commit comments

Comments
 (0)