Re: Way to control the order of macro expansion
After reading some of the original paper by Dybvig[1], I finally managed to get the macro right. The trick was to use "with-syntax", which -- I have to admit -- is still a little magical to me. But by mimicking the way the procedure "generate-temporaries" has been used in the Dybvig's implementation of letrec, I came up with the following solution: (define-syntax private+public (lambda (stx) (define (name interface) (define (interface-name interface) (match interface ((head . tail) (interface-name head)) ((? symbol? name) name))) (datum->syntax stx (interface-name (syntax->datum interface (syntax-case stx () ((_ (private ...) ((define-variant interface . body) ...)) (with-syntax (((name ...) (map name #'(interface ... #`(begin (define name (and (defined? 'name) name)) ... (let () private ... (set! name (let () (define-variant interface . body) name)) ...))) [1] http://www.cs.indiana.edu/~dyb/pubs/tr356.pdf
Re: Way to control the order of macro expansion
On Thu, 2 Jan 2014 15:30:32 +0100 Panicz Maciej Godek wrote: > After reading some of the original paper by Dybvig[1], > I finally managed to get the macro right. The trick > was to use "with-syntax", which -- I have to admit > -- is still a little magical to me. But by mimicking > the way the procedure "generate-temporaries" has > been used in the Dybvig's implementation of letrec, > I came up with the following solution: [snip] Chapter 8 of Dybvig's "Scheme programming language, 4th edition" [1] has a less fulsome but more exampled explanation of 'with-syntax' which might be useful. I found it helpful recently in order to implement a version of 'guard' which works with native guile exceptions - guile's r6rs 'guard' does not do so[2]. Chris [1] http://www.scheme.com/tspl4/syntax.html#./syntax:h0 [1] In doing this, I also discovered that guile's r6rs 'guard' is not r6rs compliant, because if the exception concerned is rethrown because there is no matching handler clause, it does so without first restoring the dynamic context to the one in which the exception was raised. Having said that, I prefer guile's behaviour; and you won't notice the difference unless you have a dynamic-wind in there somewhere.
Re: Way to control the order of macro expansion
It turned out, that the above solution doesn't work exactly as expected -- since the scopes of "private" and "interface" get separated (by the with-syntax form that I have been so proud of), it is impossible for the public forms to refer to private bindings. To solve that issue, I had to pass the private bindings to the function passed with-syntax and then retrieve them. For some reason (which is unclear to me) I had to convert them to datum and then back to syntax, because if they were given verbatim, they failed to get renamed properly. I'd appreciate if anyone could explain it to me, or reviewed the code below to tell whether the names and comments aren't misleading (e.g. I used the name "lexical-context" for a variable, but I'm not sure whether the entity that it refers to can properly be called "lexical context") (define-syntax private+public (lambda (stx) (define (interface+name+body specs lexical-context) ;; the second argument is the lexical context that we ;; want to preserve while extracting the specs (define (interface-name interface) (match interface ((head . tail) (interface-name head)) ((? symbol? name) name))) `(,(datum->syntax stx (syntax->datum lexical-context)) ;; for some reason we need to deconstruct and reconstruct ;; lexical-context here ,(map (lambda(spec) (syntax-case spec () ((interface . body) (datum->syntax stx `(,(syntax->datum #'interface) ,(interface-name (syntax->datum #'interface)) ,(syntax->datum #'body)) specs))) (syntax-case stx () ((_ (private ...) ((pub-define . pub-spec) ...)) ;; we pass the private definitions to the interface+name+body, ;; because we want to be able to refer to private definitions ;; from within the public ones (otherwise the macro processor ;; would treat them as if they were within separate contexts) (with-syntax private ...) ((interface name body) ...)) (interface+name+body #'(pub-spec ...) #'(private ... #'(begin (define name (and (defined? 'name) name)) ... (let () private ... (set! name (let () (pub-define interface . body) name)) ...)))
Where is the backtrace?
> (define (f) (define (g) (define (h) ((lambda x (cdr x (h)) (g)) > (f) :13:0: In procedure #:13:0 x>: :13:0: In procedure cdr: Wrong type argument in position 1 (expecting pair): () Entering a new prompt. Type `,bt' for a backtrace or `,q' to continue > ,bt In current input: 13:0 0 (#:13:0 x>) Why isn't the information about the subsequent procedures tracked? Do they all get inlined? regards, M.
Fwd: A (Graph?) database for GNU
Héllo, I foward to you (guile-user) this message that might be of interest, Original Message Subject: A (Graph?) database for GNU Date: 2014-01-01 15:38 From: amz3 To: gnu-misc-disc...@gnu.org Héllo all, First, I know that it's not welcomed to ask people to write free softwares but I lake time and knowledge for this one. I think that someone else can be happy to code such a thing that's why I bring it to GNU community attention. As far as I know there is no database in GNU except gdbm (http://www.gnu.org.ua/software/gdbm/) but it lakes a lot of the features needed to build reliable programs on top of it among which transactions. To my mind, if a database has to be built for GNU it must be an ACID graph database (graphdbs). This is the kind of database that solve the general problem: - it's relational - schema free To be fully reliable transactions must be able to span over several elements. Graph databases share a lot with object oriented (OO) databases. OO databases are not as good as graphdbs for relational data. There is already several free graph databases that meets those criteria http://www.neo4j.org/ is the most popular, http://www.orientdb.org/ is another one (mvcc based). Both are written in Java. Recently, Oracle claimed to have it too. Manyfolds reasons allow me to think that such a database written in C will be a very useful and very successful project. *I warmly recommend any GNU hacker with interest in this particular domain to consider such a project*. I did some research and experiments in Python, I only highlight things that can be useful: - Notes about the design of a graph database http://hypermove.net/notes/projects/graphitidb.html - A graph database written on top of berkley db, with an introduction to graphdbs API https://github.com/python-graph-lovestory/ajgu-graphdb - A graph database server written in Java with Scheme and Python scripting powers https://github.com/python-graph-lovestory/Java-GraphitiDB - Documentation of Blueprints' Python bindings, with an introduction to graphdbs API https://python-graph-lovestory.readthedocs.org/en/latest/blueprints.html - Not written by me, functional DSL/API for graphdbs https://github.com/tinkerpop/gremlin/wiki Sadly or not, I have no application that can show of the capabilities of graph databases. Like I said above graphdbs solve the general problem, so any project can use graphdbs: web, non-web and else. This doesn't mean that it is the best solution for a given a problem (e.g. log structured data) but in a lot of situation it is a better solution because it's more flexible. And always the best solution when prototyping. Here is list of possible projects involving graph that will help popularize graphdbs: 1) graph datastructure using the glib 2) graph datastructure for Guile 3) persistent/functional graph datastructure for Guile (cf. https://github.com/ijp/fectors) 4) graph database on top of gdbm (in Guile?) 5) graph database on top of berkleydb in Guile 6) an embeddable ACID graph database with Guile bindings 7) a ACID graph database server with at least Guile querying support Spread the word! Comments welcome! :) Thanks, -- amz3 ~ http://hypermove.net/