Computer Science- Primitives Flashcards
(20 cards)
(max a b)
accepts numeric inputs a, b and returns the greater of the two
(abs a)
accepts numeric input a and returns the absolute value
(quotient a b)
returns whole number part of a/b
(remainder a b)
returns remainder a b
(time (fxn call))
- evaluates (fxn call), then returns the time in ms required to evaluate (fxn call)
- must switch to INTERMEDIATE LANGUAGE
(begin
…)
executes tasks in order
(display a)
- displays contents of a
- ex (define a 42)
(display a) –> 42
(display ‘a)
a
(display “text”)
text
(newline) or “\n”
inserts a carriage return or newline
(null? L)
- # t if L is an empty set [’( )], #f otherwise
- language must be FULL SWINDLE
(list? L)
returns #t if L is a list, #f otherwise
(length L)
of cells on top in a con cell diagram
(equal? L)
- # t if a and b are equal, #f otherwise
- unlike (= a b), this can compare LISTS
(cons a b)
- returns a list with a as its CAR part and b as its CDR part
- b should be a list
- (cons 1 2 3) –> error
- (cons 1 ‘(2 3)) –> ‘(1 2 3)
- (cons ‘(1) ‘(2 3)) –> ((1) 2 3)
- essential to maintaining list structure in handling sublists
(append a b)
- combines list a and b into a single list
- both have to be a list
- (append 1 2 3) –> error
- (append 1 ‘(2 3)) –> error
- (append ‘(1) ‘(2 3)) –> (1 2 3)
(list …)
- returns a list comprised of args 1 through n in order
- (list 1 2 3) –> ‘(1 2 3)
- (list 1 ‘(2 3)) –> ‘(1 (2 3))
- (list ‘(1) ‘(2 3)) –> ‘((1) (2 3))
(number? a)
t if a is numeric, #f otherwise
(cadr L)
(car (cdr L))
(random n)
returns a random integer on interval [0, n) or [o, n-1]