Guest User

Untitled

a guest
Nov 30th, 2025
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1. namespace system
  2.  
  3. class string (const chars private basearray)
  4. {
  5. constructor (carr notnull)
  6. {
  7. if carr is not Array
  8. {
  9. throw new Exception ("Argument must be an array. ")
  10. }
  11. foreach c in carr
  12. {
  13. if c is not char
  14. {
  15. throw new Exception ("Argument must be an array of chars.")
  16. }
  17. }
  18. chars = carr
  19. }
  20.  
  21. constructor()
  22. {
  23. chars = new Array(0)
  24. }
  25.  
  26. func charAt(index notnull)
  27. {
  28. return chars [ index ]
  29. }
  30.  
  31. func length()
  32. {
  33. return lenof chars
  34. }
  35.  
  36. func substr(stind, len)
  37. {
  38. var str = new string()
  39. for var i = stind; i < length(); i = i + 1 : counter ind
  40. {
  41. str = str + chars[i]
  42. if ind = len - 1
  43. {
  44. return str
  45. }
  46. }
  47. }
  48.  
  49. func toNum( )
  50. {
  51. var num = 0
  52. const strlen = length()
  53. for var m = 1 var d = 0; d < strlen; d = d + 1 m = m * 10
  54. {
  55. var dgt = charAt(strlen - 1 - d) - '0'
  56. num = num + dgt * m
  57. }
  58. return num
  59. }
  60. }
  61.  
  62. class Exception (msg)
  63. {
  64. constructor (m notnull)
  65. {
  66. msg = m
  67. }
  68. }
  69.  
  70. class Array ()
  71. {
  72. constructor (len notnull)
  73. {
  74. // BUILTIN FUNCTION
  75. }
  76.  
  77. func length()
  78. {
  79. return lenof this
  80. }
  81.  
  82. func map (mod)
  83. {
  84. const n = new Array ( lenof this )
  85. foreach i in this : counter ind
  86. {
  87. n [ ind ] = mod ( i )
  88. }
  89. return n
  90. }
  91.  
  92. func copy ( )
  93. {
  94. return map(func(item) { return item } )
  95. }
  96. }
  97.  
  98. class List (array private basearray)
  99. {
  100. constructor ( arr notnull )
  101. {
  102. array = arr
  103. }
  104.  
  105. constructor()
  106. {
  107. array = new Array (0)
  108. }
  109.  
  110. func add(val)
  111. {
  112. const n = new Array(array.length() + 1)
  113. for var i = 0; i < count(); i = i + 1
  114. {
  115. n [i] = array[i]
  116. }
  117. n[n.length() - 1] = val
  118. array = n
  119. }
  120.  
  121. func remove(index notnull)
  122. {
  123. const n = new Array (array.length() - 1)
  124. const len = array.length()
  125. for var i = 0; i < index; i = i + 1
  126. {
  127. n[i] = array[i]
  128. }
  129. for var i = index + 1 ; i < len ; i = i + 1
  130. {
  131. n[i - 1] = array[i]
  132. }
  133.  
  134. array = n
  135. }
  136.  
  137. func setAt(i notnull, val)
  138. {
  139. array[i] = val
  140. }
  141.  
  142. func get(i notnull)
  143. {
  144. if i is not number | i > count() - 1 | i < 0
  145. {
  146. throw new Exception ( "Argument out of range." )
  147. }
  148. return array[i]
  149. }
  150.  
  151. func first(cond)
  152. {
  153. if cond is not function
  154. {
  155. throw new Exception("This function takes a function as parameter.")
  156. }
  157. foreach item in array
  158. {
  159. if cond(item) = true
  160. {
  161. return item
  162. }
  163. }
  164. }
  165.  
  166. func findAll(cond)
  167. {
  168. if cond is not function
  169. {
  170. throw new Exception ("This function takes a function as parameter.")
  171. }
  172. const all = new List()
  173. foreach item in array
  174. {
  175. if cond(item) = true
  176. {
  177. all.add(item)
  178. }
  179. }
  180. return all
  181. }
  182.  
  183. func count()
  184. {
  185. return lenof array
  186. }
  187.  
  188. func toString()
  189. {
  190. var s = "["
  191. foreach v in array : counter i
  192. {
  193. s = s + v
  194. if i < count ( ) - 1
  195. {
  196. s = s + ", "
  197. }
  198. }
  199. return s + "]"
  200. }
  201.  
  202. func print()
  203. {
  204. print toString()
  205. }
  206. }
  207.  
  208. class Date (year, month, day, hour, minute)
  209. {
  210. constructor(y, m, d, h, min)
  211. {
  212. year = y
  213. month = m
  214. day = d
  215. hour = h
  216. minute = min
  217. }
  218.  
  219. constructor()
  220. {
  221.  
  222. }
  223.  
  224. func setToNow()
  225. {
  226. // BUILTIN FUNCTION
  227. }
  228.  
  229. static func now ()
  230. {
  231. const n = new Date()
  232. n.setToNow()
  233. return n
  234. }
  235.  
  236. func toString ()
  237. {
  238. var h = hour
  239. if (h < 10)
  240. {
  241. h = "0" + h
  242. }
  243. var m = minute
  244. if (m < 10)
  245. {
  246. m = "0" + m
  247. }
  248. return day + "." + month + "." + year + " " + h + ":" + m
  249. }
  250.  
  251. func print()
  252. {
  253. print toString()
  254. }
  255. }
Advertisement
Add Comment
Please, Sign In to add comment