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…
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…
I have the following code:
(require [hyrule [-> ->>]])
(defn static/freezer [value freezer]
(cond [(not value) (setv freezer [])]
[(isinstance value list)
(do (if (not…
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)")
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',…
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):
…
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…
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,…
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…
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…
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…
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…
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))
…