Questions tagged [hy]

Hy is a Lisp dialect that's embedded in Python.

Further reading:

99 questions
1
vote
3 answers

How to write a macro like dot(.) operator in hylang?

We have some async properties (using @property) and some usual ones. We have to use hy to check if one is async or not using asyncio.iscoroutine function. The problem is we have to use getattr and not . operator, since dot will call the property…
Kamyar
  • 2,494
  • 2
  • 22
  • 33
1
vote
1 answer

macro inside of macro creates a list of None

I have defined two macros: (defmacro property [name type] `(setv ^(of Optional ~type) ~name None)) (defmacro data-type [vname &rest propertys] `(with-decorator dataclass (defclass ~vname [] ~propertys))) When called as: (data-type…
1
vote
2 answers

Macro string Interpolation / How to unquote inside string?

I have a macro like: (defmacro test [x] `"~x") After running it expands to the following: => (test abc) '~x' Why doesn't it expand to 'abc'? What is the correct method to unquote inside a string?
1
vote
1 answer

How to include Hy code into a separate file, and then import that using Hy?

I am just starting using Hy. For example we have this Hy code: (print "Hy, world!") And we have two pieces of Python code. Piece one: print("Some python code") Piece two: print("Some other python code") How to include Hy code into a separate…
vasili111
  • 6,032
  • 10
  • 50
  • 80
1
vote
2 answers

How to include Hy code inside python code?

For example we have this Hy code: (print "Hy, world!") And we have two pieces of Python code. Piece one: print("Some python code") Piece two: print("Some other python code") How can we make something like this: print("Some python code") (print…
vasili111
  • 6,032
  • 10
  • 50
  • 80
1
vote
1 answer

walk must return same type as input?

I'm unclear on how the outer function provided to walk should work. The example in documentation referenced here: https://docs.hylang.org/en/stable/contrib/walk.html Suggests the outer function can be first which would return the first element of…
Phil
  • 592
  • 6
  • 15
1
vote
1 answer

Configuring Hy to run on VSCode

I'm trying to debug Hy code in Visual Studio Code. I have downloaded the hy-mode theme and it works great. There's only one problem. The hy-mode theme disables breakpoints. I can add a breakpoint to my Hy code by switching to a totally unrelated…
lsusr
  • 163
  • 1
  • 7
1
vote
1 answer

Macros that generate code from a for-loop

This example is a little contrived. The goal is to create a macro that loops over some values and programmatically generates some code. A common pattern in Python is to initialize the properties of an object at calling time as follows: (defclass…
syntaxfree
  • 237
  • 2
  • 11
1
vote
1 answer

how to eval a cond case and return function object?

got TypeError: Don't know how to wrap : . at 0x000001B879FD3D08> when run ;a fn object (setv a_fn (fn [x] (+ 1 x))) ;a mock predicator (setv predicator True) ;inject predicator and a_fn…
Xu Qinghan
  • 153
  • 1
  • 6
1
vote
1 answer

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 work
1
vote
1 answer

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 python environments. Consider this…
HippoMan
  • 2,119
  • 2
  • 25
  • 48
1
vote
1 answer

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') # assumes there is an hy function called…
HippoMan
  • 2,119
  • 2
  • 25
  • 48
1
vote
1 answer

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, 4, 5, 6, 7], dtype=uint8) for x in…
Plus Ultra
  • 39
  • 3
1
vote
2 answers

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))))))) ^ LexException: Ran into a…
Srv19
  • 3,458
  • 6
  • 44
  • 75
1
vote
1 answer

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='news') to get a list of words in the 'news'…
user3678483