[gambit-list] Source objects and precompiling (Was: Reader macro, read square brackets to vector and module system.)
Gerald Klix
Gerald.Klix at klix.ch
Thu Jan 7 06:18:07 EST 2016
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 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
>
> _______________________________________________
> 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