Commit Graph

208 Commits

Author SHA1 Message Date
gilch
20c26a52e4 make sharp macros take arbitrary identifiers
Previously, only a single character was allowed.
2017-06-22 22:46:24 -06:00
neil-lindquist
d3df17d9d8 Modify cond to support single argument branches 2017-06-10 08:30:53 -07:00
Kodi Arfer
dffa2811e6 Return from the else clause of a try form
I overhauled the documentation of `try` while I was editing it.
2017-05-25 20:48:09 -05:00
Kodi Arfer
4c38e2c9dd Rename reader macros to "sharp macros" (#1282)
They're not actually reader macros, since their arguments are parsed s-expressions, like a regular macro, not pre-parsed source text.
2017-04-21 10:07:48 -05:00
Kodi Arfer
18acfe6495 Revert the extension of with-decorator to setv
This is no longer necessary now that `defn` always produces a `FunctionDef`.

To compensate, I've made small edits to two contrib modules and reverted a small test change.
2017-04-13 06:36:00 +03:00
Kodi Arfer
36d09cb194 More documentation of strings and keywords
Currently, HyKeyword is not in fact a subclass of HyString, so I removed that statement.
2017-04-01 08:23:41 +03:00
Kai Lüke
80f0e4af14 fix example in documentation to unquote in quasi quote 2017-03-09 15:02:23 +01:00
Kodi Arfer
8b6a45e43a Remove car and cdr in favor of first and rest (#1241)
* Remove uses of `car` and `cdr` in /hy

* Remove uses of `car` and `cdr` in quote tests

* Remove `car` and `cdr` in favor of `first` and `rest`

I beefed up the documentation and tests for `first` and `rest` while I was at it.

I defined `car` and `cdr` in native_tests.cons so the tests read a bit more naturally.
2017-03-06 10:34:40 -06:00
Tuukka Turto
8b84114869 Document get in nested structure (#1236) 2017-02-24 14:22:27 -08:00
Kodi Arfer
e4a7b317e1 Make fn work like lambda and remove lambda (#1228)
* with-decorator: Allow a `setv` form as the form to be decorated

This feature is of dubious value by itself, but it's necessary to allow `defn` to create a lambda instead of a `def`.

* Make `fn` work the same as `lambda`

That is, allow it to generate a `lambda` instead of a `def` statement if the function body is just an expression.

I've removed two uses of with_decorator in hy.compiler because they'd require adding another case to HyASTCompiler.compile_decorate_expression and they have no ultimate effect, anyway.

In a few tests, I've added a meaningless statement in `fn` bodies to force generation of a `def`.

I've removed `test_fn_compiler_empty_function` rather than rewrite it because it seems like a pain to maintain and not very useful.

* Remove `lambda`, now that `fn` does the same thing
2017-02-22 17:36:52 -06:00
Kodi Arfer
45b7a4ac9d Add bytestring literals 2017-02-19 09:04:45 +02:00
Kodi Arfer
f3edeb99ae Allow commas and underscores in numeric literals
You can use them as thousands separators.

This change differs from PEP 515 in that not only does it allow commas in addition to underscores, but it's much more liberal about placement. Any number of underscores or commas can be placed anywhere, even at the start.
2017-02-15 09:03:24 +02:00
Kodi Arfer
1d6de2792e Merge branch 'let-it-be' 2017-02-13 09:19:37 -08:00
Kodi Arfer
3ec919278d Remove let from documentation 2017-02-13 09:12:21 -08:00
Charles de Lacombe
83cdaf0a71 Docs: Hy <-> Python interop fix #1061 (#1218)
* Docs: Hy <-> Python interop fix #1061

I separated the existing text in two sections, with some additional
explanations and a link to Hy's `import`.

* added interop page

* simplified interop section in tutorial

* remove the TODO from interop section in tutorial

Because yay

* Corrections from @Kodiologist

I kept the part about mangling, but added a warning about its incompleteness. I
think it can be useful for somebody who just wants to use a Python module in his
code. Maybe it can be removed when the actual documentation for mangling is
written.

* Added myself to AUTHORS.

I'll do my best to be worthy of it. Thanks for this awesome project!
2017-02-10 17:11:21 -08:00
Jakub Wilk
99d31d153c Use HTTPS for github.com, docs.python.org and notes.pault.ag URLs (#1219)
* Use HTTPS for github.com

* Use HTTPS for docs.python.org

* Use HTTPS for notes.pault.ag
2017-02-07 13:25:40 -06:00
Kodi Arfer
9ca7f49c88 Make xor return single true inputs
The documentation should now be correct (#1214).
2017-02-03 22:25:38 +02:00
Kodi Arfer
2dd1432b07 Docs: add an example of evaluating a string 2017-01-19 09:26:12 -08:00
Tuukka Turto
e588b4928d add defmacro! and fix macro expansion error message (#1172)
* added defmacro!

* revert #924

#924 had an error and should never have been merged in the first place. (see #903)

* put back import getargspec

Without the `formatargspec` this time.

* Give better error message on failed macro expansion

Better error messages work most of the time. In cases where there are
parameters that aren't valid in Python, error message shown is rather
ugly. But this is better than no error messages at all and such
macros with strange parameter names are rather rare.

* fix flake8 errors

* Minor English improvements
2016-12-14 18:10:46 -06:00
Kodi Arfer
28b9874efd Add an example of using argparse with defmain
Closes #1091.
2016-12-13 08:57:31 -08:00
Kodi Arfer
ed8e37da62 Burninate the synonyms true, false, and nil
Per the straw poll in #908, as an alternative to #1147.

Now you must use `True`, `False`, and `None`, as in Python. Or just assign `true` to `True`, etc.; the old synonyms aren't reserved words anymore.
2016-11-23 18:35:17 -08:00
Tuukka Turto
f60ed24c29 Add docs and tests for as-> macro (#1141)
Add docs and tests for as-> macro

Closes #1047
2016-11-03 10:20:26 +02:00
Kodi Arfer
14fddbe6c3 Give require the same features as import (#1142)
Give `require` the same features as `import`

You can now do (require foo), (require [foo [a b c]]), (require [foo [*]]), and (require [foo :as bar]). The first and last forms get you macros named foo.a, foo.b, etc. or bar.a, bar.b, etc., respectively. The second form only gets the macros in the list.

Implements #1118 and perhaps partly addresses #277.

N.B. The new meaning of (require foo) will cause all existing code that uses macros to break. Simply replace these forms with (require [foo [*]]) to get your code working again.

There's a bit of a hack involved in the forms (require foo) or (require [foo :as bar]). When you call (foo.a ...) or (bar.a ...), Hy doesn't actually look inside modules. Instead, these (require ...) forms give the macros names that have periods in them, which happens to work fine with the way Hy finds and interprets macro calls.

* Make `require` syntax stricter and add tests

* Update documentation for `require`

* Documentation wording improvements

* Allow :as in `require` name lists
2016-11-03 09:35:58 +02:00
gilch
399d2bcf21 clarify documentation of import (#1121)
* clarify documentation of import

Add a comment showing the equivalent python of the long example, and demonstrate how to get `from` and `as` on the same line.

* add python example comment in last import example
2016-09-25 21:29:53 -06:00
Jakub Wilk
b94211251c Use HTTPS for Wikipedia URLs 2016-09-04 22:35:46 +02:00
Tim Martin
b3a85801bd Documentation of the &key modifier in (defn) 2016-01-26 20:34:08 +00:00
Paul‮etnomailgaT‭
3eb6001852 Merge pull request #872 from tuturto/xor
Add exclusive or logical operator
2015-12-12 12:38:14 -05:00
Johnathon Sage
ec0eea1277 Update api.rst
(for [[( ... ) ( ... )]] )  --> HyMacroExpansionError: 'for' requires an even number of args.
2015-11-14 16:56:27 -05:00
Johnathon Sage
7dbd3bcf7c Update api.rst
Extra closing '])' in yield "yields 'LexException'
2015-11-14 16:18:53 -05:00
gilch
f4afb0ca7e variadic if
The `if` form now supports elif clauses.
It works like `cond` but without the implicit `do`.
The old `if` is now `if*`

variadic lif now supports "ellif" clauses.

Update if-no-waste compiler to use `if*` properly.

(Sometimes one character is all it takes.)

document if

reword truthiness
2015-10-17 19:51:03 -06:00
Tuukka Turto
7a2be920fa Merge branch 'master' of github.com:hylang/hy into xor
Conflicts:
	hy/core/language.hy
2015-10-03 17:26:41 +03:00
Gergely Nagy
32f5d5dea7 Drop a set of brackets from with.
This changes with syntax from (with [[x (expr)] (expr)] ...) to (with
[x (expr) (expr)] ...). Should have no ill side effects apart from the
syntax change.

Closes #852.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-10-01 10:08:04 +02:00
Gergely Nagy
9f88e07e1d Drop a set of brackets from let.
This changes let to use a flat list of symbol-value pairs instead of a
vector of vectors. One side effect is that (let [[a 1] z]) is not
expressible now, and one will explicitly need to set a nil value for z,
such as: (let [a 1 z nil]).

Closes #713.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-10-01 10:08:04 +02:00
Gergely Nagy
26f342d580 Teach apply about symbol mangling
apply now mangles strings and keywords according to the Hy mangling
rules (by using the same function, now imported from
hy.lex.parser). With this change, if the dict passed to apply has
keywords, strings or quoted symbols, they'll get mangled, to turn them
into proper keys.

This only works for the cases where the keys are directly in the apply
params. A previously deffed dict, or key through a variable will not be
mangled.

This closes #219.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-09-24 09:47:12 +02:00
Paul Tagliamonte
fc5d74ba85 Add in documentation for non-base 10 numbers 2015-09-15 12:18:56 -04:00
Ryan Gonzalez
6c076f76f7 Allow 'for' and 'cond' to take a multi-expression body (closes #868) 2015-08-10 10:14:55 +02:00
Gergely Nagy
54fb0102aa Merge pull request #875 from algernon/glc/defclass
defclass reimagined
2015-08-10 09:39:00 +02:00
Gergely Nagy
dee02c5928
docs: Minor corrections, related to the alias removals
Fixed up the documentation language here and there, related to the alias
removals in previous commits.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-10 09:33:23 +02:00
Gergely Nagy
8e2a892469
hy.contrib.alias: Move defn-alias and defmacro-alias here
As discussed in #880, move defn-alias and defmacro-alias to a contrib
module.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-10 09:24:48 +02:00
gilch
7d8ddd9ecb remove lisp-if / lisp-if-not in favor of lif / lif-not 2015-08-09 01:21:12 -06:00
gilch
4cdfdfbafe remove defun in favor of defn 2015-08-09 01:09:52 -06:00
gilch
33e0b4b3db remove progn in favor of do 2015-08-09 01:00:51 -06:00
gilch
66c1f38fcc remove catch in favor of except 2015-08-09 00:53:10 -06:00
gilch
e8d26f1067 remove throw in favor of raise 2015-08-09 00:52:42 -06:00
Tuukka Turto
ec3874377b Merge branch 'master' of github.com:hylang/hy into xor
Conflicts:
	hy/core/language.hy
2015-08-07 06:30:37 +03:00
Calem Bendell
12db748c97 corrected slice to cut in docs
corrected slice to cut in the documentation.

also corrected a line in parse tumblr that used slice
2015-08-05 13:21:37 +02:00
Gergely Nagy
cbc2eed900
defclass reimagined
defclass now has a new syntax:

 (defclass Name [BaseList]
   [property value
    property value] ;; optional

   (defn method [self]
     self.property))

Anything after the optional property list (which will be translated to a
setv within the class context) will be added to the class body. This
allows one to have side effects and complex expressions within the class
definition.

As a side effect, defining methods is much more friendly now!

Closes #850.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-04 16:43:07 +02:00
Tuukka Turto
eaf1a3023a Change xor to binary function
xor with more than two input parameters is not well defined and people
have different expectations on how it should behave. Avoid confusion by
sticking with two parameters only.
2015-08-03 05:37:39 +03:00
Tuukka Turto
ca8b6b4fe5 Add exclusive or logical operator
Added xor to complement and, or, not operators. Standard python
falsey/truthy semantics are followed. This implementation works for
two or more parameters.
2015-08-02 23:57:46 +03:00
Zack M. Davis
016557deab reader macro #@ for with-decorator
The `with-decorator` special form is not the most ergonomic—this commit
introduces a new builtin `#@` reader macro that expands to an invocation
of `with-decorator`. To support this, `reader_macroexpand` is made to
also look in the default `None` namespace, in imitation of how
regular (non-reader) macros defined in hy.core are looked up. The
docstring of `hy.macros.reader` is also edited slightly for accuracy.

This in the matter of issue #856.
2015-07-26 15:05:38 -07:00
Ryan Gonzalez
736d7a7991 Let setv take pairs of arguments (ref. #844) 2015-07-25 17:45:34 -05:00
Zack M. Davis
4b00a84f9f documentation for &kwonly 2015-07-22 22:06:51 -07:00
Morten Linderud
c2fe74c4a2 Merge pull request #803 from farhaven/nonlocal-doc
Add documentation for the (nonlocal ...) directive
2015-07-01 15:30:30 +02:00
Gregor Best
b106e3c08d Expand doc for defn with &kwargs 2015-07-01 14:57:53 +02:00
Ewald Grusk
296b6eaa2a documents order of variable assignments in let expressions 2015-06-13 21:10:57 +02:00
Gregor Best
4adddbbf25 Allow specification of global table and module name for (eval ...) 2015-05-20 20:44:52 +02:00
Gregor Best
802ef0cd0d reword nonlocal doc a bit to mention nested fn scopes as well 2015-05-12 09:30:22 +02:00
Gregor Best
5743f6ae78 Add versionadded tag to nonlocal doc 2015-05-12 09:29:55 +02:00
Gregor Best
e4ed5cc357 Mention that nonlocal is for Python3.0 and up only 2015-05-12 00:00:54 +02:00
Gregor Best
9ed9bc5e11 Add documentation for the (nonlocal ...) directive
Signed-off-by: Gregor Best <gbe@unobtanium.de>
2015-05-11 23:38:02 +02:00
Berker Peksag
685688f04c Update versionadded directives.
0.11.0 is a backwards incompatible release.
2015-05-09 22:12:04 +03:00
Antony Woods
0496b7f7b6 Added name to AUTHORS and added documentation 2015-03-19 08:43:11 +00:00
Nicolás Della Penna
750d7b51be minor change
changed the specific values to make the example slightly more clear
2015-03-12 03:38:15 +02:00
Adrià Garriga-Alonso
f7b5486b69 Assert now may take an optional label, like in Python 2015-02-22 17:34:19 +01:00
Kevin Yap
8c0ac0862f Adhere to CPython's documentation guidelines
- Inline code is written using ``double backticks``
- Italicized text uses *asterisks* rather than `single backticks`
- Function parameters are italicized rather than written as inline code
2014-12-07 02:09:43 -08:00
Kevin Yap
997501bcc4 Fixes to language documentation
- Use backticks consistently for inline code
- Capitalize section headers and proper nouns
- Minor grammatical fixes
2014-12-06 15:46:44 -08:00
Tianon Gravi
96410f506e Add a dedicated lisp-if-not / lif-not macro
This is in parallel to `if` / `if-not` (so not without precedent). :)
2014-11-06 12:44:15 -07:00
Abhishek L
1da6d0af43 docs: fix decorator to reflect multiple decorators
* docs/language/api.rst: the `with-decorator' builtin supports multiple
  decorators which it applies in order. Docs are updated to reflect this
2014-05-24 17:35:39 +05:30
Berker Peksag
0f0c4227b6 Merge pull request #604 from Duta/master
Minor typo
2014-05-17 22:29:44 +03:00
Bertie Wheen
02fa251175 Minor typo
Sorry for tiny commits :P
2014-05-17 19:04:41 +01:00
Bertie Wheen
a102a268a9 Rephrased confusing comment 2014-05-17 18:46:01 +01:00
Tuukka Turto
726d1735db Merge branch 'master' into pr/571
Conflicts:
	AUTHORS
	tests/native_tests/core.hy
2014-05-13 09:32:51 +03:00
Abhishek L
4f74652c73 the mega typo fix commit
Wow! much typos! such fix!
2014-05-05 23:47:14 +05:30
Abhishek L
ad0191f343 Merge master onto pr/580 2014-05-02 19:37:54 +05:30
Tuukka Turto
d539f73d4d correct ..versionadded:: for defmain
my mistake, should have spotted before merging and pushing
2014-05-02 12:27:19 +03:00
Tuukka Turto
b1a928037e Merge branch 'master' into pr/526 2014-05-02 10:34:37 +03:00
pyos
f02e044719 Move the documentation for zipwith to the correct place. 2014-04-29 18:04:21 +04:00
Tuukka Turto
01fa9d6a3c document set-comp 2014-04-28 21:35:28 +03:00
Tuukka Turto
3a66a2d1be document dict-comp and genexpr 2014-04-28 21:09:06 +03:00
Matthew Wampler-Doty
fa5f51e0f1 Adding Version Added 0.10.1 2014-04-25 08:19:22 -05:00
Matthew Wampler-Doty
834b0019a7 Fixing doto to be API compatible with Clojure's doto 2014-04-21 12:35:56 -07:00
Tuukka Turto
f4b67e8bd8 documentation for doto
relates #567
2014-04-21 13:28:08 +03:00
Morten Linderud
e5e1489f0f Merge pull request #553 from berkerpeksag/missing-versionadded
Add a missing versionadded directive to the lisp-if/lif documentation.
2014-04-13 17:33:20 +02:00
Berker Peksag
c5dfba3c4f Fix a code-block in the lambda documentation. 2014-04-13 18:04:42 +03:00
Berker Peksag
07b9371cb8 Add a missing versionadded directive to the lisp-if/lif documentation. 2014-04-13 17:42:48 +03:00
Paul Tagliamonte
217f3ad65f Merge branch 'master' into pr/515 2014-04-10 22:52:41 -04:00
Christopher Allan Webber
d5194f23fa Properly add yield-from, using python's real "yield from".
The yield-from that existed previously wasn't actually implementing the
full complexity of "yield from":

  http://legacy.python.org/dev/peps/pep-0380/#formal-semantics

... this includes passing along errors, and many other things.

Also removes the yield-from backport macro, since it does not seem
possible at present to conditionally build macros.

Thus, there is no longer yield-from on pre-python-3.3 systems.

Includes updated docs and tests to reflect all this.
2014-04-10 14:07:49 -05:00
Christopher Allan Webber
774aad2ca8 defmain macro; handles the whole if __name__ == __main__ / main function dance
Example:

  (defmain [&rest args]
    (print "now we're having a fun time!")
    (print args))

Which outputs:

  $ hy test.hy
  now we're having a fun time!
  (['test.hy'],)

Includes documentation and tests.
2014-04-10 13:58:38 -05:00
Christopher Allan Webber
f3d978c5a3 Added lisp-if (or lif), with tests and documentation.
Now everyone can get along and everyone can have a pony, and that pony is
actually a unicorn that shoots rainbows from its horn.
2014-04-10 13:51:28 -05:00
Abhishek L
378ffae6f7 Fix versionadded in docs to 0.10.0 release 2014-04-10 23:51:32 +05:30
Berker Peksag
3528cc8278 Kill kwapply.
Closes #433.
2014-04-09 20:10:31 +03:00
Christopher Allan Webber
fa69d80b8d Merge pull request #528 from bcj/patch-2
and/or now short-circuit
2014-03-16 15:27:05 -05:00
Brendan Curran-Johnson
a210a673a2 and/or now short-circuit
Updated to reflect that and/or actually short-circuit now.
2014-03-14 16:53:10 -05:00
Bob Tolbert
4798863e0f This change updates the required Pygments version to 1.6, which
supports Hy code.

All code-blocks in the documentation have been changed from
clojure to hy.

Also added docs/make.bat for Windows, so the top-level docs
target now works on Windows as well.
2014-03-14 09:01:47 -04:00
Christopher Allan Webber
ecfd737fb9 Document how to supply docstrings to classes and class methods / lambdas
We want to encourage good practice, documentation-wise, amongst Hy
users!
2014-02-23 15:20:43 -06:00
Berker Peksag
6829d6fb3a Tweak the zipwith doc a bit and add @kirbyfan64 to AUTHORS. 2014-02-22 02:21:34 +02:00
kirbyfan64
d282d65cde Add zipwith 2014-02-22 02:14:27 +02:00
Richard Parsons
6b4e3940aa updated import documentation 2014-02-11 15:54:55 +00:00
Nicolas Dandrimont
b99af411c8 Merge branch 'master' into pr/461
Conflicts:
	tests/native_tests/native_macros.hy
2014-01-23 21:57:17 +01:00
Gergely Nagy
e90b24b73a
hy/core/macros.hy: Add an (if-not) macro
Sometimes it is better to start with the false condition, sometimes that
makes the code clearer. For that, the (if-not) macro, which simply
reverses the order of the condition blocks, can be of great use.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-01-18 22:56:20 +01:00