Reputation: 1
I am trying to get the below output in scheme language. Could anybody let me know where am I wrong? I want to add .z
at the end, not getting it. How can I?
code:
(define (countup n)
(define (help i)
(if (<= i n)
(cons 's (help (+ i 1)))
'()))
(help 1 ) )
Input:
(countup 4)
desired output:
'(s s s s .z)
but coming output
'(s s s s)
Upvotes: 0
Views: 74
Reputation: 2540
As @molbdnilo mentioned, it has to with output style of proper (ie, null-terminated) vs improper lists.
#lang racket
(cons 's (cons 's (cons 's (cons 's 'z)))) ; => '(s s s s . z)
(cons 's (cons 's (cons 's (cons 's '())))) ; => '(s s s s)
(cons 's (cons 's (cons 's (cons 's (cons 'z '()))))) ; => '(s s s s z)
Upvotes: 1