From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: holger.peters@posteo.de Newsgroups: gmane.lisp.guile.user Subject: Namespace confusion/pollution in languages implemented via Guile's compile-tower Date: Sat, 07 Nov 2020 12:54:56 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40889"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Posteo Webmail To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Nov 07 12:55:22 2020 Return-path: Envelope-to: guile-user@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 1kbMoT-000AWZ-6a for guile-user@m.gmane-mx.org; Sat, 07 Nov 2020 12:55:21 +0100 Original-Received: from localhost ([::1]:55488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbMoS-0002HG-85 for guile-user@m.gmane-mx.org; Sat, 07 Nov 2020 06:55:20 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45946) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbMoG-0002H7-3g for guile-user@gnu.org; Sat, 07 Nov 2020 06:55:08 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:49428) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbMoD-0000ri-Lq for guile-user@gnu.org; Sat, 07 Nov 2020 06:55:07 -0500 Original-Received: from submission (posteo.de [89.146.220.130]) by mout01.posteo.de (Postfix) with ESMTPS id C9C2A160062 for ; Sat, 7 Nov 2020 12:54:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1604750096; bh=33+LgSt1Ybi+1Ys3iPy82+c8FDcLzqCdzZY/fB1+Bnw=; h=Date:From:To:Subject:From; b=MfhrtHzFTRwKg1eRAJbBrFXSk+95c/YcUfzLoeATwYABhtXhZKLelBQWXtFyanmO5 YzP0Tfam9yLw9aF049SQDPlwJNc7QIzaBQRB9Y52BYbiG5MysLoxeObN8dWSkeKqTD h4DMfXsCyKukrVhROPN+EbDD3RCErjSg6V8cTrxOdaYPwluByOXMD4glifWGwNQNNT 2u9jS25jam5Jlyz1coRg/UiodfJlS8xq8BafxjNNBY8oIDEnTb9wd5QKb/LgLzslsk u39hkb/atvqwBiZXSAdiCMB5Nm7tqpLh8d44lsdR9AomuamY/Sl82AabvD7jsAcDD7 6/otQ7PngI4tg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4CSwfm2mk3z6tmw for ; Sat, 7 Nov 2020 12:54:56 +0100 (CET) X-Sender: holger.peters@posteo.de Received-SPF: pass client-ip=185.67.36.65; envelope-from=holger.peters@posteo.de; helo=mout01.posteo.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/07 06:54:57 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] 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-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17006 Archived-At: First of all let me begin by saying I am not quite sure whether this is a `works as intended' or whether this constitutes a bug, I tend to think its the latter, but wouldn't right away rule out the former, as if it were to be considered a `bug' it probably would have surfaced long before, but I disgress. let's get to my problem. * Problem statement I implemented my own language using the guile compile-tower. For the sake of you not having to read through all of my code I provide a snippet for reproducing the test case. But first, let's start by looking at the fact what I describe is present in the ecmascript iplementation bundled with guile. If you run Guile's ECMAscript REPL using `guile --language=ecmascript`, something like this works: write("test"); display(3); newline(); Haven't looked into the ECMAscript standard but I don't think Scheme's `write', `display' and `newline' are whats being demonstrated there. * Reproducing Example This creates a lang `fakescheme', that is actually identical to `(language scheme spec)' for all items except, that there are far fewer builtins (just `print' instead of `write'). (define-module (language fakescheme spec) #:use-module (system base compile) #:use-module (system base language) #:use-module (language scheme compile-tree-il) #:use-module (language scheme decompile-tree-il) #:export (fakescheme)) (define (make-fresh-module) (let ((m (make-module))) (module-define! m 'current-reader (make-fluid)) (module-set! m 'format simple-format) (module-define! m 'newline newline) (module-define! m 'print write) (module-define! m 'current-module current-module) m)) (define-language fakescheme #:title "fakescheme" #:reader (lambda (port env) ((or (and=> (and=> (module-variable env 'current-reader) variable-ref) fluid-ref) read) port)) #:compilers `((tree-il . ,compile-tree-il)) #:decompilers `((tree-il . ,decompile-tree-il)) #:evaluator (lambda (x module) (primitive-eval x)) #:printer write #:make-default-environment make-fresh-module) The general observation is: If I run a some script using this language using `guile --language=fakescheme -s myscript.scm', it works as expected, i.e. the following works (print "foo") ; works in script (write "foo") ; fails in script However, if I run the same code from within a repl via `guile --language=fakescheme', (print "foo") ; fails in repl (write "foo") ; works in repl * Whats going on here? It seems that in the REPL, Guile injects the `guile-user' module directly whereas when called with `-s` and a script guile uses the module provided with `#:make-default-environment'. That seems strange because overall I would expect REPL environments and non-REPL environments to be roughly the same. So, is this a bug? Works as intended? And if this is intended in this way is there a workaround to make REPL and script exeution to behave the same (preferably without namespace `pollution').