Questions tagged [hy]

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

Further reading:

99 questions
0
votes
1 answer

Convert python literal_eval string to hy

I would like to convert the following to Hy, but I can't seem to figure out how to do it; is there perhaps a way to convert a string of python code to the hy syntax? I don't know if py would work because the evaluated result of f_back may not be…
ShadowRylander
  • 361
  • 2
  • 8
0
votes
1 answer

Render mangled hy attribute names as regular strings

If I have an attribute self.internal/freezer in a class, and I raise an error via (raise (AttributeError f"Sorry! '{attr}' doesn't exist as an attribute!")), how can I get the attribute name to render as internal/freezer instead of…
ShadowRylander
  • 361
  • 2
  • 8
0
votes
1 answer

"Ran into a RPAREN where it wasn't expected" when using "->>"

I have the following code: (require [hyrule [-> ->>]]) (defn static/freezer [value freezer] (cond [(not value) (setv freezer [])] [(isinstance value list) (do (if (not…
ShadowRylander
  • 361
  • 2
  • 8
0
votes
1 answer

Access attribute and method names with slashes or asterisks defined in Hy from Python

If I were to do the following: (setv a/b 12) How would I access the variable in Python, such as from a regular python module, or simply using (py)? (py "print(a/b)")
ShadowRylander
  • 361
  • 2
  • 8
0
votes
1 answer

Expanding macro results in KeyError

With the following (simplified) code: (setv agnostic-manager-installers {}) (defmacro alias-assign [am &rest aliases] (for [alias aliases] (assoc agnostic-manager-installers (str alias) (-> (globals) (get (str am)) (get…
ShadowRylander
  • 361
  • 2
  • 8
0
votes
2 answers

Using `click` in a shell script that has a Hy program in a here document

How can I convert the following working example of using click with shell + python repl (I think) to hy? python3 - "$@" <<'EOF' import click @click.command() @click.option('--count', default=1, help='Number of greetings.') @click.option('--name',…
ShadowRylander
  • 361
  • 2
  • 8
0
votes
5 answers

Cosine Similarity in linear time using Lisp

The cosine similarity of two lists can be calculated in linear time using a for-loop. I'm curious as to how one would achieve this using a Lisp-like language. Below is an example of my code in Python and Hy (Hylang). Python: def cos_sim(A,B): …
jwnz
  • 75
  • 5
0
votes
0 answers

Parse arguments in Hy macro

I need help with parsing arguments in a Hy Macro that generates code for a class. What I am trying to accomplish: A macro that will generate a class with predefined properties. The property names are the variables used to initialize the class. Here…
pacificprince
  • 53
  • 2
  • 5
0
votes
1 answer

Hy equivalent to * operator in Python's function arguments that forces keyword arguments

Recently I have been trying to write a simple bot in Hy with Discord.py. In Discord.py we can write a command like this to turn the last argument into a full string that includes spaces: @commands.command(description="", help="") async def say(self,…
Gary C.
  • 35
  • 3
  • 7
0
votes
1 answer

Why are calls to `defmacro` evaluating to None?

I was writing the following pieces of code: (require [hy.contrib.walk [let]]) (defn maybe? [command-text] (let [splitted (.split command-text " ")] (= (get splitted 0) "maybe"))) (defn if? [command-text] (let [splitted (.split…
Namudon'tdie
  • 306
  • 1
  • 10
0
votes
1 answer

Dictionary merging in Hy

If I have two dictionaries, and want to merge them with preference to the latter regarding conflicting keys, I would do in Python: In [1]: x = {'a': 1, 'b': 2} In [2]: y = {'b': 3, 'c': 4} In [3]: {**x, **y} Out[3]: {'a': 1, 'b': 3, 'c': 4} How…
Namudon'tdie
  • 306
  • 1
  • 10
0
votes
1 answer

How to declare 'main' in a hy program

As per the official docs, I should be able to to use def main [ &rest _ ] I tried the example in a let block : (import argparse) (require [hy.contrib.walk [let]]) (def main [&rest _] (let [parser (argparse.ArgumentParser)] (.add-argument…
dedupe
  • 9
  • 2
0
votes
0 answers

Calysto Hy not starting properly

I have run an intro to Hy session for the Atlanta Functional Programming meetup. One audience for this intro is Pythonistas that might want to use Hy to get acquainted with a Lispy syntax by porting their python projects to Hy. Since Jupyter is…
dagmarPrime
  • 317
  • 3
  • 9
0
votes
1 answer

How to use the pandas apply method in hy

I'd like to create a new column in pandas using the .apply method where I can pass a custom function df["newcol"] = df["oldcol"].apply(lambda x: x + 1) or df["newcol"] = df.apply(lambda row: row["oldcol"]+1) How to achieve this in hy ? so far I am…
dedupe
  • 9
  • 2
0
votes
1 answer

macro for pandas column setting in hy

I feel I'm writing functions needlessly for the following operation of setting several derived columns sequentially: (defn add-cols[d] (do (setv (get d "col0") "0") (setv (get d "col1") (np.where (> 0 (get d "existing-col")) -1 1)) …
dedupe
  • 9
  • 2