Infer names for anonymous lambdas #551

Open
opened 2020-06-24 00:57:31 +00:00 by fare · 2 comments
fare commented 2020-06-24 00:57:31 +00:00 (Migrated from github.com)

For debugging purposes, it would be nice if (let (foo (lambda (x) x)) ...) would create a function for which ##procedure-name would return foo rather than #f.

See how they do it in Racket:
https://docs.racket-lang.org/reference/syntax-model.html#%28part._infernames%29

For debugging purposes, it would be nice if `(let (foo (lambda (x) x)) ...)` would create a function for which `##procedure-name` would return `foo` rather than `#f`. See how they do it in Racket: https://docs.racket-lang.org/reference/syntax-model.html#%28part._infernames%29
fare commented 2020-06-24 00:58:47 +00:00 (Migrated from github.com)

My workaround:

;; In rec, the name is bound in the body of the lambda
(defrule (rec (name . formals) body ...)
  (let () (def (name . formals) body ...) name))

;; In fn, the name is NOT bound in the body of the lambda
(defsyntax (fun stx)
  (syntax-case stx ()
    ((_ (name . formals) body ...)
     (with-syntax ((n (datum->syntax #'stx (string->uninterned-symbol (symbol->string (syntax-e #'name))))))
       #'(let () (def (n . formals) body ...) n)))))
My workaround: ``` ;; In rec, the name is bound in the body of the lambda (defrule (rec (name . formals) body ...) (let () (def (name . formals) body ...) name)) ;; In fn, the name is NOT bound in the body of the lambda (defsyntax (fun stx) (syntax-case stx () ((_ (name . formals) body ...) (with-syntax ((n (datum->syntax #'stx (string->uninterned-symbol (symbol->string (syntax-e #'name)))))) #'(let () (def (n . formals) body ...) n))))) ```
vyzo commented 2020-06-24 07:17:06 +00:00 (Migrated from github.com)

I am not convinced this can work reliably, only top-level procedures have names in gambit afaik.

I am not convinced this can work reliably, only top-level procedures have names in gambit afaik.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mighty-gerbils/gerbil#551
No description provided.