unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Holger Peters <holger.peters@posteo.de>
To: guile-devel@gnu.org
Cc: Holger Peters <holger.peters@posteo.de>
Subject: [PATCH] Use make-default-environment setting in REPL for specifying languages
Date: Fri, 20 Nov 2020 14:24:43 +0100	[thread overview]
Message-ID: <20201120132443.14802-1-holger.peters@posteo.de> (raw)

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




                 reply	other threads:[~2020-11-20 13:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201120132443.14802-1-holger.peters@posteo.de \
    --to=holger.peters@posteo.de \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).