mirror of
https://github.com/janet-lang/janet
synced 2025-07-06 12:02:53 +00:00
Update indentation in boot and init to be more like
most lisps.
This commit is contained in:
parent
79225ad3d5
commit
e60c8a9b75
@ -15,7 +15,8 @@
|
||||
"Define a function. Equivalent to (def name (fn name [args] ...))."
|
||||
(fn defn [name & more]
|
||||
(def len (length more))
|
||||
(def fstart (fn recur [i]
|
||||
(def fstart
|
||||
(fn recur [i]
|
||||
(def {i ith} more)
|
||||
(def t (type ith))
|
||||
(def tuple? (= t :tuple))
|
||||
@ -29,28 +30,23 @@
|
||||
|
||||
(def defmacro :macro
|
||||
"Define a macro."
|
||||
(do
|
||||
(fn defmacro [name & more]
|
||||
(apply1 defn (array.concat
|
||||
@[name :macro] more)))))
|
||||
(apply1 defn (array.concat @[name :macro] more))))
|
||||
|
||||
(defmacro defmacro-
|
||||
"Define a private macro that will not be exported."
|
||||
[name & more]
|
||||
(apply1 tuple (array.concat
|
||||
@['defmacro name :private] more)))
|
||||
(apply1 tuple (array.concat @['defmacro name :private] more)))
|
||||
|
||||
(defmacro defn-
|
||||
"Define a private function that will not be exported."
|
||||
[name & more]
|
||||
(apply1 tuple (array.concat
|
||||
@['defn name :private] more)))
|
||||
(apply1 tuple (array.concat @['defn name :private] more)))
|
||||
|
||||
(defmacro def-
|
||||
"Define a private value that will not be exported."
|
||||
[name & more]
|
||||
(apply1 tuple (array.concat
|
||||
@['def name :private] more)))
|
||||
(apply1 tuple (array.concat @['def name :private] more)))
|
||||
|
||||
# Basic predicates
|
||||
(defn even? [x] (== 0 (% x 2)))
|
||||
@ -92,15 +88,14 @@
|
||||
(defn true? [x] (= x true))
|
||||
(defn false? [x] (= x false))
|
||||
(defn nil? [x] (= x nil))
|
||||
(def atomic? (do
|
||||
(def non-atomic-types {
|
||||
:array true
|
||||
(def atomic?
|
||||
(do
|
||||
(def non-atomic-types
|
||||
{:array true
|
||||
:tuple true
|
||||
:table true
|
||||
:struct true
|
||||
})
|
||||
:struct true})
|
||||
(fn [x] (not (get non-atomic-types (type x))))))
|
||||
|
||||
(defn sum [xs] (apply1 + xs))
|
||||
(defn product [xs] (apply1 * xs))
|
||||
|
||||
@ -141,7 +136,7 @@ Expands to (def sym (if (= nil sym) val sym))"
|
||||
[condition & body]
|
||||
(tuple 'if condition (tuple.prepend body 'do)))
|
||||
|
||||
(defmacro when-not
|
||||
(defmacro unless
|
||||
"Shorthand for (when (not ... "
|
||||
[condition & body]
|
||||
(tuple 'if condition nil (tuple.prepend body 'do)))
|
||||
@ -213,9 +208,8 @@ value."
|
||||
(var i 0)
|
||||
(var accum @['do])
|
||||
(while (< i len)
|
||||
(array.push accum (tuple 'def
|
||||
(get bindings i)
|
||||
(get bindings (+ 1 i))))
|
||||
(def {i k (+ i 1) v} bindings)
|
||||
(array.push accum (tuple 'def k v))
|
||||
(+= i 2))
|
||||
(array.concat accum body)
|
||||
(apply1 tuple accum))
|
||||
@ -244,8 +238,7 @@ value."
|
||||
:let (tuple 'let verb (doone (+ i 2)))
|
||||
:when (tuple 'if verb (doone (+ i 2)))
|
||||
(error ("unexpected loop predicate: " verb)))
|
||||
(switch
|
||||
verb
|
||||
(switch verb
|
||||
:iterate (do
|
||||
(def preds @['and (tuple ':= bindings object)])
|
||||
(def subloop (doone (+ i 3) preds))
|
||||
@ -308,7 +301,9 @@ value."
|
||||
evaluates to false."
|
||||
[& forms]
|
||||
(def len (length forms))
|
||||
(if (= len 0) true ((fn aux [i]
|
||||
(if (= len 0)
|
||||
true
|
||||
((fn aux [i]
|
||||
(cond
|
||||
(>= (inc i) len) (get forms i)
|
||||
(tuple 'if (get forms i) (aux (inc i)) false))) 0)))
|
||||
@ -318,7 +313,9 @@ evaluates to false."
|
||||
evaluates to true."
|
||||
[& forms]
|
||||
(def len (length forms))
|
||||
(if (= len 0) false ((fn aux [i]
|
||||
(if (= len 0)
|
||||
false
|
||||
((fn aux [i]
|
||||
(def fi (get forms i))
|
||||
(if
|
||||
(>= (inc i) len) fi
|
||||
@ -974,7 +971,8 @@ onvalue."
|
||||
(def p (parser.new))
|
||||
|
||||
# Fiber stream of characters
|
||||
(def chars (coro
|
||||
(def chars
|
||||
(coro
|
||||
(def buf @"")
|
||||
(var len 1)
|
||||
(while (< 0 len)
|
||||
@ -986,7 +984,8 @@ onvalue."
|
||||
0))
|
||||
|
||||
# Fiber stream of values
|
||||
(def vals (coro
|
||||
(def vals
|
||||
(coro
|
||||
(while going
|
||||
(switch (parser.status p)
|
||||
:full (yield (parser.produce p))
|
||||
@ -1003,14 +1002,18 @@ onvalue."
|
||||
# Evaluate 1 source form
|
||||
(defn eval1 [source]
|
||||
(var good true)
|
||||
(def f (fiber.new (fn []
|
||||
(def f
|
||||
(fiber.new
|
||||
(fn []
|
||||
(def res (compile source env where))
|
||||
(if (= (type res) :function)
|
||||
(res)
|
||||
(do
|
||||
(:= good false)
|
||||
(def {:error err :error-line errl :error-column errc} res)
|
||||
(onerr where "compile"
|
||||
(onerr
|
||||
where
|
||||
"compile"
|
||||
(if (< 0 errl)
|
||||
(string err " in form at line " errl ", column " errc)
|
||||
err)))))
|
||||
@ -1040,7 +1043,8 @@ onvalue."
|
||||
(pp x))
|
||||
(when f
|
||||
(def st (fiber.stack f))
|
||||
(loop [{
|
||||
(loop
|
||||
[{
|
||||
:function func
|
||||
:tail tail
|
||||
:pc pc
|
||||
@ -1078,23 +1082,21 @@ environment is needed, use run-context."
|
||||
(run-context *env* chunks (fn [x] (:= returnval x)) default-error-handler "eval")
|
||||
returnval)
|
||||
|
||||
(def module.paths @[
|
||||
"./?.dst"
|
||||
(def module.paths
|
||||
@["./?.dst"
|
||||
"./?/init.dst"
|
||||
"./dst_modules/?.dst"
|
||||
"./dst_modules/?/init.dst"
|
||||
"/usr/local/dst/0.0.0/?.dst"
|
||||
"/usr/local/dst/0.0.0/?/init.dst"
|
||||
])
|
||||
"/usr/local/dst/0.0.0/?/init.dst"])
|
||||
|
||||
(def module.native-paths @[
|
||||
"./?.so"
|
||||
(def module.native-paths
|
||||
@["./?.so"
|
||||
"./?/??.so"
|
||||
"./dst_modules/?.so"
|
||||
"./dst_modules/?/??.so"
|
||||
"/usr/local/dst/0.0.0/?.so"
|
||||
"/usr/local/dst/0.0.0/?/??.so"
|
||||
])
|
||||
"/usr/local/dst/0.0.0/?/??.so"])
|
||||
|
||||
(defn module.find
|
||||
[path paths]
|
||||
@ -1124,7 +1126,9 @@ returned from compiling and running the file."
|
||||
|
||||
(defn check-native
|
||||
[p testpath]
|
||||
(if p p (do
|
||||
(if p
|
||||
p
|
||||
(do
|
||||
(def f (file.open testpath))
|
||||
(if f (do (file.close f) testpath)))))
|
||||
|
||||
@ -1137,11 +1141,11 @@ returned from compiling and running the file."
|
||||
(fn require [path args]
|
||||
(when (get loading path)
|
||||
(error (string "circular dependency: module " path " is loading")))
|
||||
(def {
|
||||
:exit exit-on-error
|
||||
} (or args {}))
|
||||
(def {:exit exit-on-error} (or args {}))
|
||||
(def check (get cache path))
|
||||
(if check check (do
|
||||
(if check
|
||||
check
|
||||
(do
|
||||
(def newenv (make-env))
|
||||
(put cache path newenv)
|
||||
(put loading path true)
|
||||
|
@ -8,10 +8,11 @@
|
||||
(var *exit-on-error* :private true)
|
||||
|
||||
# Flag handlers
|
||||
(def handlers :private {
|
||||
"h" (fn []
|
||||
(def handlers :private
|
||||
{"h" (fn []
|
||||
(print "usage: " (get args 0) " [options] scripts...")
|
||||
(print `Options are:
|
||||
(print
|
||||
`Options are:
|
||||
-h Show this help
|
||||
-v Print the version string
|
||||
-s Use raw stdin instead of getline like functionality
|
||||
@ -29,8 +30,7 @@
|
||||
"e" (fn [i]
|
||||
(:= *no-file* false)
|
||||
(eval (get args (+ i 1)))
|
||||
2)
|
||||
})
|
||||
2)})
|
||||
|
||||
(defn- dohandler [n i]
|
||||
(def h (get handlers n))
|
||||
@ -56,6 +56,4 @@
|
||||
(repl (fn [buf p]
|
||||
(def [line] (parser.where p))
|
||||
(def prompt (string "dst:" line ":" (parser.state p) "> "))
|
||||
(getline prompt buf))))))
|
||||
|
||||
)
|
||||
(getline prompt buf)))))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user