# HG changeset patch # User Steve Losh # Date 1639527143 18000 # Node ID 95393d6a522606340d21dc5f6e98b54fa7fb98a6 # Parent 72fe2afc82c75657913437c330cb1cb15b289678 Add `with-result` iterate clause diff -r 72fe2afc82c7 -r 95393d6a5226 DOCUMENTATION.markdown --- 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`. diff -r 72fe2afc82c7 -r 95393d6a5226 src/iterate.lisp --- 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`. diff -r 72fe2afc82c7 -r 95393d6a5226 src/package.lisp --- 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 ))