emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/geiser-guile b20a784 010/284: Better arg lists.


From: Philip Kaludercic
Subject: [nongnu] elpa/geiser-guile b20a784 010/284: Better arg lists.
Date: Sun, 1 Aug 2021 18:29:06 -0400 (EDT)

branch: elpa/geiser-guile
commit b20a784d45ac741443e2a2ed6f81178aab93ea63
Author: Jose Antonio Ortega Ruiz <jao@gnu.org>
Commit: Jose Antonio Ortega Ruiz <jao@gnu.org>

    Better arg lists.
---
 geiser/introspection.scm | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/geiser/introspection.scm b/geiser/introspection.scm
index 7fce4c9..38c0b79 100644
--- a/geiser/introspection.scm
+++ b/geiser/introspection.scm
@@ -30,6 +30,9 @@
   #:use-module (ice-9 session)
   #:use-module (srfi srfi-1))
 
+(define (proc-args proc)
+  (obj-args (resolve-symbol proc)))
+
 (define (resolve-symbol sym)
   (and (symbol? sym)
        (module-bound? (current-module) sym)
@@ -52,15 +55,25 @@
                  (program-module program))))
 
 (define (procedure-args proc)
-  (let* ((arity (procedure-property proc 'arity))
-         (req (first arity))
-         (opt (third arity))
-         (env (procedure-environment proc)))
-    (format-args (map (lambda (n)
-                        (string->symbol (format "arg~A" (+ 1 n))))
-                      (iota req))
-                 (and opt 'rest)
-                 (and (not (null? env)) env))))
+  (let ((name (procedure-name proc)))
+    (cond ((procedure-source proc) => (lambda (src)
+                                        (procedure-args-from-source name src)))
+          (else (let* ((arity (procedure-property proc 'arity))
+                       (req (first arity))
+                       (opt (third arity)))
+                  (format-args (map (lambda (n)
+                                      (string->symbol (format "arg~A" (+ 1 
n))))
+                                    (iota req))
+                               (and opt 'rest)
+                               (and name (symbol-module name))))))))
+
+(define (procedure-args-from-source name src)
+  (let ((formals (cadr src)))
+    (cond ((list? formals) (format-args formals #f (symbol-module name)))
+          ((pair? formals) (format-args (car formals)
+                                        (cdr formals)
+                                        (symbol-module name)))
+          (else '()))))
 
 (define (macro-args macro)
   (let ((prog (macro-transformer macro)))
@@ -71,10 +84,9 @@
 (define (format-args args opt module)
   (list (cons 'required args)
         (cons 'optional (or opt '()))
-        (cons 'module (if module (module-name module) '()))))
-
-(define (proc-args proc)
-  (obj-args (resolve-symbol proc)))
+        (cons 'module (cond ((module? module) (module-name module))
+                            ((list? module) module)
+                            (else '())))))
 
 (define (completions prefix)
   (sort! (map symbol->string



reply via email to

[Prev in Thread] Current Thread [Next in Thread]