Skip to content

Commit

Permalink
Better readme
Browse files Browse the repository at this point in the history
  • Loading branch information
benekastah committed Oct 19, 2012
1 parent e070efa commit 24845c6
Show file tree
Hide file tree
Showing 8 changed files with 615 additions and 22 deletions.
528 changes: 526 additions & 2 deletions README.md

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions package.yml
@@ -0,0 +1,29 @@
---
name: "oppo"
description: "A lisp for javascript"
keywords:
- "lisp"
- "functional programming"
- "fp"
- "parser"
- "compiler"
version: "0.1.2"
main: "dist/oppo.js"
author: "Paul Harper <benekastah@gmail.com>"
bin:
oppo: "./bin/oppo"
scripts:
postinstall: "bin/build"
repository:
type: "git"
url: "git@github.com:benekastah/oppo.git"
dependencies:
optimist: "0.2.x"
optionalDependencies:
uglify-js: "*"
uglify-js2: "*"
devDependencies:
coffee-script: "1.x.x"
engines:
node: "0.8.x"
preferGlobal: true
6 changes: 5 additions & 1 deletion src/compiler.coffee
Expand Up @@ -794,4 +794,8 @@ define_builtin_macro "js::eval", (to_eval) ->
catch e
result = new JavaScriptCode to_eval
else
[(new JavaScriptCode "oppo.root.eval"), compile_item to_eval]
[(new JavaScriptCode "oppo.root.eval"), compile_item to_eval]

define_builtin_macro "js::typeof", (x) ->
c_x = compile_item x
new JavaScriptCode "(typeof #{c_x})"
61 changes: 52 additions & 9 deletions src/oppo/core.oppo
Expand Up @@ -48,21 +48,18 @@
var (js::eval "new oppo.Symbol(varname)")]
`(def #{'local #yes} ,var ((js::eval "require") ,mod))))

(def ->oppo-string ('to-oppo-string ('helpers oppo)))
(def (->log-string x)
(->oppo-string x #f))

(defmacro (new Class ...args)
(let [list* (lambda (...ls) ls)
new-Class (.compile-item oppo Class)
new-Class (.join (list* "new" new-Class) " ")]
`((js::eval ,new-Class) ,@args)))

(defmacro (make-symbol x)
(defmacro #{'runtime-function #(symbol #1)} (symbol x)
`(new ('Symbol oppo) ,x))

(def (symbol x)
(new ('Symbol oppo) x))
(def ->oppo-string ('to-oppo-string ('helpers oppo)))
(def (->log-string x)
(->oppo-string x #f))

(defmacro (puts ...args)
`(.apply ('log console) console (map ->log-string #[,@args])))
Expand All @@ -87,7 +84,7 @@
(let [item (js::eval "items[0]")
rest (js::eval "items.slice(1)")
list* (lambda (...ls) ls)
module-item (make-symbol (.join (list* ('text module) "::" ('text item)) ""))]
module-item (symbol (.join (list* ('text module) "::" ('text item)) ""))]
`(do (def #{'local #yes} ,item ,module-item)
(use-from ,module ,@rest)))))

Expand Down Expand Up @@ -150,6 +147,19 @@
return false;
}"))

(def contains-key? (js::eval "function (coll, key) {
var to_type = oppo.helpers.to_type;
var type = to_type(coll);
switch (type) {
case 'array': case 'arguments': case 'string':
return !isNaN(key) && key < coll.length;
case 'object':
return key in coll;
default:
return false;
}
}"))




Expand Down Expand Up @@ -235,7 +245,7 @@

(let [-merge ('merge ('helpers oppo))]
(def [merge ...objs]
(apply -merge `[,(js::eval "{}") ,@objs])))
(apply -merge (concat #[#{}] objs))))

(def keys ('keys ('helpers oppo)))

Expand Down Expand Up @@ -329,10 +339,43 @@
(def (not=)
(not (apply = (js::eval "arguments"))))


;; TYPE CHECKING METHODS

(defmacro #{'runtime-function #(number? #1)} (number? x)
`(eq~ (js::typeof ,x) "number"))

(defmacro #{'runtime-function #(string? #1)} (string? x)
`(eq~ (js::typeof ,x) "string"))

(defmacro #{'runtime-function #(array? #1)} (array? x)
`(eq~ (typeof ,x) "array"))

(defmacro #{'runtime-function #(arguments? #1)} (arguments? x)
`(eq~ (typeof ,x) "arguments"))

(def (list? x)
(or (array? x)
(arguments? x)))

(def (object? x)
(and (not (nil? x))
(eq~ (js::typeof x) "object")))

(defmacro #{'runtime-function #(nil? #1)} (nil? x)
`(eq~ ,x #nil))

(defmacro #{'runtime-function #(function? #1)} (function? x)
`(eq~ (typeof ,x) "function"))

(defmacro #{'runtime-function #(regex? #1)} (regex? x)
`(eq~ (typeof ,x) "regexp"))

(defmacro #{'runtime-function #(date? #1)} (date? x)
`(eq~ (typeof ,x) "date"))

(def (isNaN? x)
(not-eq~ x x))


;; INCLUDES GO LAST
Expand Down
Empty file added src/oppo/js.oppo
Empty file.
2 changes: 1 addition & 1 deletion src/reader.coffee
Expand Up @@ -5,7 +5,7 @@ HELPERS / SETUP
{to_type, clone, is_quoted, is_symbol, raise} = oppo.helpers
{JavaScriptCode} = oppo
r_whitespace = /^\s+/
r_number_explicit_base = /\d+#[\da-z]+/i
r_number_explicit_base = /^\d+#[\da-z]+/i
r_number = /^(\+|-)?(\d*\.\d+|\d+)(e(\+|-)?\d+)?/i
r_symbol = /^[\w~`!@#$%^&*\-+=|\\"':?\/<>,\.]+/

Expand Down
9 changes: 1 addition & 8 deletions website/test.coffee
Expand Up @@ -7,13 +7,6 @@ compile_code = (code) ->

result = compile_code """
(def (fact n)
(let loop [n* n
accum 1]
(if (< n* 1)
accum
(loop (- n* 1) (* n* accum)))))
(puts (fact 5))
(+ 2#111 5)
"""
2 changes: 1 addition & 1 deletion website/test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24845c6

Please sign in to comment.