Skip to content

Commit 82f204a

Browse files
committed
std: Improvements for the stdlib
1 parent 0295508 commit 82f204a

File tree

3 files changed

+286
-2
lines changed

3 files changed

+286
-2
lines changed

std/fs/fs.pics

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
2+
3+
// Module: Fs
4+
// Functions for interacting with the filesystem
5+
Fs :: module {
6+
7+
// Function: readToString
8+
// Reads the path to a string
9+
//
10+
// Parameters:
11+
// path - (String) The path to read from
12+
//
13+
// Returns:
14+
// Tuple - The tuple representing a success or an error
15+
// --Code:
16+
// (true, ()) // Represents a success value
17+
// ((), err) // Represents an error value
18+
// --
19+
//
20+
readToString :: (path) = pic_nat_readtostring(path)
21+
22+
// Function: readToFileString
23+
// Reads the file to a string
24+
//
25+
// Parameters:
26+
// file - (Object) The path to read from
27+
//
28+
// Returns:
29+
// Tuple - The tuple representing a success or an error
30+
// --Code:
31+
// (true, ()) // Represents a success value
32+
// ((), err) // Represents an error value
33+
// --
34+
//
35+
readFileToString :: (file) = pic_nat_readfiletostring(file)
36+
37+
38+
// Function: writeLine
39+
// Write the line to the file represented by the path
40+
//
41+
// Parameters:
42+
// path - (Object) The path to write to
43+
// line - (String) The line to write
44+
//
45+
// Returns:
46+
// Tuple - The tuple representing a success or an error
47+
// --Code:
48+
// (true, ()) // Represents a success value
49+
// ((), err) // Represents an error value
50+
// --
51+
//
52+
writeLine :: (path, line) = pic_nat_writeline(path, line)
53+
54+
55+
// Function: writeLines
56+
// Write the line to the file represented by the path
57+
//
58+
// Parameters:
59+
// path - (Object) The path to write to
60+
// lines - (Array) The lines to write
61+
//
62+
// Returns:
63+
// Tuple - The tuple representing a success or an error
64+
// --Code:
65+
// (true, ()) // Represents a success value
66+
// ((), err) // Represents an error value
67+
// --
68+
//
69+
writeLines :: (path, lines=[]) = pic_nat_writelines(path, lines)
70+
71+
72+
// Function: appendLine
73+
// Append the line to the file represented by the path
74+
//
75+
// Parameters:
76+
// path - (Object) The path to write to
77+
// line - (String) The lines to write
78+
//
79+
// Returns:
80+
// Tuple - The tuple representing a success or an error
81+
// --Code:
82+
// (true, ()) // Represents a success value
83+
// ((), err) // Represents an error value
84+
// --
85+
//
86+
appendLine :: (path, line) = pic_nat_appendline(path, line)
87+
88+
89+
// Function: appendLines
90+
// Write the line to the file represented by the path
91+
//
92+
// Parameters:
93+
// path - (Object) The path to write to
94+
// lines - (Array) The lines to write
95+
//
96+
// Returns:
97+
// Tuple - The tuple representing a success or an error
98+
// --Code:
99+
// (true, ()) // Represents a success value
100+
// ((), err) // Represents an error value
101+
// --
102+
//
103+
appendLines :: (path, lines=[]) = pic_nat_appendlines(path, lines)
104+
105+
106+
107+
// Function: writeLineToFile
108+
// Write the line to the file object
109+
//
110+
// Parameters:
111+
// file - (File) The file to write to
112+
// line - (String) The line to write
113+
//
114+
// Returns:
115+
// Tuple - The tuple representing a success or an error
116+
// --Code:
117+
// (true, ()) // Represents a success value
118+
// ((), err) // Represents an error value
119+
// --
120+
//
121+
writeLineToFile :: (file, line) = pic_nat_writelinetofile(file, line)
122+
123+
124+
// Function: writeLinesToFile
125+
// Write the line to the file object
126+
//
127+
// Parameters:
128+
// file - (File) The file to write to
129+
// lines - (Array) The lines to write
130+
//
131+
// Returns:
132+
// Tuple - The tuple representing a success or an error
133+
// --Code:
134+
// (true, ()) // Represents a success value
135+
// ((), err) // Represents an error value
136+
// --
137+
//
138+
writeLinesToFile :: (file, lines) = pic_nat_writelinestofile(file, lines)
139+
140+
141+
142+
// Function: appendLineToFile
143+
// Append the line to the file
144+
//
145+
// Parameters:
146+
// file - (File) The file to write to
147+
// line - (String) The lines to write
148+
//
149+
// Returns:
150+
// Tuple - The tuple representing a success or an error
151+
// --Code:
152+
// (true, ()) // Represents a success value
153+
// ((), err) // Represents an error value
154+
// --
155+
//
156+
appendLineToFile :: (file, line) = pic_nat_appendlinetofile(file, line)
157+
158+
159+
// Function: appendLinesToFile
160+
// Write the line to the file
161+
//
162+
// Parameters:
163+
// file - (File) The file to write to
164+
// lines - (Array) The lines to write
165+
//
166+
// Returns:
167+
// Tuple - The tuple representing a success or an error
168+
// --Code:
169+
// (str, ()) // Represents a success value
170+
// ((), err) // Represents an error value
171+
// --
172+
//
173+
appendLinesToFile :: (file, lines=[]) = pic_nat_appendlinestofile(file, lines)
174+
175+
176+
// Function: getContext
177+
// Get the context for the filesystem
178+
//
179+
// Parameters:
180+
// path - (String) The path to create a context for
181+
//
182+
// Returns:
183+
// (Object) - The context as an object
184+
//
185+
getContext :: (path) = pic_nat_getcontext(path)
186+
187+
188+
// Function: getFileContext
189+
// Get the context for the filesystem from a file object
190+
//
191+
// Parameters:
192+
// file - (File) The file to create a context for
193+
//
194+
// Returns:
195+
// (Object) - The context as an object
196+
//
197+
getFileContext :: (file) = pic_nat_getfilecontext(file)
198+
199+
200+
// Function: cd
201+
// Change the directory
202+
//
203+
// Parameters:
204+
// ctx - (Object) The context object
205+
// path - (String) The path to change to
206+
//
207+
// Returns:
208+
// (Object) - The context as an object
209+
//
210+
cd :: (ctx, path) = pic_nat_cd(ctx, path)
211+
212+
213+
// Function: ls
214+
// Change the directory
215+
//
216+
// Parameters:
217+
// ctx - (Object) The context object
218+
// path - (String) The path to change to
219+
//
220+
// Returns:
221+
// (Object) - The context as an object
222+
//
223+
ls :: (ctx, path=".") = pic_nat_ls(ctx, path)
224+
225+
226+
// Function: getPwd
227+
// Gets the current working directory
228+
//
229+
// Parameters:
230+
// ctx - (Object) The context object
231+
//
232+
// Returns:
233+
// (String) - The current working directory
234+
//
235+
getPwd :: (ctx) = pic_nat_pwd(ctx)
236+
}
237+
238+

