95393d6a5226

Add `with-result` iterate clause
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 14 Dec 2021 19:12:23 -0500
parents 72fe2afc82c7
children c2970d9e6ea7
branches/tags (none)
files DOCUMENTATION.markdown src/iterate.lisp src/package.lisp

Changes

--- a/DOCUMENTATION.markdown	Wed Dec 01 23:43:54 2021 -0500
+++ b/DOCUMENTATION.markdown	Tue Dec 14 19:12:23 2021 -0500
@@ -1580,6 +1580,16 @@
 
 Sugar for `(if-first-time expr nil)`.
 
+### `WITH-RESULT` (macro)
+
+    (WITH-RESULT SYMBOL = EXPR)
+
+Bind `expr` to symbol using `with`, and return it at the end.
+
+  Equivalent to `(progn (with symbol = expr) (returning expr))`.
+
+  
+
 ## Package `LOSH.LISTS`
 
 Utilities for operating on lists.
@@ -2594,7 +2604,7 @@
 
 ### `PBCOPY` (function)
 
-    (PBCOPY OBJECT)
+    (PBCOPY &OPTIONAL (OBJECT *))
 
 `pbcopy` the `aesthetic-string` of `object`.
 
--- a/src/iterate.lisp	Wed Dec 01 23:43:54 2021 -0500
+++ b/src/iterate.lisp	Tue Dec 14 19:12:23 2021 -0500
@@ -978,6 +978,16 @@
   "
   `(finally (return (values ,@values))))
 
+(defmacro with-result (symbol = expr)
+  "Bind `expr` to symbol using `with`, and return it at the end.
+
+  Equivalent to `(progn (with symbol = expr) (returning expr))`.
+
+  "
+  (assert (eql = '=))
+  `(progn (with ,symbol = ,expr)
+     (returning ,symbol)))
+
 (defmacro-driver (FOR var-or-vars MATCHING regex AGAINST string &optional OVERLAP overlap? START start END end)
   "Iterate over the matches of `regex` in `string`, binding `var-or-vars`.
 
--- a/src/package.lisp	Wed Dec 01 23:43:54 2021 -0500
+++ b/src/package.lisp	Tue Dec 14 19:12:23 2021 -0500
@@ -348,6 +348,7 @@
     :when-first-iteration
     :when-first-time
     :window
+    :with-result
     :within-radius
 
     ))