-
Notifications
You must be signed in to change notification settings - Fork 2
/
modules.phia
33 lines (26 loc) · 952 Bytes
/
modules.phia
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
;; vim: syntax=lisp
;; predefined modules, inspired by and linking to certain GO's standard library
;; (use strings)
;; results in ["192", "168", "0", "217"]
;, (println (strings::split "192.168.0.217" "."))
;; allows access to formatted text, such as printf or sprintf
;; (use fmt)
;; (fmt::printf "Hello %q" "traveler")
;; (println (fmt::sprintf "Hello %q" "Space"))
;; function attached to objects / methods are not available in sophia, however
;; you are encouraged to create a module for the object containing these
;; functions and accepting the object as the first function parameter.
;; custom module
(module person
(fun str [p] (++ "person: " p#["name"])
(module extract ;; namespaces can be nested
(fun name (_ p) p["name"])
)
)
;; using a custom module
(use person)
(let pers { name: "anon" })
(println (person::string pers))
;; using nested module
(use person::extract)
(println (person::extract::module pers))