Description: Implement Clojure functionality and features on top of Gambit Scheme.
Motivation: Clojure Syntax and macros are what a modern Lisp syntax should be: flexible, readable and short. Despite the JVM be powerful and Clojure runs on top of it, the JVM based languages are not suitable to create scripts and interface native code and OS api due to low startup time. Gambit Scheme has define-macro and an excellent FFI which and complies to R5RS Scheme standard what makes this Scheme implementation suitable to build a Clojure-like language that compiles to native code.
This project aims to implement a Clojure-like scheme on top of Gambit Scheme which has the following features: Commong Lisp Style macros, define-macro and a powerful FFI (Foreign Function Interface).
- [] Implement Vector literal using reader-macro
- [] Implement Hash Map Literal using reader-macro
- [x] Learn How to use the FFI (Foreign Function Interface)
- [x] Implement Pattern Matching Macros
- [] Clojure Macros
- [x] Thread-first macro
- [x] Thread-last macro
- [x] Data flow macro with $
- [] Implement Clojure Abstraction
Core Library Containing many higher order functions
- file:core.scm Core Definitions and Macros
See: -
Contains many macros that emulates clojure syntax and features.
> (dotimes n 5 (println n))
0
1
2
3
4
> (dolist x (list 1 2 3 4 5) (println x))
1
2
3
4
5
>
> (dolist f (directory-files "/") (println f))
lost+found
initrd.img
bin
cdrom
initrd.img.old
root
opt
vmlinuz.old
lib
mnt
local.cfg
run
...
Pattern Matching Macro
(define-macro (bind-form form param sepxp)
(cond
((pair? form) `(let*
(
($ ,param)
(,(car form) (car $))
(,(cdr form) (cdr $))
)
,sepxp
))
))
;; End of bind-form
>
(map
(fn (p) (bind-form (x . y) p (+ x y)))
'((1 . 2) (3 . 4) (6 . 8) (10 . 5))
)
(3 7 14 15)
>
(defn my-map (f xs)
(if (empty? xs)
'()
(bind-form (hd . tl) xs
(cons (f hd) (my-map f tl))
)))
> (my-map inc '(1 2 3 4 5 6))
(2 3 4 5 6 7)
> (letc
(a 10
b (+ a 10)
c (* a b)
)
(+ a b c))
230
>
(include "ffi-tools.scm")
(define add-test
(c-lambda
(int int)
int
"
___result = ___arg1 + ___arg2;
"
))
;;(c-declare "#include <stdlib.h>")
;;
(def-Cfunc cbrt
"cbrt"
(double)
double
)
;;; int gethostname(char *name, size_t len);
(def-Cfunc gethostname
"gethostname"
((pointer char #f) unsigned-int)
int
)
(define (get-hostname2)
(with-malloc (s 64)
(gethostname s 64)
(ptr->string s)
))
(def-Cfunc-code get-hostname
()
char-string
"
char hostname [64];
gethostname(hostname, 64);
___result = hostname ;
"
)
(def-Cfunc cbrt
"cbrt"
(double)
double
)
Wrapper to Libxml2 to libxml2 to parse XML.
- [] Implement function that turns the xml format into sxml format.
- [] Implement tests to libxml2
- [] Build Script
Gambit Scheme Wrapper to Libcurl using ffi.
- [] Create Build Scripts
- [] Create Tests
- [] Create Examples