Computer Science- Primitives Flashcards

(20 cards)

1
Q

(max a b)

A

accepts numeric inputs a, b and returns the greater of the two

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

(abs a)

A

accepts numeric input a and returns the absolute value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

(quotient a b)

A

returns whole number part of a/b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

(remainder a b)

A

returns remainder a b

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

(time (fxn call))

A
  • evaluates (fxn call), then returns the time in ms required to evaluate (fxn call)
  • must switch to INTERMEDIATE LANGUAGE
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

(begin

…)

A

executes tasks in order

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

(display a)

A
  • displays contents of a
  • ex (define a 42)
    (display a) –> 42
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

(display ‘a)

A

a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

(display “text”)

A

text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

(newline) or “\n”

A

inserts a carriage return or newline

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

(null? L)

A
  • # t if L is an empty set [’( )], #f otherwise

- language must be FULL SWINDLE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

(list? L)

A

returns #t if L is a list, #f otherwise

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

(length L)

A

of cells on top in a con cell diagram

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

(equal? L)

A
  • # t if a and b are equal, #f otherwise

- unlike (= a b), this can compare LISTS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

(cons a b)

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

(append a b)

A
  • 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)
17
Q

(list …)

A
  • 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))
18
Q

(number? a)

A

t if a is numeric, #f otherwise

19
Q

(cadr L)

A

(car (cdr L))

20
Q

(random n)

A

returns a random integer on interval [0, n) or [o, n-1]