Type detection: Difference between revisions

Line 1,418:
 
}</lang>
 
=={{header|Scheme}}==
<lang scheme>(define (print-text source)
(cond ((string? source)
;; The source is a string.
(display source))
 
((and (list? source)
(or (null? source) (string? (car source))))
;; The source is a list of strings.
(for-each (lambda (s) (display s)) source))
 
((input-port? source)
;; The source is a file or similar.
(do ((s (read-line source) (read-line source)))
((eof-object? s))
(display s)
(newline)))))
 
(print-text "Print me.\n")
 
(print-text '("Print\n" "a list\n" "of strings.\n"))
 
(call-with-input-file "type_detection-scheme.scm" print-text)</lang>
 
{{out}}
Using CHICKEN 5 as an R7RS Scheme compiler.
 
$ csc -R r7rs type_detection-scheme.scm && ./type_detection-scheme
<pre>Print me.
Print
a list
of strings.
(define (print-text source)
(cond ((string? source)
;; The source is a string.
(display source))
 
((and (list? source)
(or (null? source) (string? (car source))))
;; The source is a list of strings.
(for-each (lambda (s) (display s)) source))
 
((input-port? source)
;; The source is a file or similar.
(do ((s (read-line source) (read-line source)))
((eof-object? s))
(display s)
(newline)))))
 
(print-text "Print me.\n")
 
(print-text '("Print\n" "a list\n" "of strings.\n"))
 
(call-with-input-file "type_detection-scheme.scm" print-text)</pre>
 
=={{header|Smalltalk}}==
1,448

edits