From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zelphir Kaltstahl Newsgroups: gmane.lisp.guile.user Subject: Weird cache issue Date: Tue, 15 Mar 2022 17:54:19 +0000 Message-ID: <857fc700-4ac5-fa7b-1306-cccda26f0d58@posteo.de> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38184"; mail-complaints-to="usenet@ciao.gmane.io" To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Mar 15 18:55:45 2022 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 1nUBOa-0009gq-Ng for guile-user@m.gmane-mx.org; Tue, 15 Mar 2022 18:55:44 +0100 Original-Received: from localhost ([::1]:43398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nUBOZ-0004Ds-BS for guile-user@m.gmane-mx.org; Tue, 15 Mar 2022 13:55:43 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:44874) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nUBNM-000366-I4 for guile-user@gnu.org; Tue, 15 Mar 2022 13:54:28 -0400 Original-Received: from mout01.posteo.de ([185.67.36.65]:59117) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nUBNI-0006ZM-D2 for guile-user@gnu.org; Tue, 15 Mar 2022 13:54:28 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id D3C4F240027 for ; Tue, 15 Mar 2022 18:54:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.de; s=2017; t=1647366860; bh=LAECneSIQk5pZgy04JIs1ua62LKMCpfv4oKfkwF/8+o=; h=Date:To:From:Subject:From; b=nAWIzX9R32VNlbm8DQFiK+Zbbj3pW83rJSlnNKpPGlZZczzmf5D0axmQ7D/Zvf0mL Nfh7iuPbxFNn2MoF8G5qjwVrc+9xInXE7MZ1NHA/9DP+Q36Eclc+V0PO3kjFD1sZxd q/P9BPk2WMmlFm+Kpu728vKAf6y6EG3frbdQVY7j9/wwETyakIFkFM3LCW+B23+rzF sXw6FVHts7nz357AaVBB2r3PqsN8UdcXYVcBQWQ4POmrWbyHXIF1gdN2SVR72KeSce xlIwsWWGf4IMQI9p9YO4nt8yl+KtCZymOaxAWfrX/2XZkZ0mKPo2u362hDhY9++R5N IW3VAXrtHSEtQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4KJ1Hw13sKz6tmb for ; Tue, 15 Mar 2022 18:54:19 +0100 (CET) Content-Language: en-US Received-SPF: pass client-ip=185.67.36.65; envelope-from=zelphirkaltstahl@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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 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:18210 Archived-At: Hello Guile users! I have a weird cache issue: I have a directory, where I have the following files: "fileio.scm" and "013.scm". The following shows the contents of the files: ~~~~fileio.scm~~~~ (library (fileio) (export get-string-from-file get-lines-from-file get-lines-from-port get-lines-from-file-using-splitting put-lines-to-file put-string-to-file) (import (except (rnrs base) let-values map) (only (guile) lambda* λ ;; file io call-with-input-file call-with-output-file set-port-encoding! eof-object? ;; strings string-split string-join) (ice-9 textual-ports) ; for textual reading and writing procedures (ice-9 binary-ports) ; not sure if needed (ice-9 rdelim) ; for `eof-object?` (ice-9 optargs) ; for keyword arguments (srfi srfi-1))) ; not sure if needed (define get-string-from-file (lambda* (file-path #:key (encoding "UTF-8")) (call-with-input-file file-path (λ (port) (set-port-encoding! port encoding) (get-string-all port))))) (define get-lines-from-file (lambda* (file-path #:key (encoding "UTF-8")) ;; another common encoding is: "ISO-8859-1" ;; see http://www.iana.org/assignments/character-sets for more (define (get-lines-from-port port) (let ([line (get-line port)]) (cond [(eof-object? line) '()] [else (cons line (get-lines-from-port port))]))) (call-with-input-file file-path (λ (port) (set-port-encoding! port encoding) (get-lines-from-port port))))) (define get-lines-from-file-using-splitting (lambda* (file-path #:key (encoding "UTF-8")) (string-split (get-string-from-file file-path #:encoding encoding) ;; You could use simple character here, but I am using ;; lambda to show that it can be used as well. (λ (char) (char=? char #\newline))))) (define put-lines-to-file (lambda* (file-path lines #:key (encoding "UTF-8") (mode 'replace)) (call-with-output-file file-path (λ (port) (set-port-encoding! port encoding) (put-string port (cond [(eq? mode 'append) (string-append (get-string-from-file file-path #:encoding encoding) "\n" (string-join lines "\n"))] [(equal? mode 'replace) (string-join lines "\n")] [else (string-join lines "\n")])))))) (define put-string-to-file (lambda* (file-path string #:key (encoding "UTF-8") (mode 'replace)) (call-with-output-file file-path (λ (port) (set-port-encoding! port encoding) (put-string port (cond [(eq? mode 'append) (string-append (get-string-from-file file-path #:encoding encoding) "\n" string)] [(equal? mode 'replace) string] [else string])))))) ~~~~ And: ~~~~013.scm~~~~ (library (fileio) (export ) (import (except (rnrs base) let-values) (only (guile) lambda* λ ;; printing display simple-format) (fileio))) (define numbers (map string->number (get-lines-from-file "013-input.txt"))) (let* ([sum (apply + numbers)] [digits (substring (number->string sum) 0 10)]) (display (simple-format #f "first 10 digits: ~a\n" digits))) ~~~~ When I call: "guile -L . 013.scm" I get: ~~~~ $ guile -q -L . 013.scm ;;; note: source file /home/user/dev/guile/guile-project-euler-solutions/013.scm ;;; newer than compiled /home/user/.cache/guile/ccache/3.0-LE-8-4.6/home/user/dev/guile/guile-project-euler-solutions/013.scm.go ;;; note: auto-compilation is enabled, set GUILE_AUTO_COMPILE=0 ;;; or pass the --no-auto-compile argument to disable. ;;; compiling /home/user/dev/guile/guile-project-euler-solutions/013.scm ;;; compiled /home/user/.cache/guile/ccache/3.0-LE-8-4.6/home/user/dev/guile/guile-project-euler-solutions/013.scm.go first 10 digits: 5537376230 $ guile -q -L . 013.scm Backtrace: In ice-9/boot-9.scm: 1752:10 6 (with-exception-handler _ _ #:unwind? _ #:unwind-for-type _) In unknown file: 5 (apply-smob/0 #) In ice-9/boot-9.scm: 724:2 4 (call-with-prompt ("prompt") # …) In ice-9/eval.scm: 619:8 3 (_ #(#(#))) In ice-9/boot-9.scm: 2836:4 2 (save-module-excursion #) 4388:12 1 (_) In 013.scm: 123:8 0 (_) 013.scm:123:8: Unbound variable: get-lines-from-file ~~~~ So the first time I run the program, it works. The second time it does not. This is reproducible by clearing the cache and trying again: ~~~~ rm -rf /home/user/.cache/guile/ ~~~~ I found out, that this behavior disappears, when I fix the (library ...) expression in "013.scm" as follows: ~~~~013.scm~~~~ (import (except (rnrs base) let-values map) (only (guile) lambda* λ ;; printing display simple-format) (fileio)) (define numbers (map string->number (get-lines-from-file "013-input.txt"))) (let* ([sum (apply + numbers)] [digits (substring (number->string sum) 0 10)]) (display (simple-format #f "first 10 digits: ~a\n" digits))) ~~~~ So it does not stop me from making progress, but it is weird, that I don't get an error about the (library ...) expression and instead the program works once and then not a second time, unless I clear the cache. Is there a logic to this, or is it somehow a result of a conscious design decision? Regards, Zelphir -- repositories: https://notabug.org/ZelphirKaltstahl