Remix Intro
Remix Intro
Language
An introductory programming language
Robert Sheehan
1
Ideas
Readable
Self documenting
2
Also inspired by block
programming languages
One of the great things about block languages is that the verbal syntax is
very readable.
4
fi
Draw 36
circling arrows
Rotating Arrows.
================
5
Draw 36
circling arrows
Rotating Arrows.
================
6
Draw 36
circling arrows
7
Draw (n) circling arrows
8
Create an arrow
9
Create an arrow
an arrow shape :
a shape of (arrow-shape) with size 5
10
The arrow shape
a new arrow :
arrow : an arrow shape
a list of (n) arrows : set the (arrow) colour
arrow
make a list for the arrows
repeat (n) times an arrow shape :
arrow : a new arrow a shape of (arrow-shape) with size 5
position the arrow
add the arrow to the list arrow-shape : {
{ 0, 1}
return the list {-2, 2}
{ 0,-2}
{ 2, 2}
}
11
Creating all the arrows
a new arrow :
arrow : an arrow shape
a list of (n) arrows : set the (arrow) colour
arrow
arrows : an empty list
repeat (n) times an arrow shape :
arrow : a new arrow a shape of (arrow-shape) with size 5
position the arrow
add the (arrow) to (arrows) arrow-shape : {
{ 0, 1}
arrows {-2, 2}
{ 0,-2}
{ 2, 2}
}
12
Positioning all the arrows
13
What about the angle?
14
Animating the arrows
15
Animating the arrows
16
Animating the arrows
17
Animating the arrows
18
We need to draw it
19
Rotating Arrows.
================
on standard paper
show paper
========================================
arrow-shape : {
{ 0, 1}
{-2, 2}
{ 0,-2}
{ 2, 2}
}
a new arrow :
arrow : an arrow shape
set the (arrow) colour
arrow
an arrow shape :
a shape of (arrow-shape) with size 5
radius : 200
step : radius × π ÷ 180
turtles : 36 turtles
show paper
========================================
(n) turtles:
turtles : an empty list
repeat (n) times
new-turtle: based on (turtle)
new-turtle’s colour : random colour
move the (new-turtle) by (radius)
turn the (new-turtle) 90 degrees
add the (new-turtle) to (turtles)
turn 10 degrees
turtles
21
Other examples
Factorial
Fizz-buzz
Insertion sort
22
Other examples
Factorial
23
Other examples
Factorial
Fizz-buzz
Insertion sort
25
Other examples
Insertion Sort.
Factorial ===============
The rainfall problem array : {-1, -3, 0, 5, -2, 1.0, 0, -1, 6, 7, 999}
26
Another just for fun
Find the middle number.
=======================
n1 : get value
n2 : get value
n3 : get value
get value :
ask for integer "Enter an integer: "
27
The Remix Language -
function names only 4 keywords:
true, false,
A collection of words and parameters return, redo
A word is a sequence of Unicode characters surrounded by
whitespace (a few characters not allowed)
e.g. ! * what a* and #item a-tag list
28
fi
Example function names
↲ :
(what) ↲ :
(value1) and (value2) :
not at end of (list) :
repeat (block) until (condition) :
for each (#item) from (start) to (finish) (block) :
filter (list) by (#item) where (condition-block) :
show (list) as list :
draw (colour) circle of (size) at (centre) :
(number) is not divisible by any in (list) :
(n)! :
29
The Remix Language -
function calls
Lisp problem of too many parentheses
separated by
30
Assignment inside functions
What is the output here?
what is a? :
(a) ↲ 4
32
fl
The Remix Language -
indentation
Code starting at the left side margin is top-level code
33
fi
fi
fi
turtle graphics on (maroon) paper
radius : 200
step : radius × π ÷ 180
turtles : 36 turtles
show paper
========================================
(n) turtles:
turtles : {}
repeat (n) times
new-turtle: based on (turtle)
new-turtle’s colour : random colour
move the (new-turtle) by (radius)
turn the (new-turtle) 90 degrees
add the (new-turtle) to (turtles)
turn 10 degrees
turtles
34
The Remix Language -
indentation and deferred blocks
Tabs are used to indent code (pause for general
moaning about this e.g. make les)
35
fi
This is really important
36
Comments
Comments are very exible
37
fl
Statements
assignment statement
my-name : "Robert"
return statement - can return nothing. Functions without explicit "return" will return last value evaluated.
return something
redo statement
redo
expression
rain-fall [2] : 13
38
fi
Expressions
Arithmetic - all operators currently have the same precedence - right associative
if no explicit return, use the result of the last statement, some statements
have the value "none"
39
fi
Lists
rain-fall : {-1, -3, 0, 5, -2, 1.0, 0, 6, 7, 999, -2, 0, 10}
40
Ranges
1 to 10, 5 to -5
direction implicit
iterator functions
start (range)
next (range)
end of (range)
41
Maps
A map/hash/dictionary - with keys
and values a-shape : {
position : {0, 0}
Can add extra elds after copying heading : 0 ; straight up
size : 5
The { } are used for lists and maps. colour : black
points : {}
}
If the elements are
make shape of (points) :
key : value new-shape : based on (a-shape)
new-shape [points] : points
new-shape
then Remix creates a map,
otherwise it creates a list.
42
fi
Objects
Objectives
43
Objects
The create function makes objects with elds
and methods.
Methods without (me) or (my) are private welcome (me) and bye :
to the object. say hello to (me)
{"bye now."} ↲
Field names must be different from
parameters. (No "this" or "self".) person : a person called "Mary"
showline (person’s name)
Syntactic sugar - object’s (the possessive) is say hello to (person)
equivalent to (object) - with parentheses. This welcome (person) and bye
means elds can be referred to in a readable
way. e.g. person’s name
44
fi
fi
Getters and Setters
object elds are private
45
fi
fi
Extending
Remix does not have inheritance
but you can extend existing objects using a similar syntax to object
creation
(my) introduction :
{"My name is ", name, "."} ↲
extend (person)
age : years
47
Blocks and Sequences
Blocks hold code for later execution - deferred
Looping is done by calling redo - this takes control back to the start of
the sequence
48
Example control structure
While a "condition" is true keep doing "block"...
while (condition) repeat (block) :
if not (condition)
return last
last : do (block)
redo
49
Transparent functions
Because a block is effectively an anonymous function return inside
a block doesn’t always mean a return from its enclosing function.
50
Reference functions
or reference parameters - the
parameter name starts with "#"
52
The Remix Language -
built-in functions and standard lib functions
Built-in functions include
mathematical operations
if/do/type/input/output functions
list/range/map functions
are all written in Remix (can be inspected and changed by the user)
53
Current implementation
Built in Red (a variant of Rebol)
Originally an interpreter
54
Some research questions
Is it helpful or just a bother?
Assuming it is helpful:
What is the best level to transition natural language statements into "code" like statements?
What is the best way to convey information about parameter requirements in the function name?
What style of function name is most readable - e.g. should prepositions and articles be
included? (Code in Remix written by a speaker of English contains lots of prepositions in function
names.)
55
fl