Skip to content

Commit

Permalink
utilities: has thunk, thunk*, some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tfeb committed Jun 11, 2024
1 parent 88add81 commit b27225b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2435,6 +2435,20 @@ Logging to pathnames rather than explicitly-managed streams may be a little slow
### Package, module
`slog` lives in and provides `:org.tfeb.hax.slog`.

## Utilities
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.

Here is what it currently provides.

- `parse-docstring-body` parses the body of a function with possible documentation and declarations into three values: docstring, list of declarations and remaining forms.
- `parse-simple-body` is like `parse-docstring-body` but it does not handle docstrings & only returns two values.
- `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"`.
- `thunk` makes anonymous functions with no arguments: `(thunk ...)` is `(lambda () ...)`.
- `thunk*` makes anonymous functions which take an arbitrary number of arguments and ignore them all.

### Package, module
The utilities live in and provide `:org.tfeb.hax.utilities`.

---

The TFEB.ORG Lisp hax are copyright 1989-2024 Tim Bradshaw. See `LICENSE` for the license.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.5.0
8.6.0
21 changes: 20 additions & 1 deletion utilities.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
(:export
#:parse-docstring-body
#:parse-simple-body
#:with-names))
#:with-names
#:thunk
#:thunk*))

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

Expand Down Expand Up @@ -51,3 +53,20 @@ Optionally you can specify the name by giving a clause as (var <string-designato
`(,name (make-symbol (string ,sd)))))))
clauses)
,@forms))

;;; Because it's time
;;;

(defmacro thunk (&body body)
"Function of no arguments"
`(lambda ()
,@body))

(defmacro thunk* (&body body)
;; Can't use WITH-NAMES yet
"Function of any number of ignored arguments"
(let ((<args> (make-symbol "<ARGS>")))
`(lambda (&rest ,<args>)
(declare (dynamic-extent ,<args>)
(ignore ,<args>))
,@body)))

0 comments on commit b27225b

Please sign in to comment.