Giter Club home page Giter Club logo

clj-scheme's Introduction

CljScheme

CljScheme

Overview

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).

Tasks

  • [] 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

Files:

scljcore.scm

Core Library Containing many higher order functions

  • file:core.scm Core Definitions and Macros

See: -

smacros.scm

Contains many macros that emulates clojure syntax and features.

Dotimes

> (dotimes n 5 (println n))
0
1
2
3
4

Dolist

> (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
...

Bind Form

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)

Clojure Special Forms

Clojure let

> (letc
   (a 10
    b (+ a 10)
    c (* a b)
    )
   (+ a b c))
230
>

system.scm

ffi-tools.scm

(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
            )

Libraries

Libxml2

Wrapper to Libxml2 to libxml2 to parse XML.

  • [] Implement function that turns the xml format into sxml format.
  • [] Implement tests to libxml2
  • [] Build Script

Libcurl

Gambit Scheme Wrapper to Libcurl using ffi.

  • [] Create Build Scripts
  • [] Create Tests
  • [] Create Examples

clj-scheme's People

Contributors

caiorss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

plumpmath

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.