2018-10-04 13:50:25 +02:00
|
|
|
<!DOCTYPE html><html lang="en"><head><meta charSet="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><title>Block · Pluto</title><meta name="viewport" content="width=device-width"/><meta name="generator" content="Docusaurus"/><meta name="description" content="# Let block"/><meta name="docsearch:language" content="en"/><meta property="og:title" content="Block · Pluto"/><meta property="og:type" content="website"/><meta property="og:url" content="https://status-im.github.io/pluto/index.html"/><meta property="og:description" content="# Let block"/><meta name="twitter:card" content="summary"/><link rel="shortcut icon" href="/pluto/img/favicon.png"/><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"/><script type="text/javascript" src="https://buttons.github.io/buttons.js"></script><script type="text/javascript" src="/pluto/js/pluto.js"></script><link rel="stylesheet" href="/pluto/css/prism.css"/><link rel="stylesheet" href="/pluto/css/main.css"/></head><body class="sideNavVisible separateOnPageNav"><div class="fixedHeaderContainer"><div class="headerWrapper wrapper"><header><a href="/pluto/"><img class="logo" src="/pluto/img/logo_white.png" alt="Pluto"/><h2 class="headerTitleWithLogo">Pluto</h2></a><div class="navigationWrapper navigationSlider"><nav class="slidingNav"><ul class="nav-site nav-site-internal"><li class=""><a href="/pluto/docs/Manifesto.html" target="_self">Docs</a></li><li class=""><a href="/pluto/examples.html" target="_self">Examples</a></li><li class=""><a href="/pluto/try.html" target="_self">Try</a></li></ul></nav></div></header></div></div><div class="navPusher"><div class="docMainWrapper wrapper"><div class="container mainContainer docMainContainer"><div class="wrapper"><div class="post"><header class="postHeader"><h1 class="postHeaderTitle">Block</h1></header><article><div><span><h1><a class="anchor" aria-hidden="true" id="let-block"></a><a href="#let-block" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Let block</h1>
|
2018-08-02 10:59:58 +00:00
|
|
|
<p>Let blocks provide lexical scope to all nested elements.
|
|
|
|
|
Associated bindings are key value pairs, with key either symbol or destructuring patterns.
|
|
|
|
|
Values can be primitive types or references to queries.</p>
|
2018-10-04 13:50:25 +02:00
|
|
|
<pre><code class="hljs css language-clojure"><span class="token punctuation">(</span><span class="token keyword">let</span> <span class="token punctuation">[</span><span class="token number">a</span> <span class="token number">1</span>
|
2018-10-14 15:27:39 +02:00
|
|
|
<span class="token punctuation">{</span><span class="token keyword">name</span> <span class="token operator">:name</span><span class="token punctuation">}</span> <span class="token punctuation">[</span>status.user<span class="token punctuation">]</span><span class="token punctuation">]</span>
|
2018-08-02 10:59:58 +00:00
|
|
|
<span class="token punctuation">[</span>view <span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|
|
|
|
<span class="token punctuation">[</span>text <span class="token punctuation">{</span><span class="token punctuation">}</span>
|
|
|
|
|
<span class="token keyword">name</span><span class="token punctuation">]</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
|
|
|
|
|
</code></pre>
|
2018-07-24 16:50:00 +00:00
|
|
|
<h2><a class="anchor" aria-hidden="true" id="destructuring"></a><a href="#destructuring" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Destructuring</h2>
|
|
|
|
|
<h3><a class="anchor" aria-hidden="true" id="sequential-data-structure"></a><a href="#sequential-data-structure" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Sequential data structure</h3>
|
|
|
|
|
<p>Extract seq elements by index
|
|
|
|
|
Elements can be ignored with <code>_</code>
|
|
|
|
|
<code>:as symbol</code> denotes the whole sequence</p>
|
|
|
|
|
<h4><a class="anchor" aria-hidden="true" id="examples"></a><a href="#examples" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Examples</h4>
|
2018-10-04 13:50:25 +02:00
|
|
|
<pre><code class="hljs css language-clojure"><span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token number">a</span> _ <span class="token number">c</span> <span class="token operator">:as</span> all<span class="token punctuation">]</span> <span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span> <span class="token number">4</span> <span class="token number">5</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
|
2018-07-24 16:50:00 +00:00
|
|
|
<span class="token comment">;; a = 1</span>
|
|
|
|
|
<span class="token comment">;; c = 3</span>
|
|
|
|
|
<span class="token comment">;; all = [1 2 3 4 5]</span>
|
|
|
|
|
</code></pre>
|
|
|
|
|
<h3><a class="anchor" aria-hidden="true" id="associative-data-structure"></a><a href="#associative-data-structure" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Associative data structure</h3>
|
|
|
|
|
<p>Extract map values by keys <code>{a :a}</code>
|
|
|
|
|
Optional values via <code>[a 5]</code>
|
|
|
|
|
No namespaced keyword support, no short syntax</p>
|
|
|
|
|
<h4><a class="anchor" aria-hidden="true" id="examples-1"></a><a href="#examples-1" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Examples</h4>
|
2018-10-04 13:50:25 +02:00
|
|
|
<pre><code class="hljs css language-clojure"><span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token number">a</span> <span class="token operator">:a</span> <span class="token number">a</span> <span class="token operator">:b</span> <span class="token punctuation">[</span><span class="token number">c</span> <span class="token number">4</span><span class="token punctuation">]</span> <span class="token operator">:c</span> <span class="token operator">:as</span> all<span class="token punctuation">}</span> <span class="token punctuation">{</span><span class="token operator">:a</span> <span class="token number">1</span> <span class="token operator">:b</span> <span class="token number">2</span> <span class="token operator">:d</span> <span class="token number">3</span><span class="token punctuation">}</span><span class="token punctuation">]</span>
|
2018-07-24 16:50:00 +00:00
|
|
|
<span class="token comment">;; a = 1</span>
|
|
|
|
|
<span class="token comment">;; b = 2</span>
|
|
|
|
|
<span class="token comment">;; c = 4</span>
|
|
|
|
|
<span class="token comment">;; all = {:a 1 :b 2 :d 3}</span>
|
|
|
|
|
</code></pre>
|
|
|
|
|
<h4><a class="anchor" aria-hidden="true" id="nesting"></a><a href="#nesting" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Nesting</h4>
|
|
|
|
|
<p>Both structure type destrucuring can be combined</p>
|
2018-10-04 13:50:25 +02:00
|
|
|
<pre><code class="hljs css language-clojure"><span class="token punctuation">[</span><span class="token punctuation">{</span><span class="token punctuation">[</span><span class="token number">a1</span> _ <span class="token number">a3</span><span class="token punctuation">]</span> <span class="token operator">:a</span> <span class="token punctuation">{</span><span class="token number">d</span> <span class="token operator">:d</span> #<span class="token punctuation">{</span><span class="token number">f</span> <span class="token number">7</span><span class="token punctuation">}</span> <span class="token operator">:f</span> <span class="token punctuation">[</span><span class="token punctuation">[</span>_ g2<span class="token punctuation">]</span> <span class="token number">8</span><span class="token punctuation">}</span><span class="token punctuation">]</span> <span class="token operator">:b</span> <span class="token punctuation">[</span>_ <span class="token number">e2</span><span class="token punctuation">]</span> <span class="token operator">:e</span> <span class="token operator">:all</span> all<span class="token punctuation">}</span>
|
2018-07-24 16:50:00 +00:00
|
|
|
<span class="token punctuation">{</span><span class="token operator">:a</span> <span class="token punctuation">[</span><span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span><span class="token punctuation">]</span> <span class="token operator">:b</span> <span class="token punctuation">{</span><span class="token operator">:d</span> <span class="token number">4</span> <span class="token operator">:e</span> <span class="token punctuation">[</span><span class="token number">5</span> <span class="token number">6</span><span class="token punctuation">]</span> <span class="token operator">:g</span> <span class="token punctuation">[</span><span class="token number">9</span> <span class="token number">10</span><span class="token punctuation">]</span><span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">]</span>
|
|
|
|
|
<span class="token comment">;; a1 = 1</span>
|
|
|
|
|
<span class="token comment">;; a3 = 3</span>
|
|
|
|
|
<span class="token comment">;; d = 4</span>
|
|
|
|
|
<span class="token comment">;; e2 = 5</span>
|
|
|
|
|
<span class="token comment">;; f = 7</span>
|
|
|
|
|
<span class="token comment">;; g2 = 10</span>
|
|
|
|
|
<span class="token comment">;; all = {:a [1 2 3] :b {:d 4 :e [5 6] :g [9 10]}}</span>
|
|
|
|
|
</code></pre>
|
2018-10-04 13:50:25 +02:00
|
|
|
</span></div></article></div><div class="docs-prevnext"></div></div></div><nav class="onPageNav docOnPageNav"><ul class="toc-headings"><li><a href="#destructuring">Destructuring</a><ul class="toc-headings"><li><a href="#sequential-data-structure">Sequential data structure</a></li><li><a href="#associative-data-structure">Associative data structure</a></li></ul></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><a href="/pluto/" class="nav-home"><img src="/pluto/img/logo_white.png" alt="Pluto" width="66" height="58"/></a><div><h5>Docs</h5><a href="docs/Tutorial">Getting Started</a><a href="docs/API">API Reference</a></div><div><h5>Community</h5><a href="https://chat.status.im">Project Chat</a><a href="https://twitter.com/ethstatus" target="_blank" rel="noreferrer noopener">Twitter</a></div><div><h5>More</h5><a href="https://blog.status.im/">Blog</a><a href="https://github.com/status-im/pluto/">GitHub</a></div></section><section class="copyright">Copyright © 2018 Status.im</section></footer></div></body></html>
|