digikar99/polymorphic-functions

FLET as a NLAMBDA replacement

Closed this issue · 3 comments

phoe commented

#-(or ccl sbcl)
`(lambda ,param-list
,(lambda-declarations parameters)
,declarations
(block ,block-name
,@(butlast body)
,(ensure-type-form return-type (lastcar body)))))

You can use (labels ((name ...)) #'name) (or flet) instead of a fully anonymous function - multiple implementations will show the local name in the backtraces. See e.g. https://github.com/phoe/trivial-custom-debugger/blob/a560594a673bbcd88136af82086107ee5ff9ca81/trivial-custom-debugger.lisp#L39-L40

Right! I had originally started out with (alexandria:named-lambda name ...), but that posed an issue for recursive functions. But instead of name, I later went with (polymorph ,name ,type-list); so alexandria:named-lambda looks useable now, but I'll stick with FLET I guess:

Does this look good?

(named-lambda ,(intern (write-to-string `(polymorph ,name ,type-list))
                       (symbol-package block-name))
  ,param-list
  ,(lambda-declarations parameters)
  ,declarations
  (block ,block-name
    ,@(butlast body)
    ,(ensure-type-form return-type (lastcar body))))
phoe commented

Sure, seems good to me.

Thanks for the review!