Impcore variable definition Example (val n 99) Compare int n = - - PowerPoint PPT Presentation

impcore variable definition
SMART_READER_LITE
LIVE PREVIEW

Impcore variable definition Example (val n 99) Compare int n = - - PowerPoint PPT Presentation

Impcore variable definition Example (val n 99) Compare int n = 99; Also, expressions at top level (definition of it ) Impcore expressions No statements means expression-oriented: (if e1 e2 e3) (while e1 e2) (set x e) (begin e1 ... en) (f


slide-1
SLIDE 1

Impcore variable definition

Example (val n 99) Compare int n = 99; Also, expressions at top level (definition of it)

slide-2
SLIDE 2

Impcore expressions

No statements means expression-oriented: (if e1 e2 e3) (while e1 e2) (set x e) (begin e1 ... en) (f e1 ... en) Each one has a value and may have side effects! Functions are primitive (+ - * / = < > print)

  • r defined with (define f ...).

The only type of data is “machine integer” (deliberate oversimplification)

slide-3
SLIDE 3

Names known in “environments”

Ways to talk about meanings of names:

  • Scope rules
  • Name spaces
  • Environments (aka symbol tables)

Impcore vars in 2 environments: globals, formals There are no local variables

  • Just like awk; if you need temps, use extra

formal parameters

  • For homework, you’ll add local variables

Functions live in their own environment (not shared with variables)

slide-4
SLIDE 4

Environmental abuse

Abuse of separate name spaces:

  • > (val f 33)

33

  • > (define f (x) (+ x x))

f

  • > (f f)

66