Questions tagged [hy]

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

Further reading:

99 questions
0
votes
1 answer

with-gensyms Error With Hy Documentation Example Code

I am fairly new to Hylang and I am trying to get the last two code snippets here to work. No matter what I do I get the error that with_gensyms is not defined. I am running hy version 0.27.0, which matches the version of the docs. Below is my sample…
jmwright
  • 131
  • 1
  • 7
0
votes
1 answer

No diffs from pytest AssertionErrors when straying from common test file name scheme

I have the following conftest.py for a pytest plugin for hy, adapted from the official hy conftest, but AssertionErros are not diffed for files beginning with test-, only test_, even when using -vv on the command line. import os from pathlib import…
ShadowRylander
  • 361
  • 2
  • 8
0
votes
1 answer

Imported modules not working with macros (anymore)

With the following pytest file: (import pytest [mark]) (import pathlib [Path]) (require oreo [with-cwd]) (defn [mark.with-cwd] test-with-cwd [cookies] (let [ cwd (.cwd Path) ] (with-cwd cookies (assert (= (.cwd Path) cookies))) …
ShadowRylander
  • 361
  • 2
  • 8
0
votes
1 answer

Locally rebinding `+`

How to translate this Clojure code to Hy, so it prints 2? It doesn't need to be like Clojure, i just want to hide + and replace it with - in local environment. (defmacro q [expr] `(let ~'[+ (fn [x y] (- x y))] ~expr)) (print (q (+ 3 1))) In…
Takis
  • 8,314
  • 2
  • 14
  • 25
0
votes
0 answers

Is there a way to get auto-complete(IntelliSense) for hy?

I have ubuntu 22.04 and hy 0.25 I tried hy-mode, i failed. I installed doom emacs, but i got this I also tried to install hy 0.20.0 and i failed again i got this. If anyone has auto-complete for hy, if possible to send what i should do, hy-mode or…
Takis
  • 8,314
  • 2
  • 14
  • 25
0
votes
1 answer

How to type-hint in Hy

Is it possible to type-hint variables and return values of functions in Hy language? # in python we can do this def some_func() -> str: return "Hello World"
pooooky
  • 490
  • 2
  • 12
0
votes
1 answer

How to set two variables at once in Hy

I just started learning Hy (my first attempt at a Lisp dialect). I have a function that returns a tuple of 2 values, and I don't know how to receive it: (defn function [] #("Hello" "World")) ; I don't know how to initialize two variables here (setv…
pooooky
  • 490
  • 2
  • 12
0
votes
1 answer

Requiring `hy' macro with `raise' function triggers `raise' on `require'

When trying to require the following macro in another file, the raise seems to be triggering immediately: (defmacro assert [a [b True] [message None]] `(unless (= ~a ~b) (raise (AssertionError (or ~message ~a))))) This results in an…
ShadowRylander
  • 361
  • 2
  • 8
0
votes
1 answer

Require macros from the same file in another macro

In the following code, given that hy seem to give a NameError when not explicitly requiring a macro's dependent macros, how do I require a macro in the same file in another macro? (defmacro with-cwd [#* body] `(do ~@body)) (defmacro let-cwd [vars #*…
ShadowRylander
  • 361
  • 2
  • 8
0
votes
1 answer

__init__.py for hy modules with relative imports

How do I require all functions in a hy module in an __init__.py? I tried to use a similar model as in the hyrule __init__.py, but am getting the following error: Traceback (most recent call last): File "", line 1, in File…
ShadowRylander
  • 361
  • 2
  • 8
0
votes
1 answer

Mimic `let' statement in a macro

In the following directory structure: . ├── a │ ├── 1 │ ├── 2 │ ├── 3 │ └── 4 ├── b │ ├── 5 │ ├── 6 │ ├── 7 │ └── 8 ├── c ├── d └── test.hy The following code prints the wrong path: (eval-and-compile (import os) (import pathlib…
ShadowRylander
  • 361
  • 2
  • 8
0
votes
1 answer

Difference between using a for loop to run a body in a macro versus mapping `exec' over the body

What's the difference between using (map exec ~body) versus (for [node ~body] node) in the following code? (defmacro with-cwd [dir #* body] `(let [ cwd (.cwd Path) ] (try (.chdir os ~dir) ;; Should I use…
ShadowRylander
  • 361
  • 2
  • 8
0
votes
0 answers

How does the official `hylang/hy' repo run its pytests on its native / `.hy' files?

Is a custom plugin used, such as pytest-hylang or hytest?
ShadowRylander
  • 361
  • 2
  • 8
0
votes
0 answers

LexException: f-string: trailing junk in field

In doing the following, I'm getting the error LexException: f-string: trailing junk in field: (nixos-install #* ctx.args :I (with [f (open (+ resources "/flake.lock"))] …
ShadowRylander
  • 361
  • 2
  • 8
0
votes
1 answer

Does Hy have inline if?

What is the Hy equivalent of Python's a if condition else b? I'm trying to convert something like this return (quicksort(under) if under else []) + same + (quicksort(over) if over else []) to Hy. It avoids calling quicksort() if the list is empty.…
Tuor
  • 875
  • 1
  • 8
  • 32