-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #216 from nbuilding/value-access
Add the `[]` operator
- Loading branch information
Showing
6 changed files
with
66 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1 @@ | ||
import times | ||
import FileIO | ||
import request | ||
import json | ||
import websocket | ||
|
||
let textToBytes = [text:str] -> list[int] { | ||
let b = [] | ||
for (i in range(0, len(text), 1)) { | ||
if let <yes c> = text |> charAt(i) { | ||
var b = b |> append(charCode(c)) | ||
} | ||
var b = b |> append(0) | ||
} | ||
return b | ||
} | ||
|
||
let thing = [] -> cmd[()] { | ||
let imageData = FileIO.readBytes("C:\\Users\\Ashvin Ranjan\\Downloads\\IMG_1499.jpg")! |> default([1]) | ||
let image = "" | ||
for (byte in imageData) { | ||
var image = image + intCode(byte) | ||
} | ||
print(times.getTime()!) | ||
let _ = FileIO.appendBytes("test.txt", [26, 26])! | ||
print(FileIO.readBytes("test.txt")!) | ||
print(request.delete("https://github.com", mapFrom([("", "")]))!) | ||
let _ = request.createServer(3000, | ||
[path:str requestType:str data:json.value] -> cmd[{ responseCode:int; data:list[int]; headers:map[str, str]; mimetype:str }] { | ||
if (path == "" && requestType == "GET") { | ||
return { | ||
responseCode: 200 | ||
data: textToBytes("oops"); | ||
headers: mapFrom([ | ||
("Access-Control-Allow-Origin", "*"), | ||
("Content-Type", "text/html"), | ||
]) | ||
mimetype: "text/html" | ||
} | ||
} | ||
return { | ||
responseCode: 404 | ||
data: textToBytes("oops"); | ||
headers: mapFrom([ | ||
("Access-Control-Allow-Origin", "*"), | ||
("Content-Type", "text/plain"), | ||
]) | ||
mimetype: "text/plain" | ||
} | ||
} | ||
)! | ||
} | ||
|
||
|
||
print(getType(thing)) | ||
print(getType(imp "./runner.n")) | ||
|
||
let thing2 = [] -> cmd[()] { | ||
print("opening the websocket!") | ||
let _ = websocket.createServer( | ||
{ | ||
onConnect: [user:websocket.user path:str] -> cmd[bool] { | ||
print(user) | ||
let _ = user.send("hello")! | ||
return false | ||
} | ||
onMessage: [user:websocket.user message:str] -> cmd[bool] { | ||
print(message) | ||
let _ = user.send(message)! | ||
// user.disconnect() | ||
return false | ||
} | ||
onDisconnect: [user:websocket.user exitData:maybe[{ code: int; reason:str }]] -> cmd[bool] { return false } | ||
}, | ||
3000 | ||
)! | ||
} | ||
|
||
let pub test = thing2() | ||
print(["12", "1", "2"][1][1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ let a = -( | |
)! | ||
)[(g |> h)] | ||
)() | ||
)([i | j)] | ||
)([i | j]) | ||
)[([])] | ||
) | ||
let b = ( | ||
|