A dialect of Lisp that's embedded in Python
parse-args
is no longer implemented with eval
; so e.g. you should now say :type int
instead of :type 'int
.hy -c
.require
s.defclass
has been removed. Use setv
and defn
instead.hy.contrib.multi
has been removed. Use cond
or the PyPI package multipledispatch
instead.HySequence
is now a subclass of tuple
instead of list
. Thus, a HyList
will never be equal to a list
, and you can't use .append
, .pop
, etc. on a HyExpression
or HyList
.py
to pys
that allow Hy programs to include inline Python code.cmp
for chained comparisons.%=
and ^=
) now allow more than two arguments.parse-args
as a wrapper for Python's argparse
.assert
are now executed.while
to be compiled twice.in
and not-in
now allow more than two arguments, as in Python.hy2py
can now handle format strings.test
.hy.extra.anaphoric
.clint
with colorama
.Warning: Hy 0.17.x will be the last Hy versions to support Python 2, and we expect 0.17.0 to be the only release in this line. By the time 0.18.0 is released (in 2020, after CPython 2 has ceased being developed), Hy will only support Python 3.
f"The sum is {(+ x y)}"
) are now supported, even on Pythons earlier than 3.6.setx
to create Python 3.8 assignment expressions.list?
and tuple
._hyx_XsemicolonXfooXvertical_lineX1235
is now _hyx_fooXUffffX1
).()
) are no longer legal at the top level.eval
/ hy_eval
and hy_compile
now accept an optional compiler
argument that enables the use of an existing HyASTCompiler
instance.(get obj :key)
, and they accept a default value as a second argument.require
their own macro dependencies.__macros__
and __tags__
attributes.defmain
with an empty lambda list.require
now compiles to Python AST.require
\s.from __future__ import ...
statements and missing Hy module docstrings caused by automatic importing of Hy builtins.__main__
file execution.hy-repr
on date and time objects.mangle
for some pathological inputs.tokenize
.HyCons
, cons
, cons?
, and list*
have been removed. These were redundant with Python's built-in data structures and Hy's most common model types (HyExpression
, HyList
, etc.).&key
is no longer special in lambda lists. Use &optional
instead.ap-pipe
and ap-compose
have been removed. Use threading macros and comp
instead.for/a
has been removed. Use (for [:async ...] ...)
instead.(except)
is no longer allowed. Use (except [])
instead.(import [foo])
is no longer allowed. Use (import foo)
instead.HyExpression
, HyDict
, and HySet
no longer inherit from HyList
. This means you can no longer use alternative punctuation in place of square brackets in special forms (e.g. (fn (x) ...)
instead of the standard (fn [x] ...)
).
Mangling rules have been overhauled; now, mangled names are always legal Python identifiers.
_
and -
are now equivalent, even as single-character names.
_
is now *1
.Non-shadow unary =
, is
, <
, etc. now evaluate their argument instead of ignoring it.
list-comp
, set-comp
, dict-comp
, and genexpr
have been replaced by lfor
, sfor
, dfor
, and gfor
, respectively, which use a new syntax and have additional features. All Python comprehensions can now be written in Hy.
&
-parameters in lambda lists must now appear in the same order that Python expects.
Literal keywords now evaluate to themselves, and HyKeyword
no longer inherits from a Python string type
HySymbol
no longer inherits from HyString
.
while
and for
are allowed to have empty bodies.for
supports the various new clause types offered by lfor
.defclass
in Python 3 supports specifying metaclasses and other keyword arguments.mangle
and unmangle
as core functions.*2
and *3
.*e
.-E
per CPython.hy.model_patterns
.hy2py
should now output legal Python code equivalent to the input Hy code in all cases.(return)
so it can exit a Python 2 generator.->
and ->>
duplicated an argument.defclass
to drop statements or crash.NaN
can no longer create an infinite loop during macro-expansion.try
to drop expressions.unquote-splice
.defmacro!
now allows optional arguments.let
.hy-repr
uses registered functions instead of methods.hy-repr
supports more standard types.def
is gone; use setv
insteadapply
is gone; use the new #*
and #**
syntax insteadyield-from
is no longer supported under Python 2Inf
\s and NaN
\s must now be capitalized like thatxi
from hy.extra.anaphoric
is now a tag macro #%
eval
is now a function instead of a special form(eval `(+ 1 ~n))
instead of (eval `(+ 1 ~(HyInteger n)))
return
has been implemented as a special form#[FOO[
and ]FOO]
, where FOO
is customizableasync
and await
) with fn/a
, defn/a
, with/a
, and for/a
#*
and #**
(e.g., (f #* args #** kwargs)
)comment
#_
syntax to discard the next termwhile
loops may now contain an else
clause, like for
loops#%
works on any expression and has a new &kwargs
parameter %**
doc
and a tag macro #doc
get
is available as a function~@
(unquote-splice
) form now accepts any false value as emptyPYTHONDONTWRITEBYTECODE
!
are no longer mistaken for shebang lines(quit)
or (exit)
exec
now works under Python 2defn
returning values evaluating to None
try
forms are now possible in defmacro
and deftag
try
macroexpand
\ing a macro with a named importwith
suppresses an exception. with
now returns None
in this case.--repl-output-fn
raises an exceptionHyTypeError
was raised with objects that had no source positionassoc
now evaluates its arguments only once eachelse
clause of a for
loopelse
clauses in for
and while
are recognized more reliablywhile
loop are repeated properlyyield-from
is now a syntax errorbreak
and continue
now raise an error when given arguments instead of silently ignoring themread
, read_str
, and eval
are exposed and documented as top-level functions in the hy
modulelet
macro has been added to hy.contrib.walk
Changed setup.py to require astor 0.5, since 0.6 isn't backwards-compatible.
let
has been removed. Python's scoping rules do not make a proper implementation of it possible. Use setv
instead.lambda
has been removed, but fn
now does exactly what lambda
diddefreader
has been renamed to defsharp
; what were previously called "reader macros", which were never true reader macros, are now called "sharp macros"try
now enforces the usual Python order for its elements (else
must follow all except
s, and finally
must come last). This is only a syntactic change; the elements were already run in Python order even when defined out of order.try
now requires an except
or finally
clause, as in Pythonbytes
objects under Python 3 and str
objects under Python 2**
, //
, not
, in
) can be used as first-class functions(** a b c d)
is now equivalent to (** a (** b (** c d)))
, not (** (** (** a b) c) d)
setv
always returns None
try
form executes an else
clause, the return value for the try
form is taken from else
instead of the try
body. For example, (try 1 (except [ValueError] 2) (else 3))
returns 3
.xor
: If exactly one argument is true, return ithy.core.reserved
is now hy.extra.reserved
cond
now supports single argument branchesand
instead of &
for chained comparisonspartition
no longer prematurely exhausts input iteratorsread
and read-str
no longer raise an error when the input parses to a false value (e.g., the empty string)yield
inside of a with
statement will properly suppress implicit returnssetv
no longer unnecessarily tries to get attributesloop
no longer replaces string literals equal to "recur"do
and try
formshy-repr
--repl-output-fn
This release brings some quite significant changes on the language and as a result very large portions of previously written Hy programs will require changes. At the same time, documentation and error messages were improved, hopefully making the language easier to use.
let
, with
and defclass
&kwonly
, &kwargs
and &key
arguments#{1 2 3}
)setv
, del
and cond
=
, !=
, <
, >
, <=
, >=
)partition
form for chunking collection to n-sized tuplesdefn-alias
and demacro-alias
moved into hy.contrib.alias
None
is returned instead of the last form in --init--
for
and cond
can take a multi-expression bodyapply
now mangles strings and keywords according to Hy mangling rulesif
defreader
can use strings as macro namesas->
macro addedrequire
syntax changed and now supports same features as import
defmulti
changed to work with dispatching functiondefmulti
renamed to defn
contrib
defmacro!
added for once-only evaluation for parameterscomp
, constantly
, complement
and juxt
addedfor
doesn't have bodydefclass
can have properties / methods with built-in nameshy2py
and hyc
&rest
can be used after &optional
(eval ...)
contrib.walk
: Coerce non-list iterables into list formcase
and switch
)ap-pipe
and ap-compose
macros#@
reader macro for with-decoratoreval
parametersand
and or
short-circuitand
and or
accept zero or more argumentsread-str
for tokenizing a linebotsbuildbots
moved to contribxi
forms (anonymous function literals)if
form optimizations in some casesxor
operatorap-if
requires then
branchinc
, dec
, odd?
, even?
, etc.) aren't type checkedimport_file_to_globals
added for use in emacs inferior lisp modehy.core.reserved
added for querying reserved wordshy2py
can use standard input instead of a filealias
, curry
, flow
and meth
removed from contrib
contrib.anaphoric
moved to hy.extra