Type detection: Difference between revisions

Content added Content deleted
Line 1,418: Line 1,418:


}</lang>
}</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}}==
=={{header|Smalltalk}}==