hylang / hydiomatic Goto Github PK
View Code? Open in Web Editor NEWThe Hy Transformer
The Hy Transformer
I was curious what Hydiomatic would say about my little timer (thanks for the Star, by the way), but it throws a TypeError and dies:
(hydiomatic)zmd@ExpectedReturn:~/Code/Examination/hydiomatic$ bin/hydiomatic.hy ~/Code/HyTimer/timer.hy
Traceback (most recent call last):
File "/home/zmd/Code/Examination/hydiomatic/bin/hy", line 9, in <module>
load_entry_point('hy==0.9.12', 'console_scripts', 'hy')()
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/cmdline.py", line 295, in hy_main
sys.exit(cmdline_handler("hy", sys.argv))
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/cmdline.py", line 283, in cmdline_handler
return run_file(options.args[0])
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/cmdline.py", line 190, in run_file
import_file_to_module("__main__", filename)
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/importer.py", line 74, in import_file_to_module
eval(ast_compile(_ast, fpath, "exec"), mod.__dict__)
File "bin/hydiomatic.hy", line 349, in <module>
File "bin/hydiomatic.hy", line 24, in process_file
(apply printer [(transform (import-file-to-hst fn) rules)]
File "/home/zmd/Code/Examination/hydiomatic/hydiomatic/core.hy", line 38, in simplify
(setv new-expr (prewalk (fn [x] (simplify-step x rules)) expr))
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 50, in prewalk
(walk (partial prewalk f) identity (f form)))
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 39, in walk
((type form) (outer (HyExpression (map inner form))))]
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 50, in prewalk
(walk (partial prewalk f) identity (f form)))
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 32, in walk
(outer (HyExpression (map inner form)))]
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 50, in prewalk
(walk (partial prewalk f) identity (f form)))
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 39, in walk
((type form) (outer (HyExpression (map inner form))))]
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 50, in prewalk
(walk (partial prewalk f) identity (f form)))
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 39, in walk
((type form) (outer (HyExpression (map inner form))))]
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 50, in prewalk
(walk (partial prewalk f) identity (f form)))
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 32, in walk
(outer (HyExpression (map inner form)))]
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 50, in prewalk
(walk (partial prewalk f) identity (f form)))
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 32, in walk
(outer (HyExpression (map inner form)))]
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/contrib/walk.hy", line 50, in prewalk
(walk (partial prewalk f) identity (f form)))
File "/home/zmd/Code/Examination/hydiomatic/hydiomatic/core.hy", line 38, in _hy_anon_fn_6
(setv new-expr (prewalk (fn [x] (simplify-step x rules)) expr))
File "/home/zmd/Code/Examination/hydiomatic/hydiomatic/core.hy", line 33, in simplify_step
(setv new-expr (simplify-step-by-rule rule new-expr)))
File "/home/zmd/Code/Examination/hydiomatic/hydiomatic/core.hy", line 23, in simplify_step_by_rule
(let [[alts (run* [q] (rule expr q))]]
File "/home/zmd/Code/Examination/hydiomatic/hydiomatic/core.hy", line 23, in _hy_anon_fn_3
(let [[alts (run* [q] (rule expr q))]]
File "/home/zmd/Code/Examination/hydiomatic/hydiomatic/core.hy", line 23, in _hy_anon_fn_2
(let [[alts (run* [q] (rule expr q))]]
File "/home/zmd/Code/Examination/hydiomatic/hydiomatic/core.hy", line 23, in :res_1280
(let [[alts (run* [q] (rule expr q))]]
File "/home/zmd/Code/Examination/hydiomatic/src/adderall/adderall/dsl.hy", line 124, in _hy_anon_fn_31
(for [opt-s1 (g1 s)]
File "/home/zmd/Code/Examination/hydiomatic/src/adderall/adderall/dsl.hy", line 126, in _hy_anon_fn_31
(yield-from (g2 opt-s1)))))) goals)
File "/home/zmd/Code/Examination/hydiomatic/src/adderall/adderall/dsl.hy", line 126, in _hy_anon_fn_31
(yield-from (g2 opt-s1)))))) goals)
File "/home/zmd/Code/Examination/hydiomatic/src/adderall/adderall/dsl.hy", line 126, in _hy_anon_fn_31
(yield-from (g2 opt-s1)))))) goals)
File "/home/zmd/Code/Examination/hydiomatic/hydiomatic/rulesets/syntaxo.hy", line 65, in _hy_anon_fn_16
(project [?params ?m ?o]
File "/home/zmd/Code/Examination/hydiomatic/hydiomatic/rulesets/syntaxo.hy", line 65, in _hy_anon_fn_15
(project [?params ?m ?o]
File "/home/zmd/Code/Examination/hydiomatic/hydiomatic/rulesets/syntaxo.hy", line 67, in _hy_anon_fn_14
(≡ ?call-name (+ ?o ?m)))))
File "/home/zmd/Code/Examination/hydiomatic/src/hy/hy/models/list.py", line 37, in __add__
return self.__class__(super(HyList, self).__add__(other))
TypeError: can only concatenate list (not "HySymbol") to list
I made a wild guess that maybe it might be a Python 2 vs. 3 issue (because the file to be analyzed runs under the Hy I got from "sudo pip3 install hy" whereas I was running Hydiomatic from a Python 2 virtualenv) but I get the same thing in a Python 3 venv. The installation of Hydiomatic itself seems okay, because it can at least turn (= (% x 2) 0)
into (is_even x)
in a test file I made.
As mentioned here, we should probably add source and target versions to the rulesets and command line. This would allow us to safely reinstate the old and new Hy syntax transformations rules that currently clash.
While it's nice that we can simplify Hy code, but it would be useful if we could obfuscate it as well. Sadly, simply running the rules backwards will not work, they'll never terminate (or they'll even die, if they assume we always have the expression available).
So, we need a way to obfuscate code, preferably one that allows us to reuse the existing rules, or at least some of them.
Per this discussion, for some of the new Hy update rules, we will need to add new import
and require
statements.
The additions will need to be scoped somewhat intelligently (e.g. the outer-most scope that encompasses more than one use of the import
/require
). For standard Python-scoped objects, this isn't too complicated, but for macros—especially pre hylang/hy#1682—the naive per-line/in-place addition might be necessary.
currently aderall mentioned in project's readme does not point to right location. Just something to keep in mind when updating the readme, next time
The optimisation ends up doing this:
(setv (, a b c) [1 2 3])
Now if any of the values tries to reference a former var, this will fail. We really need separate setv
s.
(= (% n 2) 0))
=> (even? n)
(= (% n 2) 1))
=> (odd? n)
(isinstance x type)
=> (instance? type x)
(isinstance x float)
=> (float? x)
(isinstance x int)
=> (integer? x)
(none? x)
=> (nil? x)
(isinstance x string)
, (isinstance x unicode)
=> (string? x)
(for* [x iterable] (yield x))
=> (yield-from iterable)
Can the [pre/post]walk
and fixed-point iterations be performed in miniKanren (e.g. using recursive relations, conde
/alwayso
/anyo
, etc.)?
If so, are there any advantages to doing that?
When given something like:
(defn foo [x]
(let [[y (inc x)]]
(print x y)))
Hy will create something like:
(defn foo [x]
((fn [] (setv y (inc x))
(print x y))))
It'd be nice if we could get rid of the inner function
(defmacro if-true [condition &rest stuff]
`(if (not (is False ~condition)) ~@stuff))
This gets simplified to (unless (is False ~condition) ~@stuff)
, which is wrong in multiple ways:
~@stuff
can expand to both branches, so unless is wrong here.(if (not ...))
to (if-not ...)
, it should favour (not (is False))
=> (is-not False)
.The warning rules print their warning, so they appear out of order when running hydiomatic.hy. The warnings also do not appear at all when running without diff mode.
To fix this, hydiomatic should be taught to recognise injected code, when the returned form has multiple members. It's not easy to do that, because we need to distinguish between arrays and injected code...
If we have code like:
(try
(do
....))
Simplify it to (try ...)
.
(-> a (b))
should simplify to (b a)
, but it doesn't, simplifies to ((b) a)
, which is wrong. Also, (-> a (foo b))
simplifies badly too, the rules of threading are not followed at all. Will need to revisit.
When using the latest hydiomatic
release with Hy v0.16.0, I got the following error:
hydiomatic.hy -h
Traceback (most recent call last):
File "/usr/lib/python3.7/runpy.py", line 261, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "<frozen importlib._bootstrap_external>", line 860, in get_code
File "/home/yoan/.local/bin/hydiomatic.hy", line 3
[argparse]
^
hy.errors.HySyntaxError: parse error for special form 'import': should have reached end of form: HyList([
HySymbol('argparse')])
Following the Hy CHANGELOG, release 15, that states:
(import [foo])
is no longer allowed. Use(import foo)
instead.
Which seems to have been fixed in f7e56e2
Could it be possible to make a new Pypi release including the fixes?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.