File tree Expand file tree Collapse file tree 1 file changed +41
-1
lines changed Expand file tree Collapse file tree 1 file changed +41
-1
lines changed Original file line number Diff line number Diff line change 1862
1862
~@(next forms))
1863
1863
x))
1864
1864
1865
+ ;;;;;;;;;;;;;;;;;;;;;;
1866
+ ;; String Functions ;;
1867
+ ;;;;;;;;;;;;;;;;;;;;;;
1868
+
1869
+ (import* os)
1870
+
1871
+ (defn format
1872
+ "Format a string as by Python's `%` operator."
1873
+ [fmt & args]
1874
+ (if (= 1 (count args))
1875
+ (let [arg (first args)]
1876
+ (if (or (map? arg) (py-dict? arg))
1877
+ (operator/mod fmt (python/dict arg))
1878
+ (operator/mod fmt arg)))
1879
+ (operator/mod fmt (python/tuple args))))
1880
+
1865
1881
;;;;;;;;;;;;;;;;;;;;;;
1866
1882
;; Output Utilities ;;
1867
1883
;;;;;;;;;;;;;;;;;;;;;;
1882
1898
[]
1883
1899
(.flush *out*))
1884
1900
1901
+ (defn newline
1902
+ "Write a platform specific newline to *out*."
1903
+ []
1904
+ (.write *out* os/linesep)
1905
+ nil)
1906
+
1907
+ (defmacro with-in-str
1908
+ "Evaluate body with *in* bound to a io.StringIO instance containing the
1909
+ string s."
1910
+ [s & body]
1911
+ `(binding [*in* (io/StringIO ~s)]
1912
+ ~@body))
1913
+
1885
1914
(defmacro with-out-str
1886
1915
"Capture the contents of text sent to *out* and return the contents as a
1887
1916
string."
1991
2020
(with-out-str
1992
2021
(apply println args)))
1993
2022
2023
+ (defn printf
2024
+ "Prints formatted output as per format.
2025
+
2026
+ Does not append a newline."
2027
+ [fmt & args]
2028
+ (print (apply format fmt args)))
2029
+
1994
2030
;;;;;;;;;;;;;;;;;;;;
1995
2031
;; REPL Utilities ;;
1996
2032
;;;;;;;;;;;;;;;;;;;;
2805
2841
2806
2842
(import* abc)
2807
2843
2808
- (defmulti ^:private munge
2844
+ (defmulti munge
2809
2845
"Munge the input value into a Python-safe string. Converts keywords and
2810
2846
symbols into strings as by `name` prior to munging. Returns a string."
2811
2847
python/type)
2822
2858
[s]
2823
2859
(basilisp.lang.util/munge s))
2824
2860
2861
+ (def namespace-munge
2862
+ "Convert a Basilisp namespace name to a valid Python name."
2863
+ munge)
2864
+
2825
2865
(defn gen-interface
2826
2866
"Generate and return a new Python interface (abstract base clase).
2827
2867
You can’t perform that action at this time.
0 commit comments