unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* [PATCH] Use make-default-environment setting in REPL for specifying languages
@ 2020-11-20 13:24 Holger Peters
  0 siblings, 0 replies; only message in thread
From: Holger Peters @ 2020-11-20 13:24 UTC (permalink / raw)
  To: guile-devel; +Cc: Holger Peters

Context: When executing code via `guile --language LANG -s', Guile
initialises a module according to the `make-default-environment' field
of the language definition.  However, execution of the guile REPL via
`guile --language=LANG' for these languages shows different behaviour:
it uses the `guile-user' environment instead. This means that

(a) builtin bindings in a given language are inaccessible in the REPL
    when they were available during script-execution and
(b) scheme bindings are present in the REPL while they weren't
    declared to be part of the implemented language's environment.

This patch fixes this behaviour for languages, that do not change the
`make-default-environment' field and are not Scheme.  Incidentally,
this means that guile-user is continued to be loaded for `elisp' and
`ecmascript', since for those languages `make-default-environment' is
not overwritten..

* module/ice-9/top-repl.scm (top-repl): Use `make-default-environment'
  if it isn't the default value of the language record.
  (initial-repl-module) New auxiliary procedure.
---
 module/ice-9/top-repl.scm | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/module/ice-9/top-repl.scm b/module/ice-9/top-repl.scm
index fa26e61e7..613fb4498 100644
--- a/module/ice-9/top-repl.scm
+++ b/module/ice-9/top-repl.scm
@@ -20,6 +20,10 @@
 (define-module (ice-9 top-repl)
   #:use-module (ice-9 top-repl)
   #:use-module ((system repl repl) #:select (start-repl))
+  #:use-module ((system base language)
+                #:select (lookup-language
+                          default-environment
+                          language-make-default-environment))
 
   ;; #:replace, as with deprecated code enabled these will be in the root env
   #:replace (top-repl))
@@ -44,13 +48,26 @@
                   ;; restore original C handler.
                   (sigaction SIGINT #f))))))))
 
-(define (top-repl)
-  (let ((guile-user-module (resolve-module '(guile-user))))
 
+
+(define (initial-repl-module)
+  "Returns the module to be used in the REPL, `guile-user' for scheme or
+if the language doesn't overwrite @var{make-default-environment}, if it
+overwrites this field in the language spec, it loads the module
+specified by @var{make-default-environment}."
+  (let* ((lang (lookup-language (current-language)))
+         (make-default-env (language-make-default-environment lang)))
+    (if (or (eq? (current-language) 'scheme)
+            (eq? make-default-env make-fresh-user-module))
+      (resolve-module '(guile-user))
+      (default-environment (current-language)))))
+
+(define (top-repl)
+  (let ((guile-user-module (initial-repl-module)))
     ;; Use some convenient modules (in reverse order)
 
     (set-current-module guile-user-module)
-    (process-use-modules 
+    (process-use-modules
      (append
       '(((ice-9 session)))
       (if (provided? 'regex)
-- 
2.28.0




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-11-20 13:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-20 13:24 [PATCH] Use make-default-environment setting in REPL for specifying languages Holger Peters

unofficial mirror of guile-devel@gnu.org 

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/guile-devel/0 guile-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 guile-devel guile-devel/ https://yhetil.org/guile-devel \
		guile-devel@gnu.org
	public-inbox-index guile-devel

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.lisp.guile.devel
	nntp://news.gmane.io/gmane.lisp.guile.devel


AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git