iteration: trivial-do

This commit is contained in:
vindarel 2020-10-26 23:11:35 +01:00
parent b19f7e525a
commit 66f9369abb
3 changed files with 46 additions and 10 deletions

View file

@ -44,6 +44,7 @@ Rules
- [[#data-formats][Data formats]]
- [[#date-and-time][Date and time]]
- [[#databases][Databases]]
- [[#iteration][Iteration]]
- [[#pattern-matching][Pattern matching]]
- [[#numbers][Numbers]]
- [[#regular-expressions][Regular expressions]]
@ -325,12 +326,47 @@ Mito and SxQL are available.
https://lispcookbook.github.io/cl-cookbook/databases.html
** Iteration
We ship =iterate= and =for= so you can try them, but we don't import
their symbols.
See https://lispcookbook.github.io/cl-cookbook/iteration.html for
examples, including about the good old =loop=.
We import macros from [[https://github.com/yitzchak/trivial-do/][trivial-do]], that provides =dolist=-like macro
to iterate over more structures:
- =dohash=: dohash iterates over the elements of an hash table and binds key-var to the key,
value-var to the associated value and then evaluates body as a tagbody that can include
declarations. Finally the result-form is returned after the iteration completes.
- =doplist=: doplist iterates over the elements of an plist and binds key-var to the key, value-var to
the associated value and then evaluates body as a tagbody that can include declarations.
Finally the result-form is returned after the iteration completes.
- =doalist=: doalist iterates over the elements of an alist and binds key-var to the car of each element,
value-var to the cdr of each element and then evaluates body as a tagbody that can include
declarations. Finally the result-form is returned after the iteration completes.
- =doseq*=: doseq* iterates over the elements of an sequence and binds position-var to the index of each
element, value-var to each element and then evaluates body as a tagbody that can include
declarations. Finally the result-form is returned after the iteration completes.
- =doseq=: doseq iterates over the elements of an sequence and binds value-var to successive values
and then evaluates body as a tagbody that can include declarations. Finally the result-form
is returned after the iteration completes.
- =dolist*=: dolist* iterates over the elements of an list and binds position-var to the index of each
element, value-var to each element and then evaluates body as a tagbody that can include
declarations. Finally the result-form is returned after the iteration completes.
** Pattern matching
Use Trivia, also available with the =match= local nickname.
** Numbers
We import =mean=, =variance=, =median= and =clamp= from Alexandria.
We import functions to parse numbers (Common Lisp only has
=parse-integer= by default).
[[https://github.com/soemraws/parse-float][parse-float]]
Similar to PARSE-INTEGER, but parses a floating point value and

View file

@ -55,7 +55,7 @@
;; iteration
:iterate
:for
;; :trivial-do ;; wait a bit, only in QL oct, 2020
:trivial-do
;; lambda shorthands
;; xxx: or rutils

View file

@ -30,15 +30,15 @@
:some-<>>))
;XXX: it's only in the latest Quicklisp
;; (cl-reexport:reexport-from :trivial-do
;; :include
;; '(:doalist ;; key value alist
;; :dohash ;; key value ht
;; :dolist* ;; position value list
;; :doplist ;; key value plist
;; :doseq ;; value sequence
;; :doseq* ;; position value sequence
;; ))
(cl-reexport:reexport-from :trivial-do
:include
'(:doalist ;; key value alist
:dohash ;; key value ht
:dolist* ;; position value list
;; :doplist ;; already from alexandria
:doseq ;; value sequence
:doseq* ;; position value sequence
))
(cl-reexport:reexport-from :repl-utilities
:include