Questions tagged [hy]
Hy is a Python <--> Lisp layer. It helps make things work nicer, and lets Python and the Hy lisp variant play nice together.
0
votes
0answers
14 views
How to load Hy package in zipapp?
I have a Python script (as entry point), a Hy library (simply add two columns) and an input data file:
$ cat add_cols/app.py
import hy
import sys
from mylib import add2col
def main():
inp = sys....
0
votes
1answer
18 views
What is the equivalent of `if x in y` in hy?
I can't seem to find a builtin (or equivalent) in hy that lets me check for something without handling an exception
I would like to write something like:
(setv foo {:a 1 :b 2})
(if (in foo :c)
(...
0
votes
0answers
33 views
multiprocessing in Hy lang
Is it possible to run multiprocessing codes in Hy?
The following code results in error
(import [multiprocessing :as mp])
(setv pool (mp.Pool 5))
(defn f [x] (print x))
(defmain []
(pool.map f (...
2
votes
1answer
57 views
Why does the list comprehension not generate a list of tuples?
I try to make a macro for defining ctypes.Structure. The macro is listed as follows:
(defmacro struct [name fields]
`(defclass ~name [ctypes.Structure]
[-fields-
~(lfor i (range 0 (len ...
2
votes
2answers
33 views
Substitution of list/dictionary element by the index in Hy
Is there any way to substitute a value for an element of list or dictionary by the index in Hy?
The nth function seems not corresponds to Python's square bracket.
I had expected like the following ...
0
votes
1answer
39 views
how to eval a cond case and return function object?
got TypeError: Don't know how to wrap <class 'function'>: <function test_cond_list_fn.<locals>.<lambda> at 0x000001B879FD3D08>
when run
;a fn object
(setv a_fn (fn [x] (+ 1 x)))
...
1
vote
1answer
21 views
how to print HyExpression in python?
how to print a object HyExpression as
HyExpression([
HyExpression([
HySymbol('/'),
HyInteger(2)]),
HyExpression([
HyString('ceil')])])
as
'((/ 2) ("ceil"))'
in console ...
1
vote
1answer
51 views
Syntax for specifying Metaclasses in Hy
What is the syntax for for specifying metaclasses in Hy. I tried the following:
(defclass Metaclass [] )
(defclass Foo [ :meta Metaclass ] )
(defclass Foo [ [:meta Metaclass] ] )
but this did not ...
2
votes
1answer
59 views
Running Django in Hy
I'm writing a Django webserver using Hy, a Lisp dialect that compiles into Python ast. I have been able to write everything in Hy except for specific .py files that Django looks up automatically.
...
1
vote
1answer
83 views
Hylang Map Destructuring
Does hylang support map destructuring like in clojure?
For example: https://gist.github.com/john2x/e1dca953548bfdfb9844#maps
0
votes
1answer
35 views
How to call variadic function with some parameters before variadic parameter using hy?
I am trying to write something similar to:
@classmethod
def write(cls, records, values, *args):
return super(Hello, cls).write(records, values, *args)
But I have issues with passing the *args ...
1
vote
1answer
51 views
python3/hy - When using hy.eval, imports and globals are not shared
I understand how to use hy.read_str and hy.eval from python to evaluate an hy expression from within python. However, when I use this methodology, imports and globals are not shared between the hy and ...
1
vote
1answer
100 views
python3/hy - evaluating hy expressions in python?
I know how to import an hy module into python. All I have to do is create a something.hy file containing hy code and then do the following ...
import hy
import something
something.func('args') # ...
1
vote
1answer
98 views
Using numpy.nditer in Hy
In python, the following code iterates a numpy array (the for loop), and the values of the numpy array are changed:
import numpy
a08_1 = numpy.arange(8).astype(numpy.uint8)
# a08_1: array([0, 1, 2, 3,...
0
votes
1answer
242 views
Inheriting and instantiating a subtype of typing.NamedTuple in HyLang
I'm trying to use Hy, which is a Lisp dialect built on top of Python.
I've tried running the following, but, as expected, I get an AttributeError: Cannot overwrite NamedTuple attribute __init__.
(...
0
votes
1answer
63 views
Weird HyLang dot notation behavior
Why does the following work:
(def session (sessionmaker))
(.configure session :bind engine)
...but (def session (.configure (sessionmaker) :bind engine)) causes my Hy application to throw a NoneType ...
3
votes
1answer
253 views
Generating Python code with Hy macros
I am trying to generate some python code from Hy. How is that done better?
I have tried several approaches. One is with a macro:
(defmacro make-vars [data]
(setv res '())
(for [element data]
...
1
vote
2answers
62 views
Why does my hylang program fail at parsing?
I have written a small hylang program that parses a log. However, when i try to evaluate it, i get the following error:
File "", line 8, column 38
(setv rule (.next irule)))))))
...
7
votes
1answer
2k views
Shebangs in conda managed environments
I am trying to write a program in Hy and run it per the instructions on the Quickstart page in the documentation.
So I installed Hy using pip from the GitHub repo per the docs, then added executable ...
0
votes
1answer
83 views
How to pass named arguments into python function from hy
I am trying to use a python function with named arguments from hy.
I'm using the NLTK library as well.
In python I would do something like this
from nltk.corpus import brown
brown.words(categories='...
0
votes
1answer
41 views
How can I create and execute a function/method while a script is running?
A part of a script I'm making requires that new functions be defined and made available on during execution. The function defines OK, but I'm getting an error when I try to use it:
(import io)
(defn ...
0
votes
1answer
64 views
How do I change the name of an XML tag in Hy?
This is my first post here...
I am trying to change an XML element using assignment in Hy (running on Python 3).
When I try to run the code snippet:
(setv tco (BeautifulSoup "<meek/>" 'xml))
(...
3
votes
1answer
165 views
Using pandas loc in hy
I want to do the following in hy:
from StringIO import StringIO
import pandas as pd
s = """sepal_length sepal_width petal_length petal_width species
0 5.1 3.5 1.4 ...
0
votes
1answer
104 views
hylang replace multiple words
I would like to perform multiple replace operations on a string, in hylang
Given that hy is very similar to python i found a related solution on Python replace multiple strings
# python
def replace(...
1
vote
2answers
100 views
Is there a way in the hy language to use doto on self?
hopefully someone can help me with this hy question. I am porting some python code over to hy, and was trying to figure out how I could remove some repetitive code using the doto macro. For example, ...
0
votes
1answer
82 views
Importing my own .hy files and using their elements
Suppose I have a file foo.hy, which looks like this:
(def friends ["Joe" "Mark" "Bob"])
And another file bar.hy, in the same directory as foo.hy, which looks like this:
#!/usr/bin/env hy
(import ...
2
votes
1answer
131 views
Creating objects in Hy
I've looked all over the documentation of Hy, but I can't find a way to create objects anywhere. More specifically, I'm trying to follow this PySide tutorial, but converting each command to Hy, and I'...
5
votes
2answers
368 views
How can I build a Python module in Hy?
I'd like to use Hy, a dialect of Lisp on top of Python. However my coworkers all use Python and aren't likely to switch over to a Lisp dialect any time soon.
How can I package Hy code into a ...
8
votes
1answer
686 views
Use repl for Hy in Emacs
I have successfully installed hy-mode from https://github.com/hylang/hy-mode. I now can open a .hy file in emacs and have syntax highlighting, and editing with paredit is a joy.
I however, don't know ...