You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A significant portion of Basilisp's core library operates on Seqs.
311
+
Although most of these functions accept most or all of the builtin collection types, they typically call :lpy:fn:`seq` on the input collection argument and operate on the resulting Seq instance instead.
312
+
313
+
Many of these functions may accept Seqs and return another Seq, but still others accept a Seq and return some other concrete collection type.
314
+
315
+
Basilisp includes both the Clojure-compatible :lpy:fn:`apply` for applying a sequence as arguments to a function, but also the Python specific :lpy:fn:`apply-kw` for applying a map to Python functions accepting keyword arguments.
316
+
The :lpy:fn:`apply-method` macro is another Basilisp extension which enables easier application of sequences to Python methods.
317
+
318
+
.. note::
319
+
320
+
When used alone, Seq library functions consume and produce Seqs.
321
+
If multiple such functions are needed and used together, an intermediate Seq will be created for each function application.
322
+
323
+
As an alternative, many of the Seq functions in the core library support being used in a :ref:`transducer <transducers>`.
324
+
Transducers can often be more efficient in these cases since they do not require creating an intermediate Seq for each step.
325
+
326
+
.. seealso::
327
+
328
+
Below is a non-exhaustive list of some of the built-in Seq library functions.
The sections below detail various useful groups of functions provided by Basilisp.
338
+
339
+
However, not every group of functions in the core library is detailed below and, of those which are detailed, the included list of functions is not exhaustive.
340
+
341
+
.. _control_structures:
342
+
343
+
Control Structures
344
+
^^^^^^^^^^^^^^^^^^
345
+
346
+
Basilisp features many variations on traditional programming control structures such as ``if`` and ``while`` loops thanks to the magic of :ref:`macros`.
347
+
Using these control structure variants in preference to raw :lpy:form:`if` s can often help clarify the meaning of your code while also using reducing the amount of code you have to write.
348
+
349
+
In addition to the stalwart :lpy:fn:`condp`, :lpy:fn:`and`, and :lpy:fn:`or`, Basilisp also features threading macros which help writing clear and concise code.
350
+
Threading macros can help transform deeply nested expressions into a much more readable pipeline of expressions whose source order matches the execution order at runtime.
Basilisp core includes many functions which facilitate function composition, which are particularly helpful when dealing with higher-order functions.
364
+
365
+
In addition to the Clojure-compatible :lpy:fn:`partial` function for partial application, Basilisp includes :lpy:fn:`partial-kw` for working with Python functions which accept keyword arguments.
Basilisp core includes support for regular expressions which are backed by Python's :external:py:mod:`re` module.
377
+
Pattern literals can be created using the ``#"pattern"`` :ref:`reader macro <reader_macros>` syntax or via :lpy:fn:`re-pattern` if the pattern string is not a literal.
378
+
Check for matches using :lpy:fn:`re-find`, :lpy:fn:`re-matches`, or :lpy:fn:`re-seq`.
The Basilisp standard library includes support for futures executed on threads or processes backed by Python's :external:py:mod:`concurrent.futures` module.
397
+
By default, futures are run on a thread-pool executor (bound to the dynamic Var :lpy:var:`*executor-pool*`).
398
+
Callers can submit futures using either the :lpy:fn:`future` macro or the :lpy:fn:`future-call` function.
399
+
400
+
Users wishing to quickly parallelize work across multiple threads or processes can reach for :lpy:fn:`pmap` instead.
401
+
Like the built-in :lpy:fn:`map`, ``pmap`` executes the provided function across the input collection(s) using ``future`` and, thus, using the current pool bound to ``*executor-pool*``.
402
+
403
+
.. note::
404
+
405
+
The default executor pool used by futures is a thread-pool, which is most appropriate for IO-bound work.
406
+
Due to the Python GIL, the utility of a thread-pool for CPU bound work is extremely limited.
407
+
408
+
For CPU bound tasks, consider binding :lpy:var:`*executor-pool*` to a process pool worker (an instance of ``basilisp.lang.futures.ProcessPoolExecutor``).
409
+
410
+
.. seealso::
411
+
412
+
Using futures directly: :lpy:fn:`future`, :lpy:fn:`future-call`, :lpy:fn:`future-cancel`, :lpy:fn:`future?`, :lpy:fn:`future-cancelled?`, :lpy:fn:`future-done?`
413
+
414
+
Executing futures on a :ref:`Seq <seqs>`: :lpy:fn:`pmap`, :lpy:fn:`pcalls`, :lpy:fn:`pvalues`, :lpy:fn:`*pmap-cpu-count*`
415
+
416
+
.. _various_functions:
417
+
418
+
Various Functions
419
+
^^^^^^^^^^^^^^^^^
420
+
421
+
- Functions for throwing and introspecting exceptions: :lpy:fn:`ex-info`, :lpy:fn:`ex-cause`, :lpy:fn:`ex-data`, :lpy:fn:`ex-message`, :lpy:ns:`basilisp.stacktrace`
422
+
- Functions for generating random data: :lpy:fn:`rand`, :lpy:fn:`rand-int`, :lpy:fn:`rand-nth`, :lpy:fn:`random-uuid`, :lpy:fn:`random-sample`, :lpy:fn:`shuffle`
423
+
- Functions which can be used to introspect the Python type hierarchy: :lpy:fn:`class`, :lpy:fn:`cast`, :lpy:fn:`bases`, :lpy:fn:`supers`, :lpy:fn:`subclasses`
424
+
- Functions for parsing values from strings: :lpy:fn:`parse-double`, :lpy:fn:`parse-long`, :lpy:fn:`parse-boolean`, :lpy:fn:`parse-uuid`
Copy file name to clipboardExpand all lines: docs/specialforms.rst
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,10 @@ Primary Special Forms
45
45
While it is entirely legal to ``def`` a value within a function, the results of interning the Var within the function still apply to the current namespace.
46
46
Within a function or method context, users should use the :lpy:form:`let` special form to bind a value to a name in that scope.
0 commit comments