Article View: comp.lang.misc
Article #3588Re: Who or What is Scheme?
From: Ken Dickey
Date: Wed, 17 Apr 1991 19:50
Date: Wed, 17 Apr 1991 19:50
100 lines
3524 bytes
3524 bytes
ajayshah@alhena.usc.edu (Ajay Shah) writes:
>I came across Scheme recently. Does someone have a quick summary on
>where it fits into the Universe?
From the IEEE draft standard (P1178/D4):
Programming languages should not be designed by piling feature upon
feature, but by removing the weaknesses and restrictions that make
additional features appear necessary.
Scheme is a small, elegant language which inherits from both Algol and
Lisp language families.
Scheme is lexically scoped (Algol style block structured scoping).
Scheme has "typed values" as opposed to "typed variables" (Lisp style
`dynamic' typing).
The language is extremely regular. All data objects including
procedures and continuations have "first class" status in that they
can be stored in variables, passed as parameters, returned as results,
don't have to be named, etc.
The syntax is trivial (s-expressions). Scheme uses the same rules of
evaluation for operators as for operands. E.g.:
((if (foo? x) + *) 32 X 37)
{i.e. if foo?(X) is true, apply '+' to arguments 32, X, and 37, else
apply '*' to them. The outer operator is returned by the IF statement}
Scheme directly sypports imperative, functional, and object based
programming styles. Doing a full object-system with multiple
inheritance, etc. on top of raw Scheme is about 8-12 pages of code.
Numbers are a unified tower of types. An integer is a rational is a
real is a complex.
Data types include boolean, list, vector, string, character, symbol,
procedure, and number.
Scheme is "properly tail recursive", which means that `tail-recursive'
loops are iterative--they execute in constant space. Procedure calls
are essentially gotos, so no special iteration constructs are
required--loops are expressed directly using procedure call semantics.
Again, Scheme is a very small language. The programming language
report is about 50 pages.
;;======================================================================
;; A couple of quick examples:
; Recursive factorial
(define (FACTORIAL N)
(if (< n 2)
1
(* n (factorial (- n 1)))))
; 'Continuation-passing' factorial -- also recursive
(define (FACTORIAL N)
(define (cfact n k) ; internal procedure -- k is a function
(if (< n 2)
(k 1)
(cfact (- n 1)
(lambda (value) (k (* n value)))) ; generate a new function..
) ) ; which tells us what..
; to do with the..
; result when we get it.
; body
(cfact n (lambda (any) any)) ; start things off with the identity function
)
; Iterative factorial
(define (FACTORIAL N)
(define (fact n result) ; internal procedure
(if (< n 2)
result
(fact (- n 1) (* n result))) ;; this is a loop
)
; body
(fact n 1)
)
; Iterative factorial -- another way of writing the above
(define (FACTORIAL N)
(let loop ( (n N) (result 1) )
(if (< n 2)
result
(loop (- n 1) (* n result))
) ) )
;;----------------------------E-O-F---------------------------------;;
Technical Details
Message-ID:
<477@data.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!psuvax1!rutgers!mit-eddie!uw-beaver!milton!ogicse!intelhf!agora!parsely!percy!data!kendReferences:
<32012@usc>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!psuvax1!rutgers!mit-eddie!uw-beaver!milton!ogicse!intelhf!agora!parsely!percy!data!kend From: kend@data.UUCP (Ken Dickey) Newsgroups: comp.lang.misc Subject: Re: Who or What is Scheme? Message-ID: <477@data.UUCP> Date: 17 Apr 91 19:50:22 GMT References: <32012@usc> Organization: Microcosm, Beaverton, OR Lines: 100