std/object/object.pics

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,44 @@ Object :: module {
66
// Checks is the objects has the specified value as a key
77
//
88
// Parameters:
9-
// value - The value to check
9+
// object - The object to check
10+
// key - The key to check for existence
1011
//
1112
// Returns:
1213
// true if the object contains the key, false if not
13-
haskey :: (value) = pic_nat_ishaskey(value)
14+
hasKey :: (object, key) = pic_nat_haskey(object, key)
15+
16+
17+
// Function: hasValue
18+
// Checks is the objects has the specified value
19+
//
20+
// Parameters:
21+
// object - The object to check
22+
// value - The value to check for existence
23+
//
24+
// Returns:
25+
// true if the object contains the key, false if not
26+
hasValue :: (object, value) = pic_nat_hasvalue(object, value)
27+
28+
// Function: getKeys
29+
// Gets the keys in the object
30+
//
31+
// Parameters:
32+
// object - The object to check
33+
//
34+
// Returns:
35+
// (Array) - An array of keys in the object
36+
getKeys :: (object) = pic_nat_getkeys(object)
37+
38+
39+
// Function: getValues
40+
// Gets the values in the object
41+
//
42+
// Parameters:
43+
// object - The object to check
44+
//
45+
// Returns:
46+
// (Array) - An array of values in the object
47+
getValues :: (object) = pic_nat_getvalues(object)
48+
1449
}

std/string/string.pics

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,17 @@ String :: module {
7373
split :: (value="", delim="") = pic_nat_stringsplit(value, delim)
7474

7575

76+
// Function: from
77+
// Returns the internal string representation of a value
78+
//
79+
// Parameters:
80+
// value - The value to create a string from
81+
//
82+
// Returns:
83+
// (String) - The String representation of the value passed
84+
from :: (value="") = pic_nat_stringfrom(value)
85+
86+
7687
// Function: repeat
7788
// Repeats a string `n` times.
7889
//

0 commit comments

Comments
 (0)