Quote reader macro.

This commit is contained in:
Erik Svedäng 2017-10-17 09:02:12 +02:00
parent a0f35a5543
commit 2237b955aa
3 changed files with 25 additions and 17 deletions

View File

@ -6,7 +6,7 @@
(if (= (count xs) 1)
(car xs)
(list
(quote if)
'if
(car xs)
(car (cdr xs))
(cond-internal (cdr (cdr xs))))))))
@ -16,29 +16,29 @@
(defmacro for [settings body] ;; settings = variable, from, to, <step>
(list
(quote let)
'let
(array (car settings) (car (cdr settings)))
(list
(quote while)
(list (quote Int.<) (car settings) (car (cdr (cdr settings))))
(list (quote do)
'while
(list 'Int.< (car settings) (car (cdr (cdr settings))))
(list 'do
body
(list
(quote set!) (list (quote ref) (car settings))
(list (quote Int.+)
'set! (list 'ref (car settings))
(list 'Int.+
(car settings)
(if (= 4 (count settings)) ;; optional arg for step
(car (cdr (cdr (cdr settings))))
1)))))))
(defmacro refstr [x]
(list (quote ref)
(list (quote str) x)))
(list 'ref
(list 'str x)))
(defmodule Array
(defmacro foreach [f xs]
(list (quote let)
(list 'let
(array
(quote temp)
(list (quote Array.transform) f xs))
'temp
(list 'Array.transform f xs))
())))

View File

@ -1,12 +1,14 @@
# Todo
## Critical Bugs
* The 'range' function is fully generic (for all 'a') but only compiles when 'a' is numeric type
* Go over all the Array functions and make sure they are memory safe
* Can't define globals of type String or String-ref.
* Just entering '=' at the REPL leads ot strange type error.
* The 'foreach' macro should not make use of 'transform' (it allocates an array)
## Ugliness
* Just entering '=' at the REPL leads ot strange type error.
* The 'range' function is fully generic (for all 'a') but only compiles when 'a' is numeric type
## Big Language Features
* Generic data types (apart from Array, which already is)
* Tagged unions (also known as "sum types" or "enums")
@ -18,7 +20,6 @@
* Good string functions
* Being able to use 'the' in function parameter declarations, i.e. (defn f [(the Int x)] x) to enforce a type
* Allow use of 'the' as a wrapper when defining a variable or function, i.e. (the (Fn [Int] Int) (defn [x] x))
* Quote
* Quasiquote
* Splicing in macros
* Pattern matching on arguments in macros?

View File

@ -201,9 +201,16 @@ copy = do i1 <- createInfo
_ <- Parsec.char '@'
expr <- sexpr
return (XObj (Lst [(XObj (Sym (SymPath [] "copy")) i1 Nothing), expr]) i2 Nothing)
quote :: Parsec.Parsec String ParseState XObj
quote = do i1 <- createInfo
i2 <- createInfo
_ <- Parsec.char '\''
expr <- sexpr
return (XObj (Lst [(XObj (Sym (SymPath [] "quote")) i1 Nothing), expr]) i2 Nothing)
sexpr :: Parsec.Parsec String ParseState XObj
sexpr = do x <- Parsec.choice [ref, copy, list, array, atom]
sexpr = do x <- Parsec.choice [ref, copy, quote, list, array, atom]
_ <- whitespaceOrNothing
return x