关于点“."在计划中 [英] about the dot "." in scheme

查看:44
本文介绍了关于点“."在计划中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到有其他问题关于点."我跟着,但它对我的代码不起作用....它是代码的一部分,实现并不集中在这个符号上.但输出应该包括这个点.当我输入两个列表 '(1 2 3) '(4 5)我的预期输出 => (1 . 4) (2 . 5)

I saw there are other questions about the dot "." I followed but it didn't work for my code.... it's a part of code, the implementation is not focused to this symbol. but output should be included this dot. when I give input of two lists '(1 2 3) '(4 5) my expected output => (1 . 4) (2 . 5)

我设法得到 (1 4) (2 5)只需要加上."在中间.

I managed to get (1 4) (2 5) just need to add "." in the middle.

Part of mycode 
(cons (list (car lst1) (car lst2))
....

对于."符号,如果我尝试

for the "." symbol , if I try

**trial-1**
 (cons '(list (car lst1) (car lst2)) ...)

然后输出:((list (car lst1) (car lst2))

then the output : ((list (car lst1) (car lst2))

**trail-2**
(cons (list (car lst1) '. (car lst2)) ...)

然后..它说:非法使用`.'

then.. it says : illegal use of `.'

使用点的规则是什么?我可以查看任何文件吗?顺便说一句,我正在使用球拍(R5RS).

what are the rules to use the dot? any documents I can look at? btw, I am using Racket(R5RS).

推荐答案

当您构建 cons-pairlist<时,会显示点符号/em> 不是 proper (意思是:它不以空列表结尾).例如:

The dot symbol is displayed when you build a cons-pair or a list which is not proper (meaning: it doesn't end with the empty list). For example:

(cons 1 2) 
=> (1 . 2) ; a cons-pair

(cons 1 (cons 2 (cons 3 4)))
=> '(1 2 3 . 4) ; an improper list

例如,要显示问题中显示的输出,请尝试以下操作:

For instance, to display an output such as the one shown in the question try this:

(define lst1 '(1 2 3))
(define lst2 '(4 5))

(list (cons (car lst1) (car lst2))
      (cons (cadr lst1) (cadr lst2)))

=> '((1 . 4) (2 . 5))

这篇关于关于点“."在计划中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