-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscheme.html
113 lines (93 loc) · 3.41 KB
/
scheme.html
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Coddur • Scheme</title>
<style type="text/css" media="screen">
body {
background-color: beige;
font-family: sans-serif;
}
#title {
margin: auto;
font-family: sans-serif;
}
#editor {
margin: auto;
height: 97.5vh;
width: auto;
}
</style>
</head>
<body>
<pre id="editor">SCHEME!
Here is a brief summary of the Scheme programming language (feel free to experiment around!):
Arithmetic:
(+ num1 num2) - adds two values
(- num1 num2) - subtracts two values
(* num1 num2) - multiplies two values
(/ num1 num2) - divides two values
You can combine functions within each other:
(+ (- 3 4) (/ 1 2))
Procedures:
A theoretical procedure declaration:
(define (name param)
(op param param))
An example:
(define (square x)
(* x x))
Note: you may have more than one parameter!
Words:
Quotes:
Either use '(param1) or (quote param1)
Selectors:
(first param1) - gets the first item of an element
(last param1) - gets the last item of an element
(butfirst param1) - everything but the first item of an element is returned
(butlast param1) - everything but the first item of an element is returned
(item num param1) - takes a number and returns the element found at that position
Constructors:
(word param1 param2) - joins parameters as a single world
(sentence param1 param2) - joins parameters as a sentence
Predicates:
A function that returns true (#t) or false (#f).
(equal? param1 param2) - checks if the two parameters are equal
(member? param1 param2) - checks if param1 is contained in param2
(before? param1 param2) - compares param1 and param2 althabetically
(empty? param1) - checks if param1 contains any elements
(number? param1) - checks if param1 is a number
(boolean? param1) - checks if param1 is a boolean
(word? param1) - checks if param1 is a word
(sentence? param1) - checks if param1 is sentence
Structure of an if statement:
(if (> 3 4)
'greater
'less)
And evaluates if all elements are true. Or reads left to right and evaluates as soon as one element is true.
Structure of a cond statement:
(cond ((= 3 3) #t)
((> 4 3) #t)
(else #f))
Variables:
To declare a variable:
(define x 3)
To use let:
(let ((x (+ 3 1))) ...)
Higher-Order Functions:
(every func1 param1) - applies func1 to param1 for every value in param1
(keep pred1 param1) - keeps every value of param1 that returns true for pred1
(accumulate func1 param1) - combines param1 with the function func1
Lambda:
Lambda can be thought of a function declared at an instance.
(lambda (x) (+ x 3))
Recursion is a repetitive process using a base case and calls to the function.
</pre>
<script src="ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/twilight");
editor.session.setMode("ace/mode/scheme");
</script>
</body>
</html>