(define pi (*4 (atan1)))(define circum (lambda (r) (*2 pi r)))(circum 5)
SCHEME
(import (srfi 48))(format #t"1+2=~s\n" (+12))
SCHEME
(import (srfi 19)) ;; for time procedures(import (srfi 48)) ;; for format(define(get-date) (time-utc->date (current-time time-utc)))(format #t"current UTC time: ~a\n" (date->string (get-date)))
Types
SCHEME
(string-append"A""BC")
SCHEME
(string-ref"XYZ"2) ;; indexing
SCHEME
(string-length"AB") ;; get length
SCHEME
(char->integer#\A) ;; conversion
SCHEME
(char<?#\A#\Z) ;; comparison
SCHEME
(expt275) ;; 2^75
SCHEME
(exp (*75 (log2))) ;; e^(75*ln(2))
SCHEME
(* (/53) (/92)) ;; 5/3 * 9/2
SCHEME
(+ (sqrt -6.25) 1) ;; sqrt(-6.25)+1
SCHEME
(>1e-21) ;; 0.01 > 1 ?
SCHEME
(define lst (list12))lst
SCHEME
(cons0 lst) ;; add to front
SCHEME
(append lst '(34)) ;; concatenation
SCHEME
(car lst) ;; get first
SCHEME
(cdr lst) ;; remove first
SCHEME
(cdr (cdr lst)) ;; remove both
SCHEME
(length lst) ;; get length
SCHEME
(define v (make-vector542))v
SCHEME
(vector-set! v 2#t) ;; mutationv
SCHEME
(vector-ref v 2) ;; indexing
SCHEME
(vector-length v) ;; get length
Challenge 1: Can you do it?
What is the difference between a list and a vector in scheme?
Lists are not indexed, one accesses the first and last items of a
list. Vectors are indexed, any item can be accessed, but they are more
expensive to process. Scheme is a programming language in the lisp
family of programming languages (https://en.wikipedia.org/wiki/Lisp_(programming_language)),
which extensively use lists.
SCHEME
(string->symbol"foo") ;; conversion
SCHEME
(symbol->string 'foo) ;; conversion
SCHEME
(define x (list '* 237))x(eval x)
Challenge 2: Can you do it?
Define an s-expression that uses the symbol + in a list that adds
three numbers
SCHEME
(define y (list '+ 237))y(eval y)
SCHEME
*
SCHEME
(*237)
SCHEME
(apply * (list237))
Challenge 3: Can you do it?
check if + is a procedure. Use + to add three numbers in a list.
SCHEME
+(apply + (list237))
Key Points
Scheme is a programming language that uses lists
Scheme can be used to create very powerful compact programs
Scheme has specifications which if implemented can be imported to
give additional functionality such as formatted output
Symbols can be used to create s-expressions that allow one to define
and evaluate in separate steps