[gambit-list] Reader macro, read square brackets to vector and module system.

Marc Feeley feeley at iro.umontreal.ca
Wed Jan 6 22:27:58 EST 2016


Yes Gambit’s readtable can be modified to do what you want:

> '[1 2 3]
(1 2 3)
> (include "~~lib/_gambit#.scm")
> (macro-readtable-r6rs-compatible-read?-set! (current-readtable) #f)
> '[1 2 3]
#(1 2 3)
> '{a: 11 b: 22 c: 33}
(a: 11 b: 22 c: 33)
> (macro-readtable-brace-keyword-set! (current-readtable) 'create-hashtable)
> (define (create-hashtable . rest)
    (let loop ((lst rest) (alist '()))
      (if (pair? lst)
          (loop (cddr lst)
                (cons (cons (keyword->string (car lst)) (cadr lst)) alist))
          (list->table alist))))
> (define t {a: 11 b: 22 c: 33})
> (table-ref t "b")
22

Gambit also has namespaces, so you can do:

----------------------------------------------------------------
;; file: "namespace.scm"

(namespace ("namespace#") ("" include))
(include "~~lib/gambit#.scm")

(define (fun1 x y z) (+ x y z))
----------------------------------------------------------------

and at the REPL:

> (load "namespace.scm")
"/Users/feeley/namespace.scm"
> (namespace#fun1 2 4 5)
11

Marc

> On Jan 6, 2016, at 6:50 PM, caio rodrigues <caiorss.rodrigues at gmail.com> wrote:
> 
> Hi list. Is there any way to make Gambit repl read for instance [1 2 3 4 5] and turn it into a vector #(1 2 3 4 5) and also everything into brackets {x: 2 y: 4} into a hash table ?
> 
> Another question: Is there any module system implementation for gambit that can import packages like Python, import sys or a clojure-like module system ? 
> 
> Example Clojure-like module system:
> 
> file: namespace.ss
> 
> ---------------------------------
> 
> (ns namespace)
> 
> (define (fun1 ....)
> 
> (define (fun2 x y z) ...)
> 
> ---------------------------------
> 
> and then in the repl: 
> 
> (require 'namespace)
> 
> (namespace/fun1 2 4 5)
> 
> Thanks in advance.
> 
> 
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list