1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < title > Plang Documents - Function</ title >
7
+ < meta name ="description " content ="More in depth info about using functions and defining them ">
8
+ < link rel ="stylesheet " href ="css/colors.css ">
9
+ < link rel ="stylesheet " href ="css/main.css ">
10
+ < link href ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/css/bootstrap.min.css "
rel ="
stylesheet "
integrity ="
sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN "
crossorigin ="
anonymous "
>
11
+ < script src ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/js/bootstrap.bundle.min.js "
integrity ="
sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL "
crossorigin ="
anonymous "
> </ script >
12
+ </ head >
13
+ < body >
14
+ < div class ="body ">
15
+ < div class ="side-bar ">
16
+ < a href ="index.html ">
17
+ < img
18
+ class ="icon "
19
+ src ="https://avatars.githubusercontent.com/u/146694713?s=400&u=4e01b5afefbf7e40641702e5cbdf785ff183fe35&v=4 "
20
+ alt ="P Icon "
21
+ /> </ a >
22
+ < ul >
23
+ < li > < a href ="index.html "> Introduction</ a > </ li >
24
+ < li > < a href ="getting-started.html "> Getting Started</ a > </ li >
25
+ < ul >
26
+ < li > < a href ="getting-started.html#installing "> Installing</ a > </ li >
27
+ < li > < a href ="getting-started.html#pint-first-time "> Running pint for the first time</ a > </ li >
28
+ < li > < a href ="getting-started.html#first-program "> Your very first P program!</ a > </ li >
29
+ </ ul >
30
+ < li > < a href ="variables.html "> Variables</ a > </ li >
31
+ < ul >
32
+ < li > < a href ="variables.html#defining-variables "> Defining Variables</ a > </ li >
33
+ < li > < a href ="variables.html#using-variables "> Using Variables</ a > </ li >
34
+ </ ul >
35
+ < li > < a href ="functions.html "> Function</ a > </ li >
36
+ < ul >
37
+ < li > < a href ="functions.html#defining-functions "> Defining Functions</ a > </ li >
38
+ < li > < a href ="functions.html#using-functions "> Using Functions</ a > </ li >
39
+ </ ul >
40
+ < li > < a class ="current " href ="examples.html "> Examples</ a > </ li >
41
+ < ul >
42
+ < li > < a href ="examples.html#fizz-buzz "> Fizz Buzz</ a > </ li >
43
+ < li > < a href ="examples.html#http-server "> Simple HTTP Server</ a > </ li >
44
+ < li > < a href ="examples.html#http-request "> Simple HTTP Request</ a > </ li >
45
+ </ ul >
46
+ </ ul >
47
+ </ div >
48
+ < div class ="page-content ">
49
+ < h1 class ="page-title "> Examples</ h1 >
50
+ < p > Some simple examples</ p >
51
+ < h2 id ="fizz-buzz "> Fizz Buzz</ h2 >
52
+ < pre class ="multiCode ">
53
+ use * from @std.io
54
+
55
+ Range range = 1..100
56
+
57
+ every int n in range {
58
+ if n % 3 == 0 and n % 5 == 0 {
59
+ writeln("FizzBuzz")
60
+ } else if n % 3 == 0 {
61
+ writeln("Fizz")
62
+ } else if n % 5 == 0 {
63
+ writeln("Buzz")
64
+ } else {
65
+ writeln(n)
66
+ }
67
+ }</ pre >
68
+ < br >
69
+ < h2 id ="http-server "> Simple HTTP Server</ h2 >
70
+ < pre class ="multiCode ">
71
+ use Server from @http
72
+ use * from @std.io
73
+
74
+ any server = new Server
75
+ void fn handle(any req, any res) {
76
+ res.send('<h1>Made with love in PLang</h1>')
77
+ }
78
+
79
+ int port = 8080
80
+ writeln("Listening on http://localhost:%{port}")
81
+ server.start(port, handle)</ pre >
82
+ < br >
83
+ < h2 id ="http-request "> Simple HTTP Request</ h2 >
84
+ < pre class ="multiCode ">
85
+ use writeln from @std/io
86
+ use request from @http
87
+
88
+ interface Response {
89
+ () :: any json
90
+ }
91
+
92
+ Response res = request("https://api.sampleapis.com/coffee/hot", {
93
+ method: "GET"
94
+ })
95
+
96
+ writeln(res.json())</ pre >
97
+ </ div >
98
+ </ div >
99
+ </ body >
100
+ </ html >
0 commit comments