[英]How to print the folowing to console in scheme r5rs language
(define x '())
x
in repl console gives => '()
在 repl 控制台中给出 => '()
(define x '())
(display x)
gives => ()
but I want to print it like '()
给出 => ()
但我想像'()
一样打印它
How can make display print '()
rather than ()
?如何使显示打印'()
而不是()
?
I need this because my function is logging the error incase of bad inputs provided by user and i want to print '()
input as '()
only, kinda like how scheme does when you run the following:我需要这个,因为我的函数正在记录用户提供的错误输入的错误,并且我只想将'()
输入打印为'()
,有点像运行以下命令时的方案:
(define x '())
(cdr x)
gives =>给 =>
mcdr: contract violation
expected: mpair?
given: '() (Note the ')
The code:编码:
(define x '())
(define y '(1 . 2))
x ; ==> ()
y ; ==> (1 . 2)
Thus evaluating x
in a Scheme REPL will show ()
since when you evaluate '()
it evaluates to the thing without the first '
.因此,在 Scheme REPL 中评估x
将显示()
因为当您评估'()
它评估的是没有第一个'
的东西。
In Racket they have configurable how the REPL is supposed to print values in the REPL / interactive window.在 Racket 中,他们可以配置 REPL 如何在 REPL/交互窗口中打印值。 In #lang racket
when you use display
you'll see what the value really is在#lang racket
当您使用display
您将看到真正的价值
(display x) ; prints ()
(display y) ; prints (1 . 2)
However in $lang r5rs
the default REPL with default settings output setting is print
:但是在$lang r5rs
中,默认设置输出设置的默认 REPL 是print
:
x ; ==> '()
y ; ==> (mcons 1 2)
With constructor
as output style:使用constructor
作为输出样式:
x ; ==> empty
y ; ==> (cons 1 2)
With quasiquote
as output style:使用quasiquote
作为输出样式:
x ; ==> `()
y ; ==> `(1 . 2)
All of the above doesn't really print the value.以上所有内容并没有真正打印出价值。 It prints an expression in the chosen style that, when evaluated, will become the same value.它以选定的样式打印一个表达式,在评估时将变为相同的值。 '()
, empty
, and `()
all evaluate to ()
so all of them are printed for the value you get when evaluating '()
'()
、 empty
和`()
都计算为()
因此所有这些都打印为您在计算'()
时获得的值
The only sensible choice is to use write
as output style.唯一明智的选择是使用write
作为输出样式。 This will print the real value in the REPL in the same manner as all other scheme implementations:这将以与所有其他方案实现相同的方式在 REPL 中打印实际值:
x ; ==> ()
y ; ==> (1 . 2)
(format "'%s" '())
scheme ia中的输出语法和输入语法不一样,需要自己创建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.