Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;; Causes horrible recursion
- (define (nm-test-bad terms)
- (cond ((string? (car terms))
- (display (format #f "~s" terms)))
- ((list? (car terms))
- (nm-test '((caar terms) . (cdr terms)))
- (unless (null? (cdar terms))
- (nm-test '((cdar terms) . (cdr terms)))))))
- ;; Quasi quote works
- (define (nm-test-quasi terms)
- (cond ((string? (car terms))
- (display (format #f "~s" terms)))
- ((list? (car terms))
- (nm-test `(,(caar terms) . ,(cdr terms)))
- (unless (null? (cdar terms))
- (nm-test `(,(cdar terms) . ,(cdr terms)))))))
- ;; Cons procedure works and is less confusing
- (define (nm-test terms)
- (cond ((string? (car terms))
- (display (format #f "~s" terms)))
- ((list? (car terms))
- (nm-test (cons (caar terms) (cdr terms)))
- (unless (null? (cdar terms))
- (nm-test (cons (cdar terms) (cdr terms)))))))
- (nm-test '(("tom" "dick") . "harry")))
- (nm-test '("tom" . "harry"))
Add Comment
Please, Sign In to add comment