Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace with-decorator with decorator lists in defn and defclass #2270

Merged
merged 12 commits into from
May 9, 2022

Conversation

Kodiologist
Copy link
Member

@Kodiologist Kodiologist commented May 6, 2022

@Kodiologist
Copy link
Member Author

A possible extension would to make the brackets optional for the common case of only one decorator. However, (defn foo bar [] …) arguably looks like you're defining a function named foo, anyway.

@allison-casey
Copy link
Contributor

Neat!! I'll take a look after work tonight. I do think we should keep the explicit brackets for single decorators. the ambiguity of which is the fn name doesn't seem worth the bracket saving two characters on the brackets.

What is the evaluation order of multiple decorators using the new syntax? Python is right to left/bottom up. Is this the same way?

@Kodiologist
Copy link
Member Author

It should be the same as Python's. I'll tweak a test to make it sensitive to the order in which decorators are called.

@Kodiologist
Copy link
Member Author

And yes, the decorator expressions themselves are evaluated outer-first whereas the functions obtained by this evaluation are called inner-first, in both Python and this Hy implementation. Thus both of these programs print 1 through 4 in order:

def d(n):
   return lambda f: [print(n), f][1]

@[print(1), d(4)][1]
@[print(2), d(3)][1]
def f():
    pass
(defn d [n]
  (fn [f] (print n) f))

(defn
  [(do (print 1) (d 4)) (do (print 2) (d 3))]
  g [])

Copy link
Contributor

@allison-casey allison-casey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! just needs documentation updated

@Kodiologist
Copy link
Member Author

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants