11 ms·
Some people have a lot of time on their hands. (defmacro cfor [initialize condition advance #* body] `(do ~initialize (while ~condition (do ~@body
by epr 4y ago
Some people have a lot of time on their hands.
(defmacro cfor [initialize condition advance #* body]
`(do ~initialize
(while ~condition (do ~@body ~advance))))
(cfor (setv i 0) (< i 10) (+= i 1)
(print i))
This runs on the python vm with hy right now. Took about 2 mins to have it up and running after noticing this post on hn. Couldn't pass it up.
- ihatepython 4y agoI don't understand, this gives C style for loops with C syntax?
- __jem 4y agolooks like it to me cfor(setv(i, 0), i < 10, i += 1) { print(i) }
- ihatepython 4y agoDo the brackets actually work or do you still have to get the indentation right?
- __jem 4y agono, just saying you can trivially convert any lisp code to c style syntax by moving the function call parenthesis to the right and converting wrapping parens into curly braces.
- epr 4y agoThis adds c style for loops to hy, which runs on the normal cpython vm, and therefore can make use of the thousands of open source python libraries available. My reply to the post was tongue in cheek. The point is that you can add on arbitrary language features to python using hy (any lisp, really). The syntax in question is normally referred to as an s-expression.
- deleted 4y ago[deleted]