That does clarify things indeed... Thanks! :) Hans
On Monday 14 May 2007 19:19, you wrote: > Hi Hans, > > The problem is that you are not using your new syntax correctly. > Instead of saying > > (newClass 'MyClass) > > you should be saying > > (newClass MyClass) > > > [node second] in your "syntax" evaluates to the symbol object > #MyClass, so when you quote it, you are generating the code > > (define (quote MyClass) [Prototype new]) > > when what you really want is > > (define MyClass [Prototype new]) > > > The error message you are getting has to do with a mechanism built > into the compiler for doing some rewrites automatically. For instance, > when you say > > (set (foo x) 5) > > that gets translated automatically to > > (set-foo x 5) > > Similarly, when the compiler sees > > (define (quote MyClass) [Prototype new]) > > it translates that to > > (define-quote MyClass [Prototype new]) > > > Why does this mechanism even exist? I'll give you an example... > Suppose you want to define some new syntax for accessing a field of an > object without doing a message send: > > (define-type C Object (x)) > > (syntax C-x > (lambda (node compiler) > `(long@ ,[node second] 1))) > > Now you should be able to say things like: > > (define foo [C new]) > (C-x foo) ; access the x field of foo without doing a message send > > Accessing the value of foo's x field is not so useful if you can't set > it... so you'd like to be able to write something like: > > (set (C-x foo) 1234) > > Interestingly, this does the right thing already, without any > additional work. And here's why: your "syntax" translates the > expression above into > > (set (long@ foo 1) 1234) > > When the compiler sees this, it rewrites it to > > (set-long@ foo 1 1234) > > And because set-long@ is understood by the compiler, this expression > compiles to the right thing. So by simply defining a syntax for > accessing a field, we get the setter for free. > > > An even better example of this is the way Jolt deals with method > declarations. When you write > > (define [C m: x] x) > > the compiler desugars the [C m: x] into (send 'm: C x), so the whole > expression turns into > > (define (send 'm: C x) x) > > This is automatically translated to > > (define-send 'm C x x) > > which, if you look inside object.k, means > > (syntax define-send ; selector type args... expr > (lambda (form compiler) > (let ((selector [form second]) > (type [form third]) > (args [form copyFrom: '3 to: [[form size] - '2]]) > (expr [form last])) > `(add-method ,type ,selector (lambda (_closure _self self > ,@args) ,expr))))) > > So, as you can see, there's nothing magic about method declarations in > Jolt... is that cool or what? :) > > Cheers, > Alex > > On 5/14/07, SainTiss <[EMAIL PROTECTED]> wrote: > > Hi all, > > > > I'm trying to create a new node "newClass", which should assign the > > result of a bit of pepsi code to a variable of which the name if provided > > as a parameter to "newClass". > > > > So: > > > > (newClass 'MyClass) > > > > should result in: > > > > (define MyClass [Prototype new]) > > > > I tried to accomplish this using the following piece of jolt code: > > > > (syntax newClass ; (newClass name) > > (lambda (node compiler) > > `(define ,[node second] [Prototype new]))) > > > > But I get the following error: > > > > undefined: define-quote > > > > I can't really trace this back to something I did wrong, but if I replace > > , [node second] by a hardcoded name, I don't get the error. > > > > Did I do something wrong here? > > > > Also, I'm assuming (newClass 'MyClass) is the correct syntax to use my > > new node, but maybe I should use (newClass '"MyClass") or still something > > else? > > > > Thanks, > > > > Hans > > > > -- > > A liberal is a person whose interests aren't at stake at the moment > > -- Willis Player > > > > Hans Schippers > > Research Assistant of the Research Foundation - Flanders (FWO - > > Vlaanderen) http://www.win.ua.ac.be/~hschipp/ > > Formal Techniques in Software Engineering (FoTS) > > University of Antwerp > > Middelheimlaan 1 > > 2020 Antwerpen - Belgium > > Phone: +32 3 265 38 71 > > Fax: +32 3 265 37 77 > > > > _______________________________________________ > > fonc mailing list > > [email protected] > > http://vpri.org/mailman/listinfo/fonc -- A liberal is a person whose interests aren't at stake at the moment -- Willis Player Hans Schippers Research Assistant of the Research Foundation - Flanders (FWO - Vlaanderen) http://www.win.ua.ac.be/~hschipp/ Formal Techniques in Software Engineering (FoTS) University of Antwerp Middelheimlaan 1 2020 Antwerpen - Belgium Phone: +32 3 265 38 71 Fax: +32 3 265 37 77
pgpTmLM7thxe4.pgp
Description: PGP signature
_______________________________________________ fonc mailing list [email protected] http://vpri.org/mailman/listinfo/fonc
