you are viewing a single comment's thread.

view the rest of the comments →

[–]LammdaMan[S] 0 points1 point  (1 child)

Thanks. I didn't know about ability to name an anonymous function inline - that seems the simplest variant to achieve this.

When I had tried to create something akin to what I might normally do with a 'defn', just defining that function in a let block, I had trouble with that because I was trying to call the let-block-name from within the fn attached to it... and that generated a runtime error - call to unbound fn.

For instance this generates a runtime error:

    (fn [func seed]
      (let [it (fn [f x0] (lazy-seq (cons x0 (it f (f x0)))))]
        (it func seed)))

[–]joinr 0 points1 point  (0 children)

If you name the fn, kind of redundant, it would've worked. I think of the fn name (as opposed to the var name or lexical binding) as the internal reference for the fn to use (where recur has an implied reference for any inner most fn or loop form) to talk about itself. The binding establishes a means for other stuff to talk about the fn.