Merge branch 'master' into pr/586

This commit is contained in:
Tuukka Turto 2014-05-02 21:06:20 +03:00
commit de65b7baf8

View File

@ -271,6 +271,21 @@ however is called only for every other value in the list.
(side-effect2 x)))
dict-comp
---------
`dict-comp` is used to create dictionaries. It takes three or four parameters.
The first two parameters are for controlling the return value
(key-value pair), while the third is used to select items from a sequence. The
fourth and optional parameter can be used to filter out some of the items in
the sequence based on a conditional expression.
.. code-block:: hy
=> (dict-comp x (* x 2) [x (range 10)] (odd? x))
{1: 2, 3: 6, 9: 18, 5: 10, 7: 14}
do / progn
----------
@ -667,6 +682,24 @@ normally. If the execution is halted with `break`, the `else` does not execute.
loop finished
genexpr
-------
`genexpr` is used to create generator expressions. It takes two or three parameters.
The first parameter is the expression controlling the return value, while
the second is used to select items from a list. The third and optional
parameter can be used to filter out some of the items in the list based on a
conditional expression. `genexpr` is similar to `list-comp`, except that it returns
an iterable that evaluates values one by one instead of evaluating them immediately.
.. code-block:: hy
=> (def collection (range 10))
=> (def filtered (genexpr x [x collection] (even? x)))
=> (list filtered)
[0, 2, 4, 6, 8]
.. _gensym:
gensym
@ -1041,6 +1074,22 @@ element:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
set-comp
--------
`set-comp` is used to create sets. It takes two or three parameters.
The first parameter is for controlling the return value, while the second is
used to select items from a sequence. The third and optional parameter can be
used to filter out some of the items in the sequence based on a conditional
expression.
.. code-block:: hy
=> (setv data [1 2 3 4 5 2 3 4 5 3 4 5])
=> (set-comp x [x data] (odd? x))
{1, 3, 5}
slice
-----