mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-26 13:51:50 +03:00
Update
This commit is contained in:
parent
25839de02d
commit
1206ad2309
@ -458,6 +458,13 @@
|
||||
(all? f xs)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Checks whether all of the elements in <code>xs</code> conform to the predicate
|
||||
function <code>f</code>.</p>
|
||||
<pre><code>(all? (fn [x] (< 1 x)) '(2 3 4))
|
||||
=> true
|
||||
(all? (fn [x] (< 1 x)) '(-1 0 1))
|
||||
=> false
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
@ -477,11 +484,12 @@
|
||||
(any? f xs)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>checks whether all of the elements in <code>xs</code> conform to the predicate
|
||||
<p>Checks whether any of the elements in <code>xs</code> conforms to the predicate
|
||||
function <code>f</code>.</p>
|
||||
<p>Example:</p>
|
||||
<pre><code>(all? (fn [x] (< 1 x)) '(2 3 4)) ; => true
|
||||
(all? (fn [x] (< 1 x)) '(-1 0 1)) ; => false
|
||||
<pre><code>(any? (fn [x] (= 'a x)) '(a b c))
|
||||
=> true
|
||||
(any? (fn [x] (= 'a x)) '(e f g))
|
||||
=> false
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
@ -1331,7 +1339,6 @@ result.</p>
|
||||
<p>If you only need to compose functions that take a single argument (unary arity)
|
||||
see <code>comp</code>. Comp also generates the form that corresponds to the composition,
|
||||
compose contrarily evaluates 'eagerly' and returns a computed symbol.</p>
|
||||
<p>For exmaple:</p>
|
||||
<pre><code>;; a silly composition
|
||||
((compose empty take) 3 [1 2 3 4 5])
|
||||
;; => []
|
||||
@ -1408,11 +1415,10 @@ compose contrarily evaluates 'eagerly' and returns a computed symbol.</p>
|
||||
(curry f x)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Returns a curried function accepting a single argument, that applies f to x
|
||||
<p>Returns a curried function accepting a single argument, that applies <code>f</code> to <code>x</code>
|
||||
and then to the following argument.</p>
|
||||
<p>For example,</p>
|
||||
<pre><code>(map (curry Symbol.prefix 'Foo) '(bar baz))
|
||||
;; => (Foo.bar Foo.baz)
|
||||
=> (Foo.bar Foo.baz)
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
@ -1434,16 +1440,15 @@ and then to the following argument.</p>
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Curry functions of any airity.</p>
|
||||
<p>For example:</p>
|
||||
<pre><code>(map (curry* Dynamic.zip + '(1 2 3)) '((4 5) (6)))
|
||||
;; => (((+ 1 4) (+ 2 5)) ((+ 1 6)))
|
||||
=> (((+ 1 4) (+ 2 5)) ((+ 1 6)))
|
||||
|
||||
((curry Dynamic.zip cons '(1 2 3)) '((4 5) (6)))
|
||||
;; => ((cons 1 (4 5)) (cons (2 (6))))
|
||||
=> ((cons 1 (4 5)) (cons (2 (6))))
|
||||
|
||||
(defndynamic add-em-up [x y z] (+ (+ x y) z))
|
||||
(map (curry* add-em-up 1 2) '(1 2 3))
|
||||
;; => (4 5 6)
|
||||
=> (4 5 6)
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
@ -1730,11 +1735,10 @@ and then to the following argument.</p>
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Returns the empty form of <code>xs</code>.</p>
|
||||
<p>For example:</p>
|
||||
<pre><code>(empty '(1 2 3 4))
|
||||
;; => ()
|
||||
=> ()
|
||||
(empty '[1 2 3 4])
|
||||
;; => []
|
||||
=> []
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
@ -1907,9 +1911,8 @@ and then to the following argument.</p>
|
||||
<p class="doc">
|
||||
<p>Returns a list containing only the elements of <code>xs</code> that satisify
|
||||
predicate <code>p</code>.</p>
|
||||
<p>For example:</p>
|
||||
<pre><code>(filter (fn [x] (= 'a x)) '(a b a b a b a b))
|
||||
;; => (a a a a)
|
||||
=> (a a a a)
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
@ -1930,10 +1933,9 @@ predicate <code>p</code>.</p>
|
||||
(flatten l)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>flattens a list recursively.</p>
|
||||
<p>For example:</p>
|
||||
<p>Flattens a list recursively.</p>
|
||||
<pre><code>(flatten '(1 2 (3 (4))))
|
||||
; => '(1 2 3 4)
|
||||
=> '(1 2 3 4)
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
@ -1955,9 +1957,8 @@ predicate <code>p</code>.</p>
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Flips the arguments of a function <code>f</code>.</p>
|
||||
<p>For example,</p>
|
||||
<pre><code>((flip Symbol.prefix) 'Bar 'Foo)
|
||||
=> ;; (Foo.Bar)
|
||||
=> (Foo.Bar)
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
@ -2046,6 +2047,29 @@ predicate <code>p</code>.</p>
|
||||
<p>prints all information associated with a symbol.</p>
|
||||
<p>Example Usage:</p>
|
||||
<pre><code>(info mysymbol)
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#kind">
|
||||
<h3 id="kind">
|
||||
kind
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
primitive
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
<p>prints the kind of a symbol.</p>
|
||||
<p>Example Usage:</p>
|
||||
<pre><code>(kind mysymbol)
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
@ -2142,25 +2166,6 @@ predicate <code>p</code>.</p>
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#list-to-array-internal">
|
||||
<h3 id="list-to-array-internal">
|
||||
list-to-array-internal
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
dynamic
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<pre class="args">
|
||||
(list-to-array-internal xs acc)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#list?">
|
||||
<h3 id="list?">
|
||||
@ -2295,8 +2300,7 @@ predicate <code>p</code>.</p>
|
||||
<p>Applies a function <code>f</code> to each element in the list or array <code>xs</code> and
|
||||
returns a list dynamic data literal containing the result of the function
|
||||
applications.</p>
|
||||
<p>For example:</p>
|
||||
<pre><code class="language-clojure">'(map symbol? '(a b c))
|
||||
<pre><code>'(map symbol? '(a b c))
|
||||
=> (true true true)
|
||||
'(map (curry + 1) '(1 2 3))
|
||||
=> (2 3 4)
|
||||
@ -2875,10 +2879,9 @@ value through successive applications of <code>f</code>.</p>
|
||||
(take n xs)
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Returns a list containing the first <code>n</code> eleements of a list.</p>
|
||||
<p>For example:</p>
|
||||
<p>Returns a list containing the first <code>n</code> elements of a list.</p>
|
||||
<pre><code>(take 3 '(1 2 3 4 5))
|
||||
;; => (1 2 3)
|
||||
=> (1 2 3)
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
@ -2925,9 +2928,8 @@ value through successive applications of <code>f</code>.</p>
|
||||
<p>Applies <code>f</code> to a starting value <code>x</code>, then generates a sequence of values
|
||||
by successively applying <code>f</code> to the result <code>lim-1</code> times.
|
||||
Collects results in the structure given by <code>acc</code>.</p>
|
||||
<p>For example:</p>
|
||||
<pre><code>(unreduce (curry + 1) 0 10 (list))
|
||||
;; => (1 2 3 4 5 6 7 8 9 10)
|
||||
=> (1 2 3 4 5 6 7 8 9 10)
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
@ -2995,22 +2997,21 @@ Collects results in the structure given by <code>acc</code>.</p>
|
||||
</pre>
|
||||
<p class="doc">
|
||||
<p>Returns the <em>form</em> that results from applying a function <code>f</code> to each of
|
||||
the values supplied in <code>forms</code>.</p>
|
||||
<p>If the members of a single form are exhuasted, the result of the
|
||||
the values supplied in <code>forms</code>.
|
||||
If the members of a single form are exhuasted, the result of the
|
||||
applications thus far is returned, and any remaining members in the other
|
||||
forms are ignored.</p>
|
||||
<p>For example,</p>
|
||||
<pre><code>(zip + '(1 2 3) '(4 5 6))
|
||||
;; => ((+ 1 4) (+ 2 5) (+ 3 6))
|
||||
=> ((+ 1 4) (+ 2 5) (+ 3 6))
|
||||
</code></pre>
|
||||
<p>It's important to note that zip operates on forms, and that the form
|
||||
returned by zip may not be evaluable by itself. For instance, to actually
|
||||
transform the result in the example above into something Carp can
|
||||
evaluate, we need to wrap each member of the list in a <code>do</code>:</p>
|
||||
<pre><code>(append (list 'do) (zip + '(1 2 3) '(4 5 6)))
|
||||
;; => (do (+ 1 4) (+ 2 5) (+ 3 6))
|
||||
=> (do (+ 1 4) (+ 2 5) (+ 3 6))
|
||||
(eval (append (list 'do) (zip + '(1 2 3) '(4 5 6))))
|
||||
;; => 9 ;; do returns the value of the last form in its body
|
||||
=> 9 ;; do returns the value of the last form in its body
|
||||
</code></pre>
|
||||
|
||||
</p>
|
||||
|
Loading…
Reference in New Issue
Block a user