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

caio rodrigues caiorss.rodrigues at gmail.com
Thu Jan 7 01:34:36 EST 2016


Thanks for reply.

Regarding to the module is there any way to change the reader macro to
instead of write (namespace#fun1 2 4 5) it be (namespace/fun1 2 4 5). Is it
possible to list the functions and symbols in the namespace ???

Regarding Gambit readtable: Is it possible to implement the transformation
of square brackets delimiters into vectors like Clojure without quotes in
this way:

user=>
user=> [(+ 3 4 5) 1 2 3 :x :y]
[12 1 2 3 :x :y]
user=>

user=> '[(+ 3 4 5) 1 2 3 :x :y]
[(+ 3 4 5) 1 2 3 :x :y]
user=>


When I try in this way I got:

> (macro-readtable-r6rs-compatible-read?-set! (current-readtable) #f)
> '[1 2 3]
#(1 2 3)

[(+ 3 4 5) 1 2 3 x: y:]
*** ERROR IN (console)@50.1 -- Ill-formed expression
>

>
'[(+ 3 4 5) 1 2 3 x: y:]
#((+ 3 4 5) 1 2 3 x: y:)
>

Is it possible to change the way the Gambit repl displays the output for
vectors and hash table?? I mean instead of display *#(1 2 3 4)* for
vectors, display *[1 2 3 4]* and for hash table.

> (list->table '((x 10) (y 200) ("sym" "test")))
#<table #5>
>

Instead of display: *#<table #5>*, it displays *{x 10 y 200 "sym" "test"}*


Thanks in advance.

On 7 January 2016 at 00:27, Marc Feeley <feeley at iro.umontreal.ca> wrote:

> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20160107/64347fb0/attachment.htm>


More information about the Gambit-list mailing list