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
Like many Lisps, Basilisp supports extending its syntax using macros.
21
-
Macros are created using the :lpy:fn:`defmacro` macro in :lpy:ns:`basilisp.core`.
22
-
Syntax for the macro usage generally matches that of the sibling :lpy:fn:`defn` macro, should be a relatively easy transition.
23
-
24
-
Once a macro is defined, it is immediately available to the compiler.
25
-
You may define a macro and then use it in the next form!
26
-
27
-
The primary difference between a macro and a standard function is that macros are evaluated *at compile* time and they receive unevaluated expressions, whereas functions are evaluated *at runtime* and arguments will be fully evaluated before being passed to the function.
28
-
Macros should return the unevaluated replacement code that should be compiled.
29
-
Code returned by macros *must be legal code* -- symbols must be resolvable, functions must have the correct number of arguments, maps must have keys and corresponding values, etc.
30
-
31
-
Macros created with ``defmacro`` automatically have access to two additional parameters (which *should not* be listed in the macro argument list): ``&env`` and ``&form``.
32
-
``&form`` contains the original unevaluated form (including the invocation of the macro itself).
33
-
``&env`` contains a mapping of all symbols available to the compiler at the time of macro invocation -- the values are maps representing the binding AST node.
34
-
35
-
.. note::
36
-
37
-
Being able to extend the syntax of your language using macros is a powerful feature.
38
-
However, with great power comes great responsibility.
39
-
Introducing new and unusual syntax to a language can make it harder to onboard new developers and can make code harder to reason about.
40
-
Before reaching for macros, ask yourself if the problem can be solved using standard functions first.
15
+
.. _seqs:
41
16
42
-
.. warning::
17
+
Seqs
18
+
----
43
19
44
-
Macro writers should take care not to emit any references to :ref:`private_vars` in their macros, as these will not resolve for users outside of the namespace they are defined in, causing compile-time errors.
@@ -74,6 +43,10 @@ Destructuring is supported everywhere names are bound: :lpy:form:`fn` argument v
74
43
75
44
Names without a corresponding element in the data structure (typically due to absence) will bind to ``nil``.
76
45
46
+
.. seealso::
47
+
48
+
:lpy:fn:`destructure`
49
+
77
50
.. _sequential_destructuring:
78
51
79
52
Sequential Destructuring
@@ -209,58 +182,200 @@ Both associative and sequential destructuring binding forms may be nested within
209
182
[a b c e f])
210
183
;;=> [1 :b :c 4 5]
211
184
185
+
.. _macros:
186
+
187
+
Macros
188
+
------
189
+
190
+
Like many Lisps, Basilisp supports extending its syntax using macros.
191
+
Macros are created using the :lpy:fn:`defmacro` macro in :lpy:ns:`basilisp.core`.
192
+
Syntax for the macro usage generally matches that of the sibling :lpy:fn:`defn` macro, should be a relatively easy transition.
193
+
194
+
Once a macro is defined, it is immediately available to the compiler.
195
+
You may define a macro and then use it in the next form!
196
+
197
+
The primary difference between a macro and a standard function is that macros are evaluated *at compile* time and they receive unevaluated expressions, whereas functions are evaluated *at runtime* and arguments will be fully evaluated before being passed to the function.
198
+
Macros should return the unevaluated replacement code that should be compiled.
199
+
Code returned by macros *must be legal code* -- symbols must be resolvable, functions must have the correct number of arguments, maps must have keys and corresponding values, etc.
200
+
201
+
Macros created with ``defmacro`` automatically have access to two additional parameters (which *should not* be listed in the macro argument list): ``&env`` and ``&form``.
202
+
``&form`` contains the original unevaluated form (including the invocation of the macro itself).
203
+
``&env`` contains a mapping of all symbols available to the compiler at the time of macro invocation -- the values are maps representing the binding AST node.
204
+
205
+
.. note::
206
+
207
+
Being able to extend the syntax of your language using macros is a powerful feature.
208
+
However, with great power comes great responsibility.
209
+
Introducing new and unusual syntax to a language can make it harder to onboard new developers and can make code harder to reason about.
210
+
Before reaching for macros, ask yourself if the problem can be solved using standard functions first.
211
+
212
+
.. warning::
213
+
214
+
Macro writers should take care not to emit any references to :ref:`private_vars` in their macros, as these will not resolve for users outside of the namespace they are defined in, causing compile-time errors.
Copy file name to clipboardExpand all lines: docs/reader.rst
+9-4Lines changed: 9 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,9 +11,6 @@ The Basilisp reader performs a job which is a combination of the traditional lex
11
11
The reader takes a file or string and produces a stream of Basilisp data structures.
12
12
Typically the reader streams its results to the compiler, but end-users may also take advantage of the reader directly from within Basilisp.
13
13
14
-
.. contents:: Reader Literals
15
-
:depth: 2
16
-
17
14
.. _numeric_literals:
18
15
19
16
Numeric Literals
@@ -356,7 +353,7 @@ All of the text to the end of the line are ignored.
356
353
357
354
For a convenience in writing shell scripts with Basilisp, the standard \*NIX `shebang <https://en.wikipedia.org/wiki/Shebang_(Unix)>`_ (``#!``) is also treated as a single-line comment.
358
355
359
-
.. _metadata:
356
+
.. _reader_metadata:
360
357
361
358
Metadata
362
359
--------
@@ -380,6 +377,10 @@ Metadata applied to a form must be one of: :ref:`maps`, :ref:`symbols`, :ref:`ke
380
377
* Keyword metadata will be normalized to a Map with the keyword as the key with the value of ``true``.
381
378
* Map metadata will not be modified when it is read.
382
379
380
+
.. seealso::
381
+
382
+
:ref:`metadata`
383
+
383
384
.. _reader_macros:
384
385
385
386
Reader Macros
@@ -462,6 +463,10 @@ In nearly all cases, this will be the return value from a macro function, which
462
463
463
464
Using any of these special syntax quoting characters outside of a syntax quote context will result in a compiler error.
Copy file name to clipboardExpand all lines: docs/repl.rst
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -65,6 +65,27 @@ This namespace includes some utilities for introspecting the runtime environment
65
65
66
66
:lpy:fn:`require`, :lpy:fn:`refer`, :lpy:fn:`use`
67
67
68
+
.. _taps:
69
+
70
+
Taps
71
+
^^^^
72
+
73
+
Basilisp supports the concept of "taps" as a convenient, non-blocking method of monitoring the operation of some function at runtime.
74
+
Taps are implemented as a simple in-process publish/subscribe mechanism.
75
+
Users can add tap functions using :lpy:fn:`add-tap` which subscribe to a topic (typically a keyword) or which use the default ``:basilisp.core.tap/default``.
76
+
Functions can then emit tap events at runtime into the queue using :lpy:fn:`tap>` with a topic and a background thread will call any tap functions which have subscribed to the topic.
77
+
Taps can be removed using :lpy:fn:`remove-tap`.
78
+
79
+
.. warning::
80
+
81
+
The background thread uses a :external:py:class:`queue.Queue` to store and process its results.
82
+
The queue size is limited to 1024 items by default to avoid excessive memory consumption.
83
+
Users can configure the queue size by setting the environment variable ``BASILISP_TAP_QUEUE_SIZE`` to an integer value.
Basilisp supports the concept of "binding conveyance" which allows copying the active set of dynamic Var bindings in the current thread when submitting work to another thread.
164
+
Both :lpy:fn:`future` and :lpy:fn:`pmap` support this feature natively.
0 commit comments