scheme - 在程序 scm_lreadr: #:1:42: 字符串常量中的文件结尾
问题描述
我正在使用 guile/scheme 编写测试代码,我尝试将文本文件的每一行提取为字符串并用于(eval-string str)
评估字符串中的表达式。但是,我得到In procedure scm_lreadr: #<unknown port>:1:42: end of file in string constant
错误。那么,如何#<eof>
从我要评估的字符串的末尾删除文件对象的末尾(eval-string str)
。这是示例代码
(define (test-func)
(call-with-input-file "tests.txt"
(lambda (port)
(while #t
(let ((line (get-line port)))
(if (eof-object? line) (break))
(set! line (string-trim line))
(display (format #f "-> ~a\n"line))
(set! line (string-trim (substring line 1)))
(display (format #f "~a\n" line))
(eval-string line)
)))))
解决方案
推荐阅读
- c# - 通过输入中的给定分隔符将数据表转换为 .xls、.xlsx、.csv
- .net - 如何确定此 .NET 对象是否为 int?
- c - 在这个 C90 未定义的行为定义中,“有符号或无符号类型”是什么意思?
- react-native - React Native:自定义文本组件未在 Android 中呈现(在 iOS 上运行良好)
- php - 将动态 PHP/SQL 动态子菜单与 CSS 集成
- asp.net-core-webapi - 无法访问我发布到 IIS(本地)的 API
- concurrency - Java 11 HttpClient Http2 流太多错误
- javascript - 如何使用对象作为构造函数?
- imacros - 如何评估 imacros 以提取链接上的 id?
- java - 如何从 Java 中的一维数组矩阵中删除一列?