Hy - A dialect of Lisp that's embedded in Python

Overview

Hy

Version

XKCD #224

Lisp and Python should love each other. Let's make it happen.

Hy is a Lisp dialect that's embedded in Python. Since Hy transforms its Lisp code into Python abstract syntax tree (AST) objects, you have the whole beautiful world of Python at your fingertips, in Lisp form.

To install the latest alpha of Hy, just use the command pip3 install --pre --user hy. Then you can start an interactive read-eval-print loop (REPL) with the command hy, or run a Hy program with hy myprogram.hy.

Project

Cuddles the Hacker

(fan art from the one and only doctormo)

Comments
  • Macro processing updates and fixes

    Macro processing updates and fixes

    This PR changes the way macros are loaded and managed within modules/namespaces, their scope of evaluation, and how require statements are treated during the module bytecode loading process.

    Alongside those changes, a general refactoring was started that moves toward a HyASTCompiler that can operate in two fashions: 1) compilation that occurs within a module and allows macros to interact with the compiler (as they are currently configured to do), and 2) compilation that does not require a concrete module context but does not allow true macro-compiler interaction. The latter case could drastically simplify some of the module importing work-arounds that currently exist in this PR (e.g. when interacting with runpy).

    It addresses/closes the following issues:

    • [x] https://github.com/hylang/hy/issues/1268
    • [x] https://github.com/hylang/hy/issues/1650
    • [x] https://github.com/hylang/hy/issues/1416

    Example

    Before

    hy 0.15.0+39.gd2319dc using CPython(default) 3.6.6 on Linux
    => (with [file (open "test_mod.hy" "w")] (file.write "(require [hy.contrib.walk [let]])\n\n(defmacro test-macro [x]\n  `(let [y ~x] (print y)))\n"))
    87
    => (with [file (open "test_mod.hy" "r")] (print (file.read)))
    (require [hy.contrib.walk [let]])
    
    (defmacro test-macro [x]
      `(let [y ~x] (print y)))
    
    => (require [test-mod [test-macro]])
    => (test-macro 1)
    Traceback (most recent call last):
      File "/home/bwillard/projects/code/python/hy-master/hy/importer.py", line 141, in hy_eval
        return eval(ast_compile(expr, "<eval>", "eval"), namespace)
      File "<eval>", line 1, in <module>
    NameError: name 'let' is not defined
    

    After

    hy 0.15.0+45.ga8d6a48 using CPython(default) 3.6.6 on Linux
    => (with [file (open "test_mod.hy" "w")] (file.write "(require [hy.contrib.walk [let]])\n\n(defmacro test-macro [x]\n  `(let [y ~x] (print y)))\n"))
    87
    => (with [file (open "test_mod.hy" "r")] (print (file.read)))
    (require [hy.contrib.walk [let]])
    
    (defmacro test-macro [x]
      `(let [y ~x] (print y)))
    
    => (require [test-mod [test-macro]])
    True
    => (test-macro 1)
    1
    => (import [pprint [pprint]])
    => (pprint __macros__)
    {'_hyx_XgreaterHthan_signX': <function _hy_anon_var_14 at 0x7fbc2fef0a60>,
     '_hyx_XgreaterHthan_signXXgreaterHthan_signX': <function _hy_anon_var_17 at 0x7fbc2fef0b70>,
     'assoc': <function _hy_anon_var_3 at 0x7fbc2fef07b8>,
     'comment': <function _hy_anon_var_29 at 0x7fbc2fef31e0>,
     'cond': <function _hy_anon_var_13 at 0x7fbc2fef09d8>,
     'defmacro': <function _hy_anon_var_3 at 0x7fbc2fee70d0>,
     'defmain': <function _hy_anon_var_27 at 0x7fbc2fef30d0>,
     'defn': <function _hy_anon_var_11 at 0x7fbc2fee7378>,
     'deftag': <function _hy_anon_var_7 at 0x7fbc2fee7268>,
     'doc': <function _hy_anon_var_30 at 0x7fbc2fef3268>,
     'doto': <function _hy_anon_var_16 at 0x7fbc2fef0ae8>,
     'hyx_as_XgreaterHthan_signX': <function _hy_anon_var_1 at 0x7fbc2fee7598>,
     'hyx_defmacroXexclamation_markX': <function _hy_anon_var_26 at 0x7fbc2fef3048>,
     'hyx_defmacroXsolidusXgXexclamation_markX': <function _hy_anon_var_24 at 0x7fbc2fef0f28>,
     'hyx_defnXsolidusXa': <function _hy_anon_var_14 at 0x7fbc2fee7400>,
     'hyx_if': <function _hy_anon_var_4 at 0x7fbc2fee71e0>,
     'hyx_with': <function _hy_anon_var_7 at 0x7fbc2fef08c8>,
     'hyx_withXsolidusXa': <function _hy_anon_var_8 at 0x7fbc2fef0950>,
     'ideas': <function ideas_macro at 0x7fbc302698c8>,
     'if_not': <function _hy_anon_var_18 at 0x7fbc2fef0bf8>,
     'if_python2': <function _hy_anon_var_15 at 0x7fbc2fee7488>,
     'koan': <function koan_macro at 0x7fbc30269840>,
     'lif': <function _hy_anon_var_19 at 0x7fbc2fef0c80>,
     'lif_not': <function _hy_anon_var_20 at 0x7fbc2fef0d08>,
     'macro_error': <function _hy_anon_var_8 at 0x7fbc2fee72f0>,
     'test_macro': <function <lambda> at 0x7fbc2fd9f598>,
     'unless': <function _hy_anon_var_22 at 0x7fbc2fef0e18>,
     'when': <function _hy_anon_var_21 at 0x7fbc2fef0d90>,
     'with_gensyms': <function _hy_anon_var_23 at 0x7fbc2fef0ea0>}
    
    opened by brandonwillard 64
  • Implement #qC string literals

    Implement #qC string literals

    Closes #1287.

    There's no documentation or NEWS update yet.

    ~~Note that matching delimiters are supported, but not inner pairs of matching delimiters (e.g., #q(()) is parsed the same as "(" )). This is because the lexer is regex-based, and Python doesn't implement recursive regexes.~~ Matching delimiters are supported.

    ~~@gilch, I didn't reserve a character for indicating multi-character delimiters since you hadn't seemed to settle on [,=, or <.~~ Multi-character delimiters are indicated with <.

    opened by Kodiologist 64
  • yet another let implementation

    yet another let implementation

    Once again, a major breaking change that nobody asked for, even though I haven't even finished the last one.

    Here's a (draft) implementation that adds tracking of scoping information, allowing us to implement let as a first-class result macro.

    I did my best to have let bindings interact nicely with Python's normal scoping rules; that is, let bindings are as close to possible as standard assignment.

    Examples!

    This example is fairly straightforward; x refers to the name outside the function.

    (let [x 1]
      (defn foo []
        (print x)))
    (foo)
    
    _hy_scope_1_x = 1
    def foo():
        return print(_hy_scope_1_x)
    foo()
    

    If we assign to x inside the function, then per Python scoping rules, x is entirely local to the function despite any assignment outside:

    # showing "actual" assignment for this example
    x = 1
    def foo():
        print(x)  # UnboundLocalError
        x = 8
    foo()
    

    Therefore, this is how the corresponding Hy compiles:

    (let [x 1]
      (defn foo []
        (print x)
        (setv x 8)))
    (foo)
    
    _hy_scope_1_x = 1
    def foo():
        print(x)  # UnboundLocalError, as "expected"
        x = 8
    foo()
    

    However, if we use a nonlocal/global, then all is well again!

    (let [x 1]
      (defn foo []
        (global x)
        (print x)
        (setv x 8)))
    (foo)
    
    _hy_scope_1_x = 1
    def foo():
        global _hy_scope_1_x
        print(_hy_scope_1_x)
        _hy_scope_1_x = 8  # assigns to outer `x`!
    foo()
    

    I need to experiment further, but I think the scope tracking can also help us solve the problem from #1994 with setx and scope weirdness with generator forms.

    opened by scauligi 57
  • Generate more concise syntax and compiler errors

    Generate more concise syntax and compiler errors

    This PR refactors the exception/error classes and their handling, keeps Hy source strings and their corresponding file information (if any) closer to the origin of an exception (so that calling code isn't responsible for annotating exceptions), and provides minimally intrusive traceback print-out filtering via a context manager that temporarily alters sys.excepthook (this is automatically enabled for Hy command-line sessions).

    New environment and package variables have been introduced, as well:

    • HY_COLORED_ERRORS, and package variable, hy.errors._hy_colored_errors, that enables/disables manual error coloring, and
    • HY_COLORED_AST_OBJECTS, and package variable, hy.models._hy_colored_ast_objects, that enables/disables AST object coloring.

    Also, source caching has been added to the Hy interpreter. It's modeled after the approach used by IPython via linecache. Now, for example, traces will show the relevant source lines for functions, objects, etc., defined exclusively in the REPL (see the example below).

    • [x] #657
    • [x] #1510
    • [x] #1429
    • [x] #1397
    • [x] #1486 (the error message part)

    Notes

    As mentioned above, the sys.excepthook provided here only hides internal frames from the traceback print-out, and not the actual traceback object, so, for instance, it does not affect the stack in pdb.

    There are other, more powerful and direct approaches that involve altering and/or creating low-level traceback objects (e.g. Jinja's). These allow for a better debugging experience (e.g. without any compiler or parser frames), but they're also more complicated and distribution dependent. In the long run, I think it's better to have custom tracebacks, so I'll keep an eye on good/better ways to do this; for example, this approach is interesting.

    Example

    Before

    hy 0.15.0+39.gd2319dc using CPython(default) 3.6.6 on Linux
    => (with [file (open "a.hy" "w")] (file.write "(print 'hi\""))
    11
    => (import a)
    Traceback (most recent call last):
      File "/home/bwillard/projects/code/python/hy-master/hy/importer.py", line 138, in hy_eval
        eval(ast_compile(_ast, "<eval_body>", "exec"), namespace)
      File "<eval_body>", line 1, in <module>
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 674, in exec_module
      File "<frozen importlib._bootstrap_external>", line 781, in get_code
      File "/home/bwillard/projects/code/python/hy-master/hy/importer.py", line 228, in _hy_source_to_code
        hy_tree = hy_parse(source)
      File "/home/bwillard/projects/code/python/hy-master/hy/importer.py", line 65, in hy_parse
        return HyExpression([HySymbol("do")] + tokenize(source + "\n"))
      File "/home/bwillard/projects/code/python/hy-master/hy/lex/__init__.py", line 19, in tokenize
        return parser.parse(lexer.lex(buf))
      File "/home/bwillard/apps/anaconda3/envs/hy-master-cpython36/lib/python3.6/site-packages/rply/parser.py", line 23, in parse
        t, symstack, statestack, state
      File "/home/bwillard/apps/anaconda3/envs/hy-master-cpython36/lib/python3.6/site-packages/rply/parser.py", line 80, in _reduce_production
        value = p.func(targ)
      File "/home/bwillard/projects/code/python/hy-master/hy/lex/parser.py", line 223, in t_partial_string
        raise PrematureEndOfInput("Premature end of input")
    hy.lex.exceptions.PrematureEndOfInput: LexException: Premature end of input
    
    => (require blah)
    Traceback (most recent call last):
      File "/home/bwillard/projects/code/python/hy-master/hy/importer.py", line 120, in hy_eval
        _ast, expr = hy_compile(hytree, module_name, get_expr=True)
      File "/home/bwillard/projects/code/python/hy-master/hy/compiler.py", line 1716, in hy_compile
        result = compiler.compile(tree)
      File "/home/bwillard/projects/code/python/hy-master/hy/compiler.py", line 350, in compile
        ret = self.compile_atom(tree)
      File "/home/bwillard/projects/code/python/hy-master/hy/compiler.py", line 344, in compile_atom
        return Result() + _model_compilers[type(atom)](self, atom)
      File "/home/bwillard/projects/code/python/hy-master/hy/compiler.py", line 1584, in compile_expression
        self, expr, unmangle(sroot), *parse_tree)
      File "/home/bwillard/projects/code/python/hy-master/hy/compiler.py", line 573, in compile_do
        return self._compile_branch(body)
      File "/home/bwillard/projects/code/python/hy-master/hy/compiler.py", line 444, in _compile_branch
        ret += self.compile(exprs[-1])
      File "/home/bwillard/projects/code/python/hy-master/hy/compiler.py", line 361, in compile
        raise_empty(HyCompileError, e, sys.exc_info()[2])
      File "<string>", line 1, in raise_empty
    hy.errors.HyCompileError: Internal Compiler Bug 😱
    ⤷ ModuleNotFoundError: No module named 'blah'
    Compilation traceback:
    File "/home/bwillard/projects/code/python/hy-master/hy/compiler.py", line 350, in compile
        ret = self.compile_atom(tree)
      File "/home/bwillard/projects/code/python/hy-master/hy/compiler.py", line 344, in compile_atom
        return Result() + _model_compilers[type(atom)](self, atom)
      File "/home/bwillard/projects/code/python/hy-master/hy/compiler.py", line 1584, in compile_expression
        self, expr, unmangle(sroot), *parse_tree)
      File "/home/bwillard/projects/code/python/hy-master/hy/compiler.py", line 1154, in compile_import_or_require
        importlib.import_module(module)
      File "/home/bwillard/apps/anaconda3/envs/hy-master-cpython36/lib/python3.6/importlib/__init__.py", line 126, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 994, in _gcd_import
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
    => (defn test [x]
    ... (print(+ 1 x))
    ... )
    => (test 'a)
    Traceback (most recent call last):
      File "/home/bwillard/projects/code/python/hy-master/hy/importer.py", line 141, in hy_eval
        return eval(ast_compile(expr, "<eval>", "eval"), namespace)
      File "<eval>", line 1, in <module>
      File "<eval_body>", line 1, in test
    TypeError: unsupported operand type(s) for +: 'int' and 'HySymbol'
    => (defmacro blah [x] `(print ~@z))
    <function <lambda> at 0x7f1351095730>
    => (defmacro bleh [q] `(print (blah ~q)))
    <function <lambda> at 0x7f1351095840>
    => (bleh y)
      File "<input>", unknown location
    HyMacroExpansionError: expanding `blah': NameError("name 'z' is not defined",)
    
    => (defn foo []
    ... (setv bar 42)
    ... (import pdb) (pdb.set-trace))
    => (foo)
    --Return--
    > <eval_body>(1)foo()->None
    (Pdb) l
    [EOF]
    

    After

    hy 0.15.0+45.ga8d6a48 using CPython(default) 3.6.6 on Linux
    => (with [file (open "a.hy" "w")] (file.write "(print 'hi\""))
    11
    => (import a)
    Traceback (most recent call last):
      File "stdin-99c0d4eb813cb56c622500ab4696f5bbb3cb3660", line 1, in <module>
        (import a)
      File "<frozen importlib._bootstrap>", line 971, in _find_and_load
      File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 674, in exec_module
      File "<frozen importlib._bootstrap_external>", line 781, in get_code
      File "/tmp/a.hy", line 1
        (print 'hi"
                  ^
    hy.lex.exceptions.PrematureEndOfInput: Partial string literal
    => (require blah)
    Traceback (most recent call last):
      File "stdin-97db2eacebe610e14f46e56e428d68ec1c466f2f", line 1, in <module>
        (require blah)
    hy.errors.HyRequireError: No module named 'blah'
    => (defn test [x]
    ... (print (+ 1 x))
    ... )
    None
    => (test 'a)
    Traceback (most recent call last):
      File "stdin-e199a43c50b388bff5e7901a7a1f02f5525d862d", line 1, in <module>
        (test 'a)
      File "stdin-71d0b2f8a864d8760f5a5eab4efa209694ee2714", line 2, in test
        (print (+ 1 x))
    TypeError: unsupported operand type(s) for +: 'int' and 'HySymbol'
    => (defmacro blah [x] `(print ~@z))
    <function <lambda> at 0x7fd6741319d8>
    => (defmacro bleh [q] `(print (blah ~q)))
    <function <lambda> at 0x7fd674131268>
    => (bleh y)
    Traceback (most recent call last):
      File "stdin-ff397ee5ec5c34f03703a2acccc9f62ed9b3a9ae", line 1, in <module>
        (bleh y)
      File "stdin-a0f7e3bfef673f0bae54abd3721c76c25db16c65", line 1, in <lambda>
        (defmacro blah [x] `(print ~@z))
    hy.errors.HyMacroExpansionError: expanding macro blah
      NameError: name 'z' is not defined
    => (defn foo []
    ... (setv bar 42)
    ... (import pdb) (pdb.set-trace))
    None
    => (foo)
    --Return--
    > /home/bwillard/stdin-2741f77da2a8503d126c87cd48d527a65903cc14(3)foo()->None
    (Pdb) l
      1  	(defn foo []
      2  	(setv bar 42)
      3  ->	(import pdb) (pdb.set-trace))
    [EOF]
    
    opened by brandonwillard 54
  • Homoiconic REPL

    Homoiconic REPL

    This pull request adds a function hy-repr and uses it to print out stuff in the REPL (edit: only when you launch Hy with --hy-repr).

    Closes hylang/hy#351.

    hylang/hy#1244 is a prerequesite. Merge that first and I'll rebase this.

    An annoying consequence of this change (edit: now fixed, using the method listed second below) is that setv at the REPL now prints the value of whatever you assigned. I think this is bad because when I'm doing data analysis on the REPL, I often say things like (setv x (some-function-that-produces-a-huge-pandas-dataframe)), and I don't want that printed. I see two ways around this:

    • Make setv always return None. The question of what setv should return, particularly in the REPL, is kind of a mess, anyway (#249, hylang/hy#871, hylang/hy#1049), so this change would eliminate another weird corner of the language.
    • Make the REPL check whether the last statement of each input is ast.Assign, and if so, don't print the value.

    As for the documentation examples, I don't think we should bother systematically updating them before we have documentation tests.

    opened by Kodiologist 53
  • Get rid of let

    Get rid of let

    We all know let is broken. There have been many proposed solutions, but one option that no-one has offered--or perhaps actually thought of, but never dared to say--is to get rid of let altogether.

    I understand this may be controversial. If at least a couple of core members feel strongly that Hy must have a let, then feel free to close this issue and I'll not mention it again. But do hear me out first.

    Remember the main selling point of Hy: "We're still Python(TM). Most of the internals translate 1:1 to Python internals." Hy is not Clojure, nor Common Lisp, but homoiconic Python. Do we really need let?

    In the older Lisps, usually let is just used to create a local variable. Hy can do this more simply with the setv form. Python has no block scope. Creating and calling a new function just for a local or two is pretty inefficient in Python. Shouldn't we encourage users to use setv anyway in such cases? This approach also breaks break continue yield and would break return if we had it (we should). There may be other problems I haven't thought of.

    Now I'm confident that, in time, we could fix all of these issues, perhaps with an alternative approach. But all of these alternatives will expand into something complicated especially compared to setv. There will likely be overhead or other nasty surprises.

    If someone really needs a new scope block (perhaps to control variable lifetime in a macro), then there's nothing stopping them from explicitly doing it the same way as they would in Python. Perhaps with a class, function or dictionary. Then those familiar with Python would not be surprised by their expectations about how let is supposed to work and we wouldn't have to port nonlocal to Python 2.

    opened by gilch 49
  • Custom Parser and Reader Macros

    Custom Parser and Reader Macros

    closes #722

    Open question if hy should support such a permissive reader macros. This PR has it so you can define a reader for any single char or any sym prefixed by a #.

    In my opinion reader macros prefised by # are more idiomatic and restricting user defined macros to only ones prefixed by # would make Hy more predictable and tooling easier down the road. I'd be in favor of that kind of restriction, but i'll leave that as an open question for discussion.

    There's also the behavior of reader macros on require. Right now, readers macros need to be required per module and then enabled per module. This is how Racket works and to me seems like the right thing to do for a macro that drastically change how code looks and is written. Again another question for discussion though.

    @scauligi as this was your baby, do you have any thoughts?

    opened by allison-casey 44
  • added defmacro!

    added defmacro!

    I saw defmacro/g! in Let Over Lambda before I saw it in Hy, but it's just a helper macro for the real utility: defmacro!, which is like defmacro/g!, plus automatic once-only evaluation for o! parameters, which are available as the equivalent g! symbol. This pull translates defmacro! to Hy.

    For those who haven't read the book, a common problem with macros is multiple-evaluation.

    => (defn expensive-get-number [] (print "spam") 14)
    => (defmacro triple-1 [n] `(+ n n n))
    => (triple-1 (expensive-get-number))  ; evals n three times!
    spam
    spam
    spam
    42
    

    You can avoid this with a gensym:

    => (defmacro/g! triple-2 [n] `(do (setv ~g!n ~n) (+ ~g!n ~g!n ~g!n)))
    => (triple-2 (expensive-get-number))  ; avoid repeats with a gensym
    spam
    42
    

    But this is more concise and clear with defmacro!, which does that for you:

    => (defmacro! triple-3 [o!n] `(+ ~g!n ~g!n ~g!n))
    => (triple-3 (expensive-get-number))  ; easier with defmacro!
    spam
    42
    
    opened by gilch 44
  • Refactor/docs overhaul

    Refactor/docs overhaul

    Complete overhaul of the Hy docs to unify the documentation for the core api in one place. Uses my Sphinx Hy Domain extension (do we want to bring this under hylang while were at it? It's not complete, but it has what we need for right now) to autogenerate the docs for almost all the core library. Existing method docs have been migrated into the docstrings of their respective methods/modules. All method documentation is now unified under api.rst and navigable from cheatsheet.rst (I need help defining the categories for this). Closes #1845, Closes #1915, Closes #1044

    Only core lib code changes, were adding docstring pass through to defmacro/g! and defmacro! which closes closes #1423 and closes #1424

    I'm sure I've missed some things and there might be some bugs in hydomain I haven't noticed, but at this point I think it needs some more eyes on it because I'm starting to go blind to it lol.

    opened by allison-casey 41
  • Make and/or short-circuit

    Make and/or short-circuit

    This basically wraps statements into a function call. It only wraps statements, so (and 1 1) will still be compiled to just 1 and 1.

    Closes #233 and #766.

    opened by refi64 39
  • Remove redundant keywords

    Remove redundant keywords

    There are redundant keywords in the current implementation:

    • setf/setv/def
    • lambda/fn
    • for/foreach (?)
    • throw/raise
    • catch/except
    • do/prgn

    I believe we should avoid any ambiguity by removing duplication and settling on one of each. It's one of these things that we should worry about now, while we can afford to break the language.

    complaint / disgust doc me bro 
    opened by joehakimrahme 38
  • `~@ #* …` produces a weird result instead of an error

    `~@ #* …` produces a weird result instead of an error

    (defmacro condp-1 [op obj #*body]
      `(cond
         ~@(lfor [val res] (by2s body)
             `((~op ~obj ~val) ~res) )))
    
    (defmacro condp-2 [op obj #*body]
      `(cond
         ~@(unpack-iterable (lfor [val res] (by2s body)
                  `((~op ~obj ~val) ~res) ))))
    
    (.macroexpand-1 hy (.read hy "(condp-1 < 10 100 12 1000 123 10000 0 120000 1)"))
    (.macroexpand-1 hy (.read hy "(condp-2 < 10 100 12 1000 123 10000 0 120000 1)"))
    

    The macroexpansion I want to get is

    (cond (< 10 100) 12 (< 10 1000) 123 (< 10 10000) 0 (< 10 120000) 1)
    

    instead I'm getting, from condp-1 and condp-2 respectively:

    ;; condp-1
    '(cond ((< 10 100) 12) ((< 10 1000) 123) ((< 10 10000) 0) ((< 10 120000) 1))
    
    ;; condp-2
    '(cond (< 10 100) 12)
    

    The first has inner expressions nested a level too deep. The second is missing elements.

    Am I missing something about how unpack-iterable works? From testing its behavior, this is the only scenario where I found it to not return all members

    complaint / disgust 
    opened by z80dev 3
  • Trouble with `defreader` inside other forms

    Trouble with `defreader` inside other forms

    Consider

    (do
      (defreader r 5)
      (print #r))
    

    The result is LexException: reader macro '#r' is not defined. Perhaps defreader shouldn't be legal here in the first place, but what's checked in defreader is whether we're in the global scope, which we clearly are. What's more, that check doesn't seem to work, because the same error message as above is produced when you use a defn instead of do.

    bug 
    opened by Kodiologist 0
  • Code read with `hy.read` can't define a reader macro

    Code read with `hy.read` can't define a reader macro

    => (hy.eval (hy.read "(defreader r 5)"))
    Traceback (most recent call last):
      File "stdin-27f203d5d830092f5be52fd45c79e54c119e57b6", line 1, in <module>
        (hy.eval (hy.read "(defreader r 5)"))
    hy.errors.HyEvalError: module 'hy' has no attribute 'hyx_XampersandXreader'
    

    #2290 creates a more detailed traceback, but doesn't fix this.

    bug 
    opened by Kodiologist 4
  • ast.parse expects not None filename

    ast.parse expects not None filename

    => (import hy.compiler [asty])
    => (asty.parse '1 "1 + 1" "<string>" "eval")
    <ast.Expression object at 0x7f124604c700>
    
    => (asty.parse '1 "1 + 1" None "eval")
    Traceback (most recent call last):
      File "stdin-dcc5fc697bf44164cb8034c9a58f5f1c670b51a6", line 1, in <module>
        (asty.parse '1 "1 + 1" None "eval")
      File "/usr/lib64/python3.10/ast.py", line 50, in parse
        return compile(source, filename, mode, flags,
    TypeError: expected str, bytes or os.PathLike object, not NoneType
    

    This hasn't been an issue before since, the lex methods defaulted to <string>, but we have a couple places where filename defaults to None that have worked okay by chance. We should probably move those to default to <string> to avoid unexpected future bugs.

    opened by allison-casey 0
Releases(0.25.0)
  • 0.25.0(Nov 8, 2022)

    Breaking Changes

    • dfor no longer requires brackets around its final arguments, so (dfor x (range 5) [x (* 2 x)]) is now (dfor x (range 5) x (* 2 x)).
    • except* (PEP 654) is now recognized in try, and a placeholder macro for except* has been added.

    Bug Fixes

    • __file__ should now be set the same way as in Python.
    • \N{…} escape sequences are now recognized in f-strings.
    • Fixed a bug with python -O where assertions were still partly evaluated.
    • Fixed hy.repr of slice objects with non-integer arguments.

    New Features

    • Python 3.11 is now supported.

    Misc. Improvements

    • hyc now requires a command-line argument.
    • hyc prints each path it writes bytecode to, and its messages now go to standard error instead of standard output.
    Source code(tar.gz)
    Source code(zip)
    hy-0.25.0.tar.gz(94.85 KB)
  • 0.24.0(Jun 23, 2022)

    This release is a direct successor to 1.0a4. We've returned to 0.* version numbers to work around the inflexibility of PyPI and pip regarding the default version to install. (We skipped some version numbers because this release is several major releases since 0.20.0.) Sorry for the mess.

    Removals

    • Tag macros have been removed. Use reader macros instead, rewriting (defmacro "#foo" [arg] …) as (defreader foo (setv arg (.parse-one-form &reader)) …).
    • with-decorator and #@ have been removed in favor of decorator lists (see below).
    • Fraction literals have been removed. Use fractions.Fraction instead.
    • Unrecognized backslash escapes in string and byte literals are no longer allowed. (They've been deprecated in Python since 3.6.)
    • A bare # is no longer a legal symbol.
    • u is no longer allowed as a string prefix. (It had no effect, anyway.)
    • hy.read-str has been removed. Use hy.read, which now accepts strings, instead.

    Other Breaking Changes

    • Tuples are now indicated with #( … ), as in #(1 2 3), instead of (, … ), as in (, 1 2 3).

    • Tuples have their own model type, hy.models.Tuple, instead of being represented as Expression\s.

    • if now requires all three arguments. For the two-argument case (i.e., with no else-clause), when is a drop-in replacement.

    • cond has a new unbracketed syntax:

       (cond [a b] [x y z])     ; Old
       (cond  a b  x (do y z))  ; New
      
    • defmacro once again requires the macro name as a symbol, not a string literal.

    • Annotations are now indicated by #^ instead of ^.

    • annotate (but not #^) now takes the target first and the type second, as in (annotate x int).

    • The way f-strings are parsed has changed, such that unescaped double quotes are now allowed inside replacement fields.

    • Non-ASCII whitespace is no longer ignored during tokenization like ASCII whitespace.

    • The mangling rules have been refined to account for Python's treatment of distinct names as referring to the same variable if they're NFKC-equivalent. Very little real code should be affected.

    • hy.cmdline.run_repl has been replaced with hy.cmdline.HyREPL.run.

    Bug Fixes

    • Fixed a crash when using keyword objects in match.
    • Fixed a scoping bug in comprehensions in let bodies.
    • Literal newlines (of all three styles) are now recognized properly in string and bytes literals.
    • defmacro no longer allows further arguments after #* args.
    • != with model objects is now consistent with =.
    • Tracebacks from code parsed with hy.read now show source positions.
    • Elements of builtins such as help are no longer overridden until the REPL actually starts.
    • Readline is now imported only when necessary, to avoid triggering a CPython bug regarding the standard module curses (cpython#46927).
    • Module names supplied to hy -m are now mangled.
    • Hy now precompiles its own Hy code during installation.

    New Features

    • Added user-defined reader macros, defined with defreader.

    • defn and defclass now allow a decorator list as their first argument.

    • ... is now understood to refer to Ellipsis, as in Python.

    • Python reserved words are allowed once more as parameter names and keyword arguments. Hy includes a workaround for a CPython bug that prevents the generation of legal Python code for these cases (cpython#90678).

    • New macro export.

      • Or you can set the variable _hy_export_macros to control what macros are collected by (require module *).
    • New macro delmacro.

    • New function hy.read_many.

    • New function hy.model_patterns.parse_if.

    • New function hy.model_patterns.in_tuple.

    • Added a command-line option -u (or --unbuffered) per CPython.

    • Tab-completion in the REPL now attempts to unmangle names.

    Source code(tar.gz)
    Source code(zip)
    hy-0.24.0.tar.gz(93.59 KB)
  • 1.0a4(Jan 9, 2022)

    Removals

    • Python 3.6 is no longer supported.

    Other Breaking Changes

    • import and require no longer need outer brackets. (import [foo [bar]]) is now (import foo [bar]) and (import [foo :as baz]) is now (import foo :as baz). To import all names from a module, use (import foo *).

    • Lots of objects (listed below) have been spun off to a new package called Hyrule, from which you can import or require them. Thus Hy now brings only the hy module and a limited set of core macros into scope automatically.

      • Functions: butlast, coll?, constantly, dec, destructure, distinct, drop-last, end-sequence, flatten, inc, macroexpand-all, parse-args, pformat, postwalk, pp, pprint, prewalk, readable?, recursive?, rest, saferepr, walk
      • Classes: PrettyPrinter, Sequence
      • Macros: #%, #:, ->, ->>, ap-dotimes, ap-each, ap-each-while, ap-filter, ap-first, ap-if, ap-last, ap-map, ap-map-when, ap-reduce, ap-reject, as->, assoc, cfor, comment, defmacro!, defmacro/g!, defmain, defn+, defn/a+, defseq, dict=:, do-n, doto, fn+, fn/a+, ifp, let+, lif, list-n, loop, ncut, of, profile/calls, profile/cpu, seq, setv+, smacrolet, unless, with-gensyms
    • Functions that provide first-class Python operators, such as + in constructs like (reduce + xs), are no longer brought into scope automatically. Say (import hy.pyops *) to get them.

    • Hy scoping rules more closely follow Python scoping in certain edge cases.

    • let is now a core macro with somewhat different semantics. In particular, definition-like core macros (defn, defclass, import) now introduce new names that shadow corresponding let-bound names and persist outside the body of the let.

    • The constructors of String and FString now check that the input would be syntactically legal as a literal.

    • hy.extra.reserved has been renamed to hy.reserved.

    Bug Fixes

    • In comprehension forms other than for, assignments (other than :setv and loop clauses) are now always visible in the surrounding scope.
    • match now only evaluates the subject once.
    • let will no longer re-evaluate the default arguments of a function it's used in.
    • hy.repr now properly formats bracket strings.
    • The repr and str of string models now include brackets if necessary.
    • When standard output can't accommodate Unicode, hy2py now crashes instead of emitting incorrect Python code.
    • Fixed a bug with self-requiring files on Windows.
    • Improved error messages for illegal uses of finally and else.

    New Features

    • hy.repr now supports several more standard types.
    • The attribute access macro . now allows method calls. For example, (. x (f a)) is equivalent to (x.f a).
    • hy.as-model checks for self-references in its argument.
    • New function hy.model_patterns.keepsym.
    Source code(tar.gz)
    Source code(zip)
    hy-1.0a4-py3-none-any.whl(73.94 KB)
    hy-1.0a4.tar.gz(86.50 KB)
  • 1.0a3(Jul 9, 2021)

  • 1.0a2(Jul 7, 2021)

    Removals

    • All reimplementations of functions in the package Toolz have been removed. Import these from Toolz (or CyToolz) instead. Beware that the Toolz functions are not all drop-in replacements for the old Hy functions; e.g., partition has a different order of parameters.

      • complement, compose (formerly comp in Hy), drop, first, identity, interleave, interpose, iterate, juxt, last, merge-with, nth, partition, second, take-nth, take
    • All aliases of objects in Python's standard library have been removed. Import these objects explicitly instead.

      • From itertools: accumulate, chain, combinations-with-replacement (formerly multicombinations in Hy), combinations, compress, count, cycle, dropwhile (formerly drop-while), filterfalse (formerly remove), groupby (formerly group-by), islice, permutations, product, repeat, starmap (formerly *map), takewhile (formerly take-while), tee, zip-longest
      • From functools: reduce
      • From fractions: Fraction (formerly fraction)
    • The following core predicate functions have been removed. Use isinstance etc. instead.

      • empty?, even?, every?, float?, integer-char?, integer?, iterable?, iterator?, keyword?, list?, neg?, none?, numeric?, odd?, pos?, some, string?, symbol?, tuple?, zero?
    • Several other core functions and macros have been removed:

      • keyword: Use (hy.models.Keyword (hy.unmangle …)) instead.
      • repeatedly: Use toolz.iterate instead.
      • if-not: Use (if (not …) …) instead.
      • lif-not: Use (lif (not …) …) instead.
      • macro-error: Use raise instead.
      • calling-module: Now internal to Hy.
      • calling-module-name: Now internal to Hy.

    Other Breaking Changes

    • if no longer allows more than three arguments. Use cond instead.

    • cut with exactly two arguments (the object to be cut and the index) now works like Python slicing syntax and the slice function: (cut x n) gets the first n elements instead of everything after the first n.

    • In defn, the return-value annotation, if any, is now placed before the function name instead of after.

    • Python reserved words are no longer allowed as parameter names, nor as keywords in keyword function calls.

    • Hy model objects are no longer equal to ordinary Python values. For example, (!= 1 '1). You can promote values to models with hy.as-model before making such a check.

    • The following functions are now called as attributes of the hy module:

      • hy.disassemble, hy.gensym, hy.macroexpand, hy.macroexpand-1, hy.repr (formerly hy.contrib.hy-repr.hy-repr), hy.repr-register (formerly hy.contrib.hy-repr.hy-repr-register)
    • cmp has been renamed to chainc.

    • defclass no longer automatically adds None to the end of __init__ method definitions.

    • All special forms have been replaced with macros. This won't affect most preexisting code, but it does mean that user-defined macros can now shadow names like setv.

    • hy.repr no longer uses the registered method of a supertype.

    • The constructors of Symbol and Keyword now check that the input would be syntactically legal.

    • Attempting to call a core macro not implemented on the current version of Python is now an error.

    • hy.extra.reserved.special has been replaced with hy.extra.reserved.macros.

    New Features

    • hy-repr is now the default REPL output function.
    • The command python -m hy now works the same as hy.
    • New function hy.as-model.
    • New macro match (Python 3.10 only).
    • annotate is now a user-visible macro.

    Bug Fixes

    • Fixed issues with newer prereleases of Python 3.10.
    • The REPL now properly displays SyntaxErrors.
    • Fixed a bug in pprint in which width was ignored.
    • Corrected repr and hy.repr for f-strings.
    • --spy and --repl-output-fn can now overwrite HYSTARTUP values.
    Source code(tar.gz)
    Source code(zip)
    hy-1.0a2-py2.py3-none-any.whl(101.71 KB)
    hy-1.0a2.tar.gz(109.37 KB)
  • 1.0a1(Apr 17, 2021)

    Removals

    • The core function name has been removed. Use unmangle or the name attribute of keyword objects instead.
    • deftag has been removed. Instead of (deftag foo …), say (defmacro "#foo" …).
    • #doc has been removed. Instead of #doc @, say (doc "#@").
    • __tags__ has been removed. Tag macros are now tracked in __macros__.

    Other Breaking Changes

    • Lambda lists (function parameter lists) have been simplified. &optional is gone, &args is #*, &kwargs is #**, and &kwonly is *. Thus, [a &optional b [c 3] &rest args &kwargs kwargs] is now [a [b None] [c 3] #* args #** kwargs].
    • Hy models have been renamed to remove "Hy", and are no longer automatically brought into scope. Thus, HyList is now hy.models.List.
    • eval is no longer automatically brought into scope. Call it as hy.eval (or import it explicitly).
    • Calling a keyword object now does a string lookup, instead of a keyword-object lookup. Thus, (:key obj) is equivalent to (get obj (mangle (. :key name))).
    • To require a tag macro foo, instead of (require [module [foo]]), you must now say (require [module ["#foo"]]).
    • Mangling no longer converts leading hyphens to underscores, and unmangling no longer converts leading underscores to hyphens.
    • F-strings now have their own model type, and store their code parts as models instead of strings.

    New Features

    • Python 3.10 is now supported.
    • Lambda lists now support positional-only arguments.
    • F-strings now support = syntax per Python.
    • with now supports unnamed context managers.
    • defmacro and require can now take macro names as string literals.
    • New standard macros do-n, list-n, and cfor.
    • The location of the REPL history file can now be set with the environment variable HY_HISTORY.
    • REPL initialization scripts are now supported with the envrionment variable HYSTARTUP.
    • The module hy.extra.reserved has a new function special.
    • New module hy.contrib.destructure for Clojure-style destructuring.
    • New module hy.contrib.slicing for multi-index sequence slicing.

    Bug Fixes

    • Fixed the identifier J being incorrectly parsed as a complex number.
    • Attempts to assign to constants are now more reliably detected.
    • Fixed a bug where AST nodes from macro expansion did not properly receive source locations.
    • Fixed doc sometimes failing to find core macros.
    • doc now works with names that need mangling.
    • Fixed bugs with require of names that need mangling.
    • Fixed a compiler crash from trying to use .. as an operator.
    • Fixed namespace pollution caused by automatic imports of Hy builtins and macros.
    • require now works with relative imports and can name modules as members, as in (require [hy.contrib [walk]]).
    • Fixed error handling for illegal macro names.
    • Fixed hyc and hy2py not finding relative imports.
    • Fixed hy.contrib.walk.smacrolet requiring a module name.

    Misc. Improvements

    • The library astor is no longer required on Pythons ≥ 3.9.
    Source code(tar.gz)
    Source code(zip)
    hy-1.0a1-py2.py3-none-any.whl(107.16 KB)
    hy-1.0a1.tar.gz(113.01 KB)
  • 0.20.0(Jan 25, 2021)

  • 0.19.0(Jul 16, 2020)

    Breaking Changes

    • parse-args is no longer implemented with eval; so e.g. you should now say :type int instead of :type 'int.

    New Features

    • Python 3.9 is now supported.

    Bug Fixes

    • Improved support for nesting anaphoric macros by only applying symbol replacement where absolutely necessary.
    • Quoted f-strings are no longer evaluated prematurely.
    • Fixed a regression in the production of error messages for empty expressions.
    • Fixed a scoping bug for code executed with hy -c.
    • Fixed a bug in the compilation of multiple require s.
    • Fixed various bugs in command-line option parsing.
    Source code(tar.gz)
    Source code(zip)
    hy-0.19.0-py2.py3-none-any.whl(77.82 KB)
    hy-0.19.0.tar.gz(84.52 KB)
  • 0.18.0(Feb 2, 2020)

    Removals

    • Python 2 is no longer supported.
    • Support for attribute lists in defclass has been removed. Use setv and defn instead.
    • Literal keywords are no longer parsed differently in calls to functions with certain names.
    • hy.contrib.multi has been removed. Use cond or the PyPI package multipledispatch instead.

    Other Breaking Changes

    • 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.

    New Features

    • Added special forms py to pys that allow Hy programs to include inline Python code.
    • Added a special form cmp for chained comparisons.
    • All augmented assignment operators (except %= and ^=) now allow more than two arguments.
    • Added support for function annotations (PEP 3107) and variable annotations (PEP 526).
    • Added a function parse-args as a wrapper for Python's argparse.

    Bug Fixes

    • Statements in the second argument of assert are now executed.
    • Fixed a bug that caused the condition of a while to be compiled twice.
    • in and not-in now allow more than two arguments, as in Python.
    • hy2py can now handle format strings.
    • Fixed crashes from inaccessible history files.
    • Removed an accidental import from the internal Python module test.
    • Fixed a swarm of bugs in hy.extra.anaphoric.

    Misc. Improvements

    • Replaced the dependency clint with colorama.
    Source code(tar.gz)
    Source code(zip)
    hy-0.18.0-py2.py3-none-any.whl(76.91 KB)
    hy-0.18.0.tar.gz(81.83 KB)
  • 0.17.0(May 20, 2019)

    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.

    Removals

    • Python 3.4 is no longer supported.

    New Features

    • Python 3.8 is now supported.
    • Format strings with embedded Hy code (e.g., f"The sum is {(+ x y)}") are now supported, even on Pythons earlier than 3.6.
    • Added a special form setx to create Python 3.8 assignment expressions.
    • Added new core functions list? and tuple.
    • Gensyms now have a simpler format that's more concise when mangled (e.g., _hyx_XsemicolonXfooXvertical_lineX1235 is now _hyx_fooXUffffX1).

    Bug Fixes

    • Fixed a crash caused by errors creating temporary files during bytecode compilation.
    Source code(tar.gz)
    Source code(zip)
    hy-0.17.0-py2.py3-none-any.whl(82.37 KB)
    hy-0.17.0.tar.gz(84.07 KB)
  • 0.16.0(Feb 12, 2019)

    Removals

    • Empty expressions (()) are no longer legal at the top level.

    New Features

    • eval / hy_eval and hy_compile now accept an optional compiler argument that enables the use of an existing HyASTCompiler instance.
    • Keyword objects (not just literal keywords) can be called, as shorthand for (get obj :key), and they accept a default value as a second argument.
    • Minimal macro expansion namespacing has been implemented. As a result, external macros no longer have to require their own macro dependencies.
    • Macros and tags now reside in module-level __macros__ and __tags__ attributes.

    Bug Fixes

    • Cleaned up syntax and compiler errors.
    • You can now call defmain with an empty lambda list.
    • require now compiles to Python AST.
    • Fixed circular require\s.
    • Fixed module reloading.
    • Fixed circular imports.
    • Fixed errors from from __future__ import ... statements and missing Hy module docstrings caused by automatic importing of Hy builtins.
    • Fixed __main__ file execution.
    • Fixed bugs in the handling of unpacking forms in method calls and attribute access.
    • Fixed crashes on Windows when calling hy-repr on date and time objects.
    • Fixed a crash in mangle for some pathological inputs.
    • Fixed incorrect mangling of some characters at low code points.
    • Fixed a crash on certain versions of Python 2 due to changes in the standard module tokenize.
    Source code(tar.gz)
    Source code(zip)
    hy-0.16.0-py2.py3-none-any.whl(80.66 KB)
    hy-0.16.0.tar.gz(81.99 KB)
  • 0.15.0(Jul 21, 2018)

    Removals

    • Dotted lists, 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.
    • Lambda lists can no longer unpack tuples.
    • 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.

    Other Breaking Changes

    • 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.

      • The REPL history variable _ 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.

    New Features

    • Python 3.7 is now supported.
    • 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.
    • Added mangle and unmangle as core functions.
    • Added more REPL history variables: *2 and *3.
    • Added a REPL variable holding the last exception: *e.
    • Added a command-line option -E per CPython.
    • Added a new module hy.model_patterns.

    Bug Fixes

    • hy2py should now output legal Python code equivalent to the input Hy code in all cases.
    • Fixed (return) so it can exit a Python 2 generator.
    • Fixed a case where -> and ->> duplicated an argument.
    • Fixed bugs that caused defclass to drop statements or crash.
    • Fixed a REPL crash caused by illegal backslash escapes.
    • NaN can no longer create an infinite loop during macro-expansion.
    • Fixed a bug that caused try to drop expressions.
    • The compiler now properly recognizes unquote-splice.
    • Trying to import a dotted name is now a syntax error, as in Python.
    • defmacro! now allows optional arguments.
    • Fixed handling of variables that are bound multiple times in a single let.

    Misc. Improvements

    • hy-repr uses registered functions instead of methods.
    • hy-repr supports more standard types.
    Source code(tar.gz)
    Source code(zip)
    hy-0.15.0-py2.py3-none-any.whl(67.10 KB)
    hy-0.15.0.tar.gz(70.57 KB)
  • 0.14.0(Feb 14, 2018)

    Removals

    • Python 3.3 is no longer supported
    • def is gone; use setv instead
    • apply is gone; use the new #* and #** syntax instead
    • yield-from is no longer supported under Python 2
    • Periods are no longer allowed in keywords
    • Numeric literals can no longer begin with a comma or underscore
    • Literal Inf\s and NaN\s must now be capitalized like that

    Other Breaking Changes

    • Single-character "sharp macros" are now "tag macros", which can have longer names
    • xi from hy.extra.anaphoric is now a tag macro #%
    • eval is now a function instead of a special form

    New Features

    • The compiler now automatically promotes values to Hy model objects as necessary, so you can write (eval `(+ 1 ~n)) instead of (eval `(+ 1 ~(HyInteger n)))
    • return has been implemented as a special form
    • Added a form of string literal called "bracket strings" delimited by #[FOO[ and ]FOO], where FOO is customizable
    • Added support for PEP 492 (async and await) with fn/a, defn/a, with/a, and for/a
    • Added Python-style unpacking operators #* and #** (e.g., (f #* args #** kwargs))
    • Added a macro comment
    • Added EDN #_ syntax to discard the next term
    • while loops may now contain an else clause, like for loops
    • #% works on any expression and has a new &kwargs parameter %**
    • Added a macro doc and a tag macro #doc
    • get is available as a function
    • ~@ (unquote-splice) form now accepts any false value as empty

    Bug Fixes

    • Relative imports (PEP 328) are now allowed
    • Numeric literals are no longer parsed as symbols when followed by a dot and a symbol
    • Hy now respects the environment variable PYTHONDONTWRITEBYTECODE
    • String literals should no longer be interpreted as special forms or macros
    • Tag macros (née sharp macros) whose names begin with ! are no longer mistaken for shebang lines
    • Fixed a bug where REPL history wasn't saved if you quit the REPL with (quit) or (exit)
    • exec now works under Python 2
    • No TypeError from multi-arity defn returning values evaluating to None
    • try forms are now possible in defmacro and deftag
    • Multiple expressions are now allowed in try
    • Fixed a crash when macroexpand\ing a macro with a named import
    • Fixed a crash when with suppresses an exception. with now returns None in this case.
    • Fixed a crash when --repl-output-fn raises an exception
    • Fixed a crash when HyTypeError was raised with objects that had no source position
    • assoc now evaluates its arguments only once each
    • Multiple expressions are now allowed in the else clause of a for loop
    • else clauses in for and while are recognized more reliably
    • Statements in the condition of a while loop are repeated properly
    • Argument destructuring no longer interferes with function docstrings
    • Nullary yield-from is now a syntax error
    • break and continue now raise an error when given arguments instead of silently ignoring them

    Misc. Improvements

    • read, read_str, and eval are exposed and documented as top-level functions in the hy module
    • An experimental let macro has been added to hy.contrib.walk
    Source code(tar.gz)
    Source code(zip)
    hy-0.14.0-py2.py3-none-any.whl(67.08 KB)
    hy-0.14.0.tar.gz(70.20 KB)
  • 0.13.1(Nov 3, 2017)

  • 0.13.0(Jun 20, 2017)

    Language Changes

    • Pythons 2.6, 3.0, 3.1, and 3.2 are no longer supported
    • 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 did
    • defreader 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 excepts, 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 Python
    • Importing or executing a Hy file automatically byte-compiles it, or loads a byte-compiled version if it exists and is up to date. This brings big speed boosts, even for one-liners, because Hy no longer needs to recompile its standard library for every startup.
    • Added bytestring literals, which create bytes objects under Python 3 and str objects under Python 2
    • Commas and underscores are allowed in numeric literals
    • Many more operators (e.g., **, //, not, in) can be used as first-class functions
    • The semantics of binary operators when applied to fewer or more than two arguments have been made more logical
    • (** a b c d) is now equivalent to (** a (** b (** c d))), not (** (** (** a b) c) d)
    • setv always returns None
    • When a 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 it
    • hy.core.reserved is now hy.extra.reserved
    • cond now supports single argument branches

    Bug Fixes

    • All shadowed operators have the same arities as real operators
    • Shadowed comparison operators now use and instead of & for chained comparisons
    • partition no longer prematurely exhausts input iterators
    • read and read-str no longer raise an error when the input parses to a false value (e.g., the empty string)
    • A yield inside of a with statement will properly suppress implicit returns
    • setv no longer unnecessarily tries to get attributes
    • loop no longer replaces string literals equal to "recur"
    • The REPL now prints the correct value of do and try forms
    • Fixed a crash when tokenizing a single quote followed by whitespace

    Misc. Improvements

    • New contrib module hy-repr
    • Added a command-line option --repl-output-fn
    Source code(tar.gz)
    Source code(zip)
    hy-0.13.0-py2.py3-none-any.whl(90.39 KB)
    hy-0.13.0.tar.gz(84.43 KB)
  • 0.12.0(Jan 17, 2017)

    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.

    Language Changes

    • New syntax for let, with and defclass
    • defmacro will raise an error on &kwonly, &kwargs and &key arguments
    • Keyword argument labels to functions are required to be strings
    • slice replaced with cut to stop overloading the python built-in
    • removed reduntant throw, catch, progn, defun, lisp-if, lisp-if-not, filterfalse, true, false and nil
    • global now takes multiple arguments
    • Nonlocal keyword (Python 3 only)
    • Set literals (#{1 2 3})
    • Keyword-only arguments (Python 3 only)
    • Setv can assign multiple variables at once
    • Empty form allowed for setv, del and cond
    • One-argument division, rationals and comparison operators (=, !=, <, >, <=, >=)
    • partition form for chunking collection to n-sized tuples
    • defn-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 body
    • Hex and octal support for integer literals
    • apply now mangles strings and keywords according to Hy mangling rules
    • Variadic if
    • defreader can use strings as macro names
    • as-> macro added
    • require syntax changed and now supports same features as import
    • defmulti changed to work with dispatching function
    • old defmulti renamed to defn
    • Lazy sequences added to contrib
    • defmacro! added for once-only evaluation for parameters
    • comp, constantly, complement and juxt added
    • keyword arguments allowed in method calls before the object

    Bug Fixes

    • Better error when for doesn't have body
    • Better error detection with list comprehensions in Python 2.7
    • Setting value to callable will raise an error
    • defclass can have properties / methods with built-in names
    • Better error messages on invalid macro arguments
    • Better error messages with hy2py and hyc
    • Cmdline error to string conversion.
    • In python 3.3+, generator functions always return a value
    • &rest can be used after &optional

    Misc. Improvements

    • Version information includes SHA1 of current commit
    • Improved Python 3.5 support
    • Allow specification of global table and module name for (eval ...)
    • General documentation improvements
    • contrib.walk: Coerce non-list iterables into list form
    • Flow macros (case and switch)
    • ap-pipe and ap-compose macros
    • #@ reader macro for with-decorator
    • Type check eval parameters
    • and and or short-circuit
    • and and or accept zero or more arguments
    • read-str for tokenizing a line
    • botsbuildbots moved to contrib
    • Trailing bangs on symbols are mangled
    • xi forms (anonymous function literals)
    • if form optimizations in some cases
    • xor operator
    • Overhauled macros to allow macros to ref the compiler
    • ap-if requires then branch
    • Parameters for numeric operations (inc, dec, odd?, even?, etc.) aren't type checked
    • import_file_to_globals added for use in emacs inferior lisp mode
    • hy.core.reserved added for querying reserved words
    • hy2py can use standard input instead of a file
    • alias, curry, flow and meth removed from contrib
    • contrib.anaphoric moved to hy.extra
    Source code(tar.gz)
    Source code(zip)
Compiler Final Project - Lisp Interpreter

Compiler Final Project - Lisp Interpreter

null 2 Jan 23, 2022
A topology optimization framework written in Taichi programming language, which is embedded in Python.

Taichi TopOpt (Under Active Development) Intro A topology optimization framework written in Taichi programming language, which is embedded in Python.

Li Zhehao 41 Nov 17, 2022
CaskDB is a disk-based, embedded, persistent, key-value store based on the Riak's bitcask paper, written in Python.

CaskDB - Disk based Log Structured Hash Table Store CaskDB is a disk-based, embedded, persistent, key-value store based on the Riak's bitcask paper, w

null 886 Dec 27, 2022
A quick experiment to demonstrate Metamath formula parsing, where the grammar is embedded in a few additional 'syntax axioms'.

Warning: Hacked-up code ahead. (But it seems to work...) What it does This demonstrates an idea which I posted about several times on the Metamath mai

Marnix Klooster 1 Oct 21, 2021
An Embedded Linux Project Build and Compile Tool -- An Bitbake UI Extension

Dianshao - An Embedded Linux Project Build and Compile Tool

null 0 Mar 27, 2022
Todos os exercícios do Curso de Python, do canal Curso em Vídeo, resolvidos em Python, Javascript, Java, C++, C# e mais...

Exercícios - CeV Oferecido por Linguagens utilizadas atualmente O que vai encontrar aqui? ?? Esse repositório é dedicado a armazenar todos os enunciad

Coding in Community 43 Nov 10, 2022
PyDy, short for Python Dynamics, is a tool kit written in the Python

PyDy, short for Python Dynamics, is a tool kit written in the Python programming language that utilizes an array of scientific programs to enable the study of multibody dynamics. The goal is to have a modular framework and eventually a physics abstraction layer which utilizes a variety of backends that can provide the user with their desired workflow

PyDy 307 Jan 1, 2023
A Python script made for the Python Discord Pixels event.

Python Discord Pixels A Python script made for the Python Discord Pixels event. Usage Create an image.png RGBA image with your pattern. Transparent pi

Stanisław Jelnicki 4 Mar 23, 2022
this is a basic python project that I made using python

this is a basic python project that I made using python. This project is only for practice because my python skills are still newbie.

Elvira Firmansyah 2 Dec 14, 2022
Analisador de strings feito em Python // String parser made in Python

Este é um analisador feito em Python, neste programa, estou estudando funções e a sua junção com "if's" e dados colocados pelo usuário. Neste código,

Dev Nasser 1 Nov 3, 2021
Python with braces. Because Python is awesome, but whitespace is awful.

Bython Python with braces. Because Python is awesome, but whitespace is awful. Bython is a Python preprosessor which translates curly brackets into in

null 1 Nov 4, 2021
PSP (Python Starter Package) is meant for those who want to start coding in python but are new to the coding scene.

Python Starter Package PSP (Python Starter Package) is meant for those who want to start coding in python, but are new to the coding scene. We include

Giter/ 1 Nov 20, 2021
Py-Parser est un parser de code python en python encore en plien dévlopement.

PY - PARSER Py-Parser est un parser de code python en python encore en plien dévlopement. Une fois achevé, il servira a de nombreux projets comme glad

pf4 3 Feb 21, 2022
A community based economy bot with python works only with python 3.7.8 as web3 requires cytoolz

A community based economy bot with python works only with python 3.7.8 as web3 requires cytoolz has some issues building with python 3.10

null 4 Jan 1, 2022
A python script based on OpenCV-Python, you can automatically hang up the Destiny 2 Throne to get the Dawning Essence.

A python script based on OpenCV-Python, you can automatically hang up the Destiny 2 Throne to get the Dawning Essence.

null 1 Dec 19, 2021
Run python scripts and pass data between multiple python and node processes using this npm module

Run python scripts and pass data between multiple python and node processes using this npm module. process-communication has a event based architecture for interacting with python data and errors inside nodejs.

Tyler Laceby 2 Aug 6, 2021
inverted pendulum fuzzy control python code (python 2.7.18)

inverted-pendulum-fuzzy-control- inverted pendulum fuzzy control python code (python 2.7.18) We have 3 general functions for 3 main steps: fuzzificati

arian mottaghi 4 May 23, 2022
Izy - Python functions and classes that make python even easier than it is

izy Python functions and classes that make it even easier! You will wonder why t

null 5 Jul 4, 2022