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)
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)) ...)
then the output : ((list (car lst1) (car lst2))
**trail-2**
(cons (list (car lst1) '. (car lst2)) ...)
then.. it says : illegal use of `.'
what are the rules to use the dot? any documents I can look at? btw, I am using Racket(R5RS).
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))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With