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.
Afficher les réponses par date
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@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@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
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@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@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@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Hello Marc,
you once pointed out, that it is possible to write a preprocessor and keep the source code information (http://article.gmane.org/gmane.lisp.scheme.gambit/6402)
By browsing the gambit sources I found out that this could be done in an even simpler way:
(println (eqv? 34 (eval (##source-code (call-with-input-string "(+ 33 1)" ##read-expr-from-port)))))
So passing such expressions to eval does the right thing.
But: How can achive the same effect as compile-file-to-target on source code objects? In other words can I generate location annotated source code and compile it to C (or any other target language)? Needles to say, that any exception should contain the right source location.
Best Regards,
Gerald
On Wed, 6 Jan 2016 22:27:58 -0500 Marc Feeley feeley@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@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@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Hello Marc,
you once pointed out, that it is possible to write a preprocessor and keep the source code information (http://article.gmane.org/gmane.lisp.scheme.gambit/6402)
By browsing the gambit sources I found out that this could be done in an even simpler way:
(println (eqv? 34 (eval (##source-code (call-with-input-string "(+ 33 1)" ##read-expr-from-port)))))
So passing such expressions to eval does the right thing.
But: How can achive the same effect as compile-file-to-target on source code objects? In other words can I generate location annotated source code and compile it to C (or any other target language)? Needles to say, that any exception should contain the right source location.
Best Regards,
Gerald
On Wed, 6 Jan 2016 22:27:58 -0500 Marc Feeley feeley@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@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@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list
Gambit-list mailing list Gambit-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list