Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/139'
Browse files Browse the repository at this point in the history
  • Loading branch information
chr15m committed Jan 20, 2017
2 parents 73f1441 + aa34a49 commit dd5c73c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 11 deletions.
4 changes: 2 additions & 2 deletions doc/readme-original.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Variable definitions also happen through special forms:

In _wisp_ variables can be set to new values via the `set!` special form.

Note that in functional programing binding changes are a bad practice (avoiding these will improve the quality and testability of your code), but there are always cases where this is required for JavaScript interoperability:
Note that in functional programming binding changes are a bad practice (avoiding these will improve the quality and testability of your code), but there are always cases where this is required for JavaScript interoperability:

```clojure
(set! a 1) ; => a = 1
Expand Down Expand Up @@ -768,7 +768,7 @@ extended to implement specific protocol using
(-rest [array] (.slice array 1)))
```

Once type / class implemnets some protocol, it's functions can be used
Once type / class implements some protocol, its functions can be used
on the instances of that type / class.

```clojure
Expand Down
1 change: 1 addition & 0 deletions src/backend/escodegen/writer.wisp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
(identical? id ">=") "not-less-than"
(identical? id ">") "greater-than"
(identical? id "<") "less-than"
(identical? id "->") "thread-first"
:else id))

;; **macros** -> __macros__
Expand Down
3 changes: 2 additions & 1 deletion src/backend/javascript/writer.wisp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
(identical? id ">=") "not-less-than"
(identical? id ">") "greater-than"
(identical? id "<") "less-than"
(identical? id "->") "thread-first"
:else id))
;; **macros** -> __macros__
(set! id (join "_" (split id "*")))
Expand Down Expand Up @@ -182,4 +183,4 @@
(vector? form) (write-vector form)
(dictionary? form) (write-dictionary)
(list? form) (apply write-invoke (map write (vec form)))
:else (write-error "Unsupported form")))
:else (write-error "Unsupported form")))
28 changes: 24 additions & 4 deletions src/expander.wisp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
expander (macro op)]
(cond expander (expand expander form env)
;; Calling a keyword compiles to getting value from given
;; object associted with that key:
;; object associated with that key:
;; '(:foo bar) => '(get bar :foo)
(keyword? op) (desugar keyword-invoke form)
;; '(.-field object) => (aget object 'field)
Expand Down Expand Up @@ -202,14 +202,14 @@
(cons '.concat
(sequence-expand (apply concat
(seq form)))))
;; If a vector form expand all sub-forms and concatinate
;; them togather:
;; If a vector form expand all sub-forms and concatenate
;; them together:
;;
;; [~a b ~@c] -> (.concat [a] [(quote b)] c)
(vector? form) (cons '.concat (sequence-expand form))

;; If a list form expand all the sub-forms and apply
;; concationation to a list constructor:
;; concatenation to a list constructor:
;;
;; (~a b ~@c) -> (apply list (.concat [a] [(quote b)] c))
(list? form) (if (empty? form)
Expand Down Expand Up @@ -249,6 +249,26 @@
`(not (= ~@body)))
(install-macro! :not= not-equal)

(defn if-not [condition truthy alternative]
"Complements the `if` exclusive conditional branch."
(if (not condition) truthy, alternative))
(install-macro! :if-not if-not)

(defn expand-comment
"Ignores body, yields nil"
[& body])
(install-macro! :comment expand-comment)

(defn expand-thread-first
"Thread first macro"
[& operations]
(reduce
(fn [form operation]
(cons (first operation)
(cons form (rest operation))))
(first operations)
(rest operations)))
(install-macro! :-> expand-thread-first)

(defn expand-cond
"Takes a set of test/expr pairs. It evaluates each test one at a
Expand Down
9 changes: 9 additions & 0 deletions src/runtime.wisp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
"Returns its argument."
[x] x)

(defn complement
"Takes a fn f and returns a fn that takes the same arguments as f,
has the same effects, if any, and returns the opposite truth value."
[f] (fn
([] (not (f)))
([x] (not (f x)))
([x y] (not (f x y)))
([x y & zs] (not (apply f x y zs)))))

(defn ^boolean odd? [n]
(identical? (mod n 2) 1))

Expand Down
8 changes: 4 additions & 4 deletions src/string.wisp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
(defn ^String capitalize
"Converts first character of the string to upper-case, all other
characters to lower-case."
[string]
(if (< (count string) 2)
(upper-case string)
[s]
(if (< (count s) 2)
(upper-case s)
(str (upper-case (subs s 0 1))
(lower-case (subs s 1)))))

Expand Down Expand Up @@ -125,4 +125,4 @@
(defn reverse
"Returns s with its characters reversed."
[string]
(join "" (.reverse (split string ""))))
(join "" (.reverse (.split string #""))))

0 comments on commit dd5c73c

Please sign in to comment.