about summary refs log tree commit diff stats
path: root/screen.mu
blob: b1e4e5b4ccce5af09f68084329c45daeb2e188c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# example program: managing the display using 'screen' objects
#
# The zero screen below means 'use the real screen'. Tests can also use fake
# screens.

recipe main [
  open-console
  print-character 0/screen, 97/a, 2/red
  1:number/raw, 2:number/raw <- cursor-position 0/screen
  wait-for-event 0/console
  clear-screen 0/screen
  move-cursor 0/screen, 0/row, 4/column
  print-character 0/screen, 98/b
  wait-for-event 0/console
  move-cursor 0/screen, 0/row, 0/column
  clear-line 0/screen
  wait-for-event 0/console
  cursor-down 0/screen
  wait-for-event 0/console
  cursor-right 0/screen
  wait-for-event 0/console
  cursor-left 0/screen
  wait-for-event 0/console
  cursor-up 0/screen
  wait-for-event 0/console
  close-console
]
und-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# example program: constructing recipes out of order
#
# We construct a factorial function with separate base and recursive cases.
# Compare factorial.mu.
#
# This isn't a very tasteful example, just a simple demonstration of
# possibilities.

recipe factorial [
  local-scope
  n:number <- next-ingredient
  {
    +base-case
  }
  +recursive-case
]

after +base-case [
  # if n=0 return 1
  zero?:boolean <- equal n, 0
  break-unless zero?
  reply 1
]

after +recursive-case [
  # return n * factorial(n - 1)
  x:number <- subtract n, 1
  subresult:number <- factorial x
  result:number <- multiply subresult, n
  reply result
]

recipe main [
  1:number <- factorial 5
  $print [result: ], 1:number, [
]
]