Anonymous function returning 1 using #()

后端 未结 3 1118
礼貌的吻别
礼貌的吻别 2021-02-07 06:19

Using defn or fn it\'s easy to create a function that taking one argument that ignores it and returns 1:

(defn ret1 [arg] 1)
(fn [arg] 1)

Is it

相关标签:
3条回答
  • 2021-02-07 06:36

    #(do %& 1) ... but (constantly 1) is better.

    0 讨论(0)
  • 2021-02-07 06:39

    The #() syntax can't be used to create functions that have unused parameters in the way your description requires. This is a limitation of the #() reader macro.

    I would recommend not using #() and instead just writing (constantly 1) which is a very brief way to create a function that ignores a parameter and instead always returns 1.

    0 讨论(0)
  • 2021-02-07 06:40

    How about #(identity 1)? which does the same thing as #(do %& 1) or (constantly 1).

    0 讨论(0)
提交回复
热议问题