~subsetpark/ec

208a50058aaaa7a7a93cc4bba216ce87bd2ca9cb — Zach Smith 3 months ago 5771c13 v0.4.2
float parsing and handle bools directly
4 files changed, 34 insertions(+), 32 deletions(-)

M src/calc.janet
M src/operations.janet
M src/parser.janet
M src/repl.janet
M src/calc.janet => src/calc.janet +3 -0
@@ 101,6 101,9 @@
# TODO: Do we want to do something more sophisticated here?
(defmulti make-element [:number] [n] (:new Float n
                                           :doc (string n)))
(defmulti make-element [:boolean] [b] (if b
                                        (make-element 1)
                                        (make-element 0)))
(defmulti make-element [_] [v] v)

(defn- inner-apply

M src/operations.janet => src/operations.janet +11 -12
@@ 13,12 13,12 @@
(defop div 2 /)
(defop mul 2 *)
(defop cmp 2 cmp
  `
  x y -- bool
  ```
  x y -- z
  Push -1 if x < y;
        0 if x = y;
        1 if x > y.
  `)
  ```)
(defop pow 2 math/pow)
(defop sqrt 1 math/sqrt)
(defop small 1 |(or (= $ 0) (= $ 1))


@@ 27,15 27,14 @@
(defmacro defcmp
  [name arity cmp]
  ~(defop ,name ,arity
     (fn [x y] (if (,cmp x y) 1 0))
     (string/format
       `
      x y -- bool
      Comparison predicate.
      Push 1 if x %s y;
             else 0.
      `
       ,(string cmp))))
     ,cmp
     (string/format ```
                    x y -- bool
                    Comparison predicate.
                    Push 1 if x %s y;
                           else 0.
                    ```
                    ,(string cmp))))

(defcmp lt 2 <)
(defcmp gt 2 >)

M src/parser.janet => src/parser.janet +1 -1
@@ 37,7 37,7 @@
              :quotes (cmt (* (set "({") :main (set ")}")) ,handle-quotes)
              :vectors (cmt (* "[" :main "]") ,handle-vectors)
              :number-part (some (+ :d "_"))
              :float (cmt (<- (* (? "-") :number-part "." :number-part)) ,handle-float)
              :float (cmt (<- (* (? "-") (? :number-part) "." :number-part)) ,handle-float)
              :int (cmt (<- (* (? "-") :number-part)) ,handle-int)
              :word (cmt (<- (some (if-not (+ :s (set "()[]{}")) 1))) ,handle-word)
              :token (+ :float :int :word)}))

M src/repl.janet => src/repl.janet +19 -19
@@ 21,14 21,14 @@
    (try
      (let [to-expand (string (string/slice line start end))]
        (->>
         (env-keys env)
         (filter (fn [s] (string/has-prefix? to-expand s)))))
      
          (env-keys env)
          (filter (fn [s] (string/has-prefix? to-expand s)))))

      ([err f]
       (eprint "error in tab completion function:")
       (debug/stacktrace f err)
       @[])))
  
        (eprint "error in tab completion function:")
        (debug/stacktrace f err)
        @[])))

  (when-let [ln (rl/readline prompt get-completions)]
    (buffer/push-string buf ln "\n")
    buf))


@@ 67,18 67,18 @@
  (match obj
    @[:special char] (string char " (Special)")
    _ (string/format
       ```
        ```
       --
       %s : %s
       
       %s%s
       ```
       (print/p obj)
       (string (obj :type))
       (obj :doc)
       (match (obj :composes)
         nil ""
         words (string "\n\n(" (print/p words) ")")))))
        (print/p obj)
        (string (obj :type))
        (obj :doc)
        (match (obj :composes)
          nil ""
          words (string "\n\n(" (print/p words) ")")))))

(defn- describe-all
  [s q]


@@ 118,11 118,11 @@
              (parser/parse)
              (handle-commands s))

         ([err fib]
          (eprint err)
          (if (os/getenv "EC_TRACEBACK")
            (propagate err fib)
            (put s :data bak))))))
      ([err fib]
        (eprint err)
        (if (os/getenv "EC_TRACEBACK")
          (propagate err fib)
          (put s :data bak))))))

(defn handle-line
  ```