Questions tagged [hy]

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

Further reading:

99 questions
0
votes
1 answer

configure automatic Hy REPL imports

I've been absolutely loving the Hy REPL. However it would speed up my workflow immensely if I could have a set of default imports at startup. Clojure has a way of configuring startup imports via leiningen config. Currently I load the repl this…
dedupe
  • 9
  • 2
0
votes
1 answer

How to construct AST of Hy lang snippets

I have several Hy Lang code snippets that I use in my python project. I was wondering if there is a relatively easy way for me to get an Abstract Syntax Tree of the Hy code with some python library or maybe even the Hy compiler itself (I've looked…
0
votes
1 answer

how to use hy to when operating on pandas dataframe columns

There seems to be no documentation on how to use hy on single column pandas operation such as the following. Would appreciate any help: # simple instantiation to scalar df['a'] = '2' # the above can be done like so: (-> df (.assign :a "2")) but…
dedupe
  • 9
  • 2
0
votes
2 answers

Does Hy code require indenting, just like Python?

I am unable to submit multiple lines of Hy to Python without indentation: import hy expr=hy.read_str("(+ 1 1)(+ 2 2)") hy.eval(expr) => 2 The second '(+ 2 2)' statement has apparently been ignored. Obviously Python's raison d'etre is indentation,…
berniethejet
  • 236
  • 2
  • 11
0
votes
1 answer

How do I setup a hy project so that I can use pytest for testing

I'm trying to test a hy project with pytest but am having trouble with pytest discovering my tests. What needs to be done so that pytest can pick up tests written in hy? I've made the assumption that tests can be written in hy and discovered by…
GHvW
  • 17
  • 2
  • 7
0
votes
1 answer

RecursionError in Python Using Hylang

First off let me just say I know what I'm doing is not ideal, but I'm trying to write the member? function from The Little Schemer using Hy. (setv else True) (defn null? [lst] " If list is empty return True else False " (if lst False …
decabytes
  • 386
  • 2
  • 14
0
votes
2 answers

Is there a way to capture a name from the environment when using hy.eval?

I'm trying to create functions in hylang and use them from python but the created functions don't seem to have access to the environment passed to hy.eval. import hy env = dict(x=5) func = hy.eval(hy.read_str('(fn [] x)'), env) print(func()) The…
Kris
  • 1,358
  • 13
  • 24
0
votes
1 answer

`self` can not use as arguments of a hy macro

The following macro tries to assign a member variable from init argument. But name 'self' is not defined (defmacro optional_assign [x &optional [base self]] `(lif ~x (setv (. ~base ~x) ~x) (setv (. ~base ~x ) None) )) (defclass clsa [] …
niitsuma
  • 117
  • 1
  • 4
0
votes
1 answer

Importing .hy file with function definition in .py file and after calling function from .hy from python

My .py file looks like: import hy import example foo2() My .hy file looks like: (defn foo2 [] (+ 1 1)) .hy file is in same folder as .py file. If I run .py file I am getting error: runfile('D:/del/hy2/untitled46.py', wdir='D:/del/hy2') Reloaded…
vasili111
  • 6,032
  • 10
  • 50
  • 80
0
votes
1 answer

HyLang import_buffer_to_ast removed version 0.18.0

I am updating from Hy 0.12.1 to the newest version 0.18.0, and I make heavy use of the import_buffer_to_ast function in my python code. This function has been removed from hy.importer, I was hoping someone could lead me to a good alternative.
JoCee
  • 50
  • 4
0
votes
2 answers

Auto insert await when asyncio function in hy-lang

The following do/a macro can auto-insert await when asyncio function is used. The following also shows usage. (import asyncio) (import time) (defmacro do/a [&rest code] `(do ~@(lfor p code (if (= (cut (str…
niitsuma
  • 117
  • 1
  • 4
0
votes
1 answer

How can I create a Python standalone executable using Hy modules?

Given an entry file main.py like so: #-*- coding: utf-8 -*- # -*- mode: python -*- import hy import os.path import hymodule datas=[(os.path.dirname(hy.__file__), 'hy')] hymodule.hello_world() Given a Hy file hymodule.hy: (defn hello-world [] …
Phob1a
  • 743
  • 1
  • 10
  • 19
0
votes
0 answers

Why is my version of Hy unknown and deftag undefined?

Why hy unknown? How to use deftag? Snippet from http://docs.hylang.org/en/stable/language/api.html#deftag gt@gt-ThinkPad-X230:~$ hy --spy hy unknown using CPython(default) 3.6.8 on Linux => (deftag ♣ [expr] `[~expr ~expr]) from hy…
dagmarPrime
  • 317
  • 3
  • 9
0
votes
2 answers

Example of using hylang with python multiprocessing

I am looking for an example of using python multiprocessing (i.e. a process-pool/threadpool, job queue etc.) with hylang.
ggg123
  • 99
  • 10
0
votes
1 answer

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.argv[1] out = sys.argv[2] print(f'read…
Leo
  • 1,710
  • 2
  • 26
  • 29