From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Holger Peters Newsgroups: gmane.lisp.guile.devel Subject: [PATCH] Use make-default-environment setting in REPL for specifying languages Date: Fri, 20 Nov 2020 14:24:43 +0100 Message-ID: <20201120132443.14802-1-holger.peters@posteo.de> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17640"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Holger Peters To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Nov 20 14:25:01 2020 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kg6PM-0004SH-8j for guile-devel@m.gmane-mx.org; Fri, 20 Nov 2020 14:25:00 +0100 Original-Received: from localhost ([::1]:55186 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kg6PL-0000fO-Bc for guile-devel@m.gmane-mx.org; Fri, 20 Nov 2020 08:24:59 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33286) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kg6PB-0000fD-B0 for guile-devel@gnu.org; Fri, 20 Nov 2020 08:24:49 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:41359) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kg6P9-0006bX-58 for guile-devel@gnu.org; Fri, 20 Nov 2020 08:24:49 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id 1C1E5160063 for ; Fri, 20 Nov 2020 14:24:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1605878685; bh=6QRJDKhtgd6AoTaUo7fFina9FYd4tpkPGY8Dmf8LZJg=; h=From:To:Cc:Subject:Date:From; b=TKvpgsIN8Uz+emIF7oWOA0W4XYuSKoTEb8LHO/XTp5KaNI0/3I/akCiA88CQePvgz A6G9nj0e1K0a1sh1aLl3JgK+VylGVoRlK10aC9BpjpDUMxefhOjPl1hzApIDjT+B1d U9E5epN/cW2+5FTYlnE3MH5axKC3mjKhjcFH2ck75yaLF6Tt2rO7wWOld1wZtDqiGA hxy/j1tapcyGhkrQeLxhN42PTH811yrEky5KJxIfslhmpnN8pVdr3JfuCYz+zRBag2 cwFpEho0ep1Y2DectyqEq0eKg5/a/qtx1kXdA8f2HgVnKx1OelaAW9MjVYkcQKg0YY m3NIdgbBuKb4A== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4Ccy2N5FQFz9rxK; Fri, 20 Nov 2020 14:24:44 +0100 (CET) X-Mailer: git-send-email 2.28.0 Received-SPF: pass client-ip=185.67.36.65; envelope-from=holger.peters@posteo.de; helo=mout01.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:20612 Archived-At: 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