Questions tagged [hy]

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

Further reading:

99 questions
14
votes
1 answer

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 permissions to the file with chmod +x myfile.hy.…
Hugo
  • 546
  • 5
  • 12
9
votes
2 answers

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 standard Python module?
MRocklin
  • 55,641
  • 23
  • 163
  • 235
9
votes
2 answers

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 how to start a REPL. At the bottom of the github…
DJG
  • 6,413
  • 4
  • 30
  • 51
6
votes
1 answer

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.2 setosa 1 4.9 3.0 …
The Unfun Cat
  • 29,987
  • 31
  • 114
  • 156
5
votes
1 answer

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] (setv varname (HySymbol (+ "var" (str element)))) …
Srv19
  • 3,458
  • 6
  • 44
  • 75
4
votes
1 answer

Macros that loop and transform a sequence of forms

I am writing macros to simplify making plots with matplotlib. My first attempt, as follows, works correctly: (defmacro insert-ax [body] `((getattr g!ax (str '~(first body))) ~@(rest body))) (defmacro/g! plot [main &optional title [fig-kwargs {}]] …
syntaxfree
  • 237
  • 2
  • 11
3
votes
1 answer

HyLang : Howto simplest for loop in hy?

I wanna get Hy! How, In Hylang, do I do the simple Python loop: for i in range(5): print(i)
dagmarPrime
  • 317
  • 3
  • 9
3
votes
1 answer

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 ?
Xu Qinghan
  • 153
  • 1
  • 6
3
votes
1 answer

Hylang Map Destructuring

Does hylang support map destructuring like in clojure? For example: https://gist.github.com/john2x/e1dca953548bfdfb9844#maps
Daniel Severo
  • 1,768
  • 2
  • 15
  • 22
2
votes
1 answer

Non-existent hy macros runs assertions, but fails appropriately with everything else

In the following code: (eval-and-compile (import os hy)) (eval-and-compile (import pathlib [Path])) ; (defmacro with-cwd [dir #* body] ; (setv cwd (hy.gensym)) ; `(let [ ~cwd (.cwd Path) ] ; (try (.chdir os…
ShadowRylander
  • 361
  • 2
  • 8
2
votes
1 answer

importing module from current folder in hy

Has import changed in Hy version 1.0a4+199.g22021c56? I'm trying to import a file from the same folder (or cwd), but I get ModuleNotFoundError: No module named 'thenameofthefile' Even if I append current path to sys.path. This is how you can…
plokstele
  • 63
  • 4
2
votes
2 answers

Dynamic bindings with let in Hy?

Comming from Common Lisp, I'm trying to use let to shadow the value of a global variable dynamically. (setv glob 18) (defn callee [] (print glob)) (defn nonl [x] (callee) (let [glob x] (callee)) (callee)) (nonl 39) => 18 18 18 Is…
2
votes
2 answers

How to serialize hylang s-expression into PostgreSQL json/json-b?

We are trying to use hylang as DSL for some financial business flow. We were trying to use business rules as JSON, but switched to DSL using hy language. Now we need to persist s-expression items into postgreSQL as like previous JSON-B items. Is…
Kamyar
  • 2,494
  • 2
  • 22
  • 33
2
votes
1 answer

What is the difference between if and cond?

Perhaps I am misunderstanding something. In Hy, if* can take (after the if* symbol) one predicate (evaluation returned if there are no further expressions) zero or one consequent (evaluated and returned if the predicate is truthy) (if a consequent…
dagmarPrime
  • 317
  • 3
  • 9
2
votes
1 answer

Why is it that '0 is false, but 'False is true?

I was playing around with symbols and was surprised to see that: hy 0.18.0 using CPython(default) 3.7.3 on Linux => (bool '0) False => (bool 'False) True => Is that a design decision? What is the best way to represent boolean values on Hy?
λlover
  • 23
  • 3
1
2 3 4 5 6 7