Re: [Chicken-users] C_word type / Cython (warning: passing argument 2 from incompatible pointer type)
From: David Dreisigmeyer Subject: [Chicken-users] C_word type / Cython (warning: passing argument 2 from incompatible pointer type) Date: Fri, 11 Feb 2011 17:47:24 -0500 > Here's the solution on the Cython side. > > Is C_word a long (or int) though? > A long on 64-bit platforms and an int on 32-bit systems. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Implementing a macroexpand-all
> Does anyone know which forms introduce new bindings? How can I check this > up? `let' and `lambda' introduce new bindings. `let' is not transformed into `lambda', it is handled as a primitive. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Using a macro definition within a explicit renaming macro.
> > There may be a shorter way involving begin-for-syntax or something. > (begin-for-syntax (define-syntax ...)) should actually work, but it doesn't. I have to investigate this. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] C_word type / Cython (warning: passing argument 2 from incompatible pointer type)
Thanks Felix, Mt question wasn't clear. What about C_word's use here: int CHICKEN_eval_string (char *str, C_word *result) Wouldn't this be able to return arbitrary results? I was thinking that this is like CHICKEN_eval_string_to_string except an actual scheme expression is returned instead of a string. On Sat, Feb 12, 2011 at 5:11 AM, Felix wrote: > From: David Dreisigmeyer > Subject: [Chicken-users] C_word type / Cython (warning: passing argument 2 > from incompatible pointer type) > Date: Fri, 11 Feb 2011 17:47:24 -0500 > >> Here's the solution on the Cython side. >> >> Is C_word a long (or int) though? >> > > A long on 64-bit platforms and an int on 32-bit systems. > > > cheers, > felix > ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Using a macro definition within a explicit renaming macro.
Thanks for the help. The module workaround will work fine for what I'm doing! -Patrick On Sat, Feb 12, 2011 at 5:36 AM, Felix < fe...@call-with-current-continuation.org> wrote: > > > > There may be a shorter way involving begin-for-syntax or something. > > > > (begin-for-syntax (define-syntax ...)) should actually work, but it > doesn't. I have to investigate this. > > > cheers, > felix > ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Implementing a macroexpand-all
Thanks for the help Felix! There's one more question I stumbled upon actually. Do you know of some way I can tell if a symbol *actually* refers to lambda or let? eg. after some macro expansions, a form might look like (lambda89 (x y) body ...) where lambda89 is equivalent to lambda. Given a symbol, I need to check whether it refers to a macro or not. -Patrick On Sat, Feb 12, 2011 at 5:14 AM, Felix < fe...@call-with-current-continuation.org> wrote: > > Does anyone know which forms introduce new bindings? How can I check this > > up? > > `let' and `lambda' introduce new bindings. `let' is not transformed into > `lambda', it is handled as a primitive. > > > cheers, > felix > ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Implementing a macroexpand-all
On Sat, Feb 12, 2011 at 11:15:31AM -0500, Patrick Li wrote: > Thanks for the help Felix! > > There's one more question I stumbled upon actually. Do you know of some way > I can tell if a symbol *actually* refers to lambda or let? > > eg. after some macro expansions, a form might look like (lambda89 (x y) body > ...) > where lambda89 is equivalent to lambda. After full expansion, you should get ##core#lambda, which is the "core" lambda. To determine whether a renamed symbol like lambda89 refers to a macro, you need to look it up in the syntax environment you've built up till the point where you encounter it. Cheers, Peter -- http://sjamaan.ath.cx -- "The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music." -- Donald Knuth ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Implementing a macroexpand-all
> > After full expansion, you should get ##core#lambda, which is the "core" > lambda. > I didn't understand what you mean by this part. How do I perform a "full expansion"? eg. (define-syntax mymacro (syntax-rules () ((mymacro) (lambda () 3 (expand '(mymacro)) => (lambda1020 () 3) (expand (expand '(mymacro))) => (lambda1020 () 3) How do I get it to expand to: (##core#lambda () 3) -Patrick ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Implementing a macroexpand-all
On Sat, Feb 12, 2011 at 11:52:40AM -0500, Patrick Li wrote: > I didn't understand what you mean by this part. How do I perform a "full > expansion"? > eg. > (define-syntax mymacro (syntax-rules () ((mymacro) (lambda () 3 > > (expand '(mymacro)) > => (lambda1020 () 3) What version of Chicken are you using? I see the following with 4.6.0 and 4.6.5: #;1> (define-syntax mymacro (syntax-rules () ((mymacro) (lambda () 3 #;2> (expand '(mymacro)) (##core#lambda () 3) Cheers, Peter -- http://sjamaan.ath.cx -- "The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music." -- Donald Knuth ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Implementing a macroexpand-all
Ah I'm using Chicken 4.4.0. I'm a beginner to Chicken and just typed "port install chicken" into my MacOSX terminal. I'll figure out how to upgrade Chicken. -Patrick On Sat, Feb 12, 2011 at 12:04 PM, Peter Bex wrote: > On Sat, Feb 12, 2011 at 11:52:40AM -0500, Patrick Li wrote: > > I didn't understand what you mean by this part. How do I perform a "full > > expansion"? > > eg. > > (define-syntax mymacro (syntax-rules () ((mymacro) (lambda () 3 > > > > (expand '(mymacro)) > > => (lambda1020 () 3) > > What version of Chicken are you using? > I see the following with 4.6.0 and 4.6.5: > > #;1> (define-syntax mymacro (syntax-rules () ((mymacro) (lambda () 3 > #;2> (expand '(mymacro)) > (##core#lambda () 3) > > Cheers, > Peter > -- > http://sjamaan.ath.cx > -- > "The process of preparing programs for a digital computer > is especially attractive, not only because it can be economically > and scientifically rewarding, but also because it can be an aesthetic > experience much like composing poetry or music." >-- Donald Knuth > ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] C_word type / Cython (warning: passing argument 2 from incompatible pointer type)
C_word is the fundamental scheme object type. The underlying type of int or long is just used to make the width of this type 32-bit or 64-bit, and the actual representation is indicated by a type tag (some subset of bits in that word). So it actually can return an arbitrary result. See Data Representation in the manual for details. Jim On Feb 12, 2011, at 6:47, David Dreisigmeyer wrote: > Thanks Felix, > > Mt question wasn't clear. What about C_word's use here: > > int CHICKEN_eval_string (char *str, C_word *result) > > Wouldn't this be able to return arbitrary results? I was thinking > that this is like CHICKEN_eval_string_to_string except an actual > scheme expression is returned instead of a string. > > > On Sat, Feb 12, 2011 at 5:11 AM, Felix > wrote: >> From: David Dreisigmeyer >> Subject: [Chicken-users] C_word type / Cython (warning: passing argument 2 >> from incompatible pointer type) >> Date: Fri, 11 Feb 2011 17:47:24 -0500 >> >>> Here's the solution on the Cython side. >>> >>> Is C_word a long (or int) though? >>> >> >> A long on 64-bit platforms and an int on 32-bit systems. >> >> >> cheers, >> felix >> > > ___ > Chicken-users mailing list > Chicken-users@nongnu.org > http://lists.nongnu.org/mailman/listinfo/chicken-users ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Implementing a macroexpand-all
On Sat, Feb 12, 2011 at 12:18:30PM -0500, Patrick Li wrote: > Ah I'm using Chicken 4.4.0. > I'm a beginner to Chicken and just typed "port install chicken" into my > MacOSX terminal. > I'll figure out how to upgrade Chicken. If you have more questions, it may be more efficient to continue the conversation on IRC. Cheers, Peter -- http://sjamaan.ath.cx -- "The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music." -- Donald Knuth ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Implementing a macroexpand-all
Thanks for the help! I upgraded to 4.6.0 and everything's fine now. -Patrick On Sat, Feb 12, 2011 at 12:55 PM, Peter Bex wrote: > On Sat, Feb 12, 2011 at 12:18:30PM -0500, Patrick Li wrote: > > Ah I'm using Chicken 4.4.0. > > I'm a beginner to Chicken and just typed "port install chicken" into my > > MacOSX terminal. > > I'll figure out how to upgrade Chicken. > > If you have more questions, it may be more efficient to continue the > conversation on IRC. > > Cheers, > Peter > -- > http://sjamaan.ath.cx > -- > "The process of preparing programs for a digital computer > is especially attractive, not only because it can be economically > and scientifically rewarding, but also because it can be an aesthetic > experience much like composing poetry or music." >-- Donald Knuth > ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Implementing a macroexpand-all
Thank you for everyone's help! I scrounged together a half-working implementation of macroexpand-all. It recursively macroexpands all the subforms within a form until there are absolutely no macros left in the expression. This is a temporary solution for whoever needs it, as I think Felix probably already has this implemented somewhere in the Chicken scheme system (because the compiler needs it I think) and just haven't exposed it for public use yet. Known Limitations: (1) It does not work if you call it with fundamental macros ALREADY shadowed by existing local bindings. A contrived example of shooting oneself in the foot: (let ((let (fn (x) x))) (macroexpand-all '(let 10))) This will STILL try to expand the "let" inside the form, because macroexpand-all does not know about the "let" binding introduced before the call to macroexpand-all. (2) It does not work if the given form contains local macro definitions, or subforms that expand to local macro definitions. I imagine this will take some work and I just haven't gotten around to doing this yet. -Patrick ;; ;; MACRO EXPAND ;;Helper Function for macroexpanding an expression with a list of known bound symbols. ;;Symbols are assumed to be NOT bound to macros. So this implementation does not work ;;with local macros. (define (-macroexpand-all bound-symbols expression) (define (recurse-macroexpand-all bound-symbols expression) (cons (-macroexpand-all bound-symbols (car expression)) (-macroexpand-all bound-symbols (cdr expression (define (get-symbols binding) (cond ((null? binding) '()) ((pair? binding) (append (get-symbols (car binding)) (get-symbols (cdr binding (else (list binding (if (pair? expression) (let ((head (car expression)) (tail (cdr expression))) (cond ;;((...) ...) ((pair? head) (recurse-macroexpand-all bound-symbols expression)) ;;Bound Symbol ((memq head bound-symbols) (recurse-macroexpand-all bound-symbols expression)) ;;Quoted Expression ((eq? head '##core#quote) expression) ;;Lambda Expression ((eq? head '##core#lambda) (let* ((bindings (cadr expression)) (body (cddr expression)) (new-symbols (append (get-symbols bindings) bound-symbols))) (cons head (cons bindings (recurse-macroexpand-all new-symbols body) ;;Let Form ((eq? head '##core#let) (let* ((bindings (cadr expression)) (body (cddr expression)) (new-symbols (append (map car bindings) bound-symbols)) (expanded-bindings (map (lambda (b) (list (car b) (-macroexpand-all bound-symbols (cadr b bindings))) (cons head (cons expanded-bindings (recurse-macroexpand-all new-symbols body) ;;Normal Form just expand it (else (recurse-macroexpand-all bound-symbols (expand expression) expression)) ;;Macroexpand-All (define (macroexpand-all expression) (-macroexpand-all '() expression)) On Sat, Feb 12, 2011 at 2:08 PM, Patrick Li wrote: > Thanks for the help! I upgraded to 4.6.0 and everything's fine now. > -Patrick > > > On Sat, Feb 12, 2011 at 12:55 PM, Peter Bex wrote: > >> On Sat, Feb 12, 2011 at 12:18:30PM -0500, Patrick Li wrote: >> > Ah I'm using Chicken 4.4.0. >> > I'm a beginner to Chicken and just typed "port install chicken" into my >> > MacOSX terminal. >> > I'll figure out how to upgrade Chicken. >> >> If you have more questions, it may be more efficient to continue the >> conversation on IRC. >> >> Cheers, >> Peter >> -- >> http://sjamaan.ath.cx >> -- >> "The process of preparing programs for a digital computer >> is especially attractive, not only because it can be economically >> and scientifically rewarding, but also because it can be an aesthetic >> experience much like composing poetry or music." >>-- Donald Knuth >> > > ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Help solving this phasing problem.
Hello everyone, I'm creating a module that exports two things, a macro and a function. The definition of the macro happens to require the use of the function. I am having problems creating this module. The defined macro cannot access the function. --Example-- (module tempmodule (convenience-function my-macro) (import chicken scheme) (define (convenience-function) (display "do convenience things\n")) (define-syntax my-macro (lambda (expression rename comparison) (convenience-function) "My Macro Output")) );;END MODULE (import tempmodule) (my-macro) => Error: during expansion of (my-macro ...) - unbound variable: convenience-function --- I have a *very* ugly workaround right now. I define the convenience function twice. Once normally. And again within a begin-for-syntax form. ---Example- (module tempmodule (convenience-function my-macro) (import chicken scheme) (define (convenience-function) (display "do convenience things\n")) (begin-for-syntax (define (convenience-function) (display "do convenience things\n"))) (define-syntax my-macro (lambda (expression rename comparison) (convenience-function) "My Macro Output")) );;END MODULE --- I would appreciate your help if someone knows how to solve this problem properly. Thank you! -Patrick ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Help solving this phasing problem.
On Sat, Feb 12, 2011 at 04:35:23PM -0500, Patrick Li wrote: > > I have a *very* ugly workaround right now. > I define the convenience function twice. Once normally. And again within a > begin-for-syntax form. You can do the same trick as before: (module module-a (convenience-function) (import chicken scheme) (define (convenience-function) (display "do convenience things\n"))) (module module-b (my-macro convenience-function) (import chicken scheme module-a) (import-for-syntax module-a) (define-syntax my-macro (lambda (expression rename comparison) (convenience-function) "My Macro Output"))) This imports module-a (which can be internal and nobody has to know it's there) both for syntax and normally, and then re-exports the convenience function. Yes, this is ugly. Cheers, Peter -- http://sjamaan.ath.cx -- "The process of preparing programs for a digital computer is especially attractive, not only because it can be economically and scientifically rewarding, but also because it can be an aesthetic experience much like composing poetry or music." -- Donald Knuth ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Help solving this phasing problem.
Thanks Peter. That's perfectly good enough. As long as I'm not repeating myself and it's transparent to the user, I can live with it. You've been very helpful. -Patrick On Sat, Feb 12, 2011 at 4:51 PM, Peter Bex wrote: > On Sat, Feb 12, 2011 at 04:35:23PM -0500, Patrick Li wrote: > > > > I have a *very* ugly workaround right now. > > I define the convenience function twice. Once normally. And again within > a > > begin-for-syntax form. > > You can do the same trick as before: > > (module module-a (convenience-function) > (import chicken scheme) > > (define (convenience-function) > (display "do convenience things\n"))) > > (module module-b (my-macro convenience-function) > (import chicken scheme module-a) > (import-for-syntax module-a) > (define-syntax my-macro >(lambda (expression rename comparison) > (convenience-function) > "My Macro Output"))) > > This imports module-a (which can be internal and nobody has to know it's > there) both for syntax and normally, and then re-exports the convenience > function. > > Yes, this is ugly. > > Cheers, > Peter > -- > http://sjamaan.ath.cx > -- > "The process of preparing programs for a digital computer > is especially attractive, not only because it can be economically > and scientifically rewarding, but also because it can be an aesthetic > experience much like composing poetry or music." >-- Donald Knuth > > ___ > Chicken-users mailing list > Chicken-users@nongnu.org > http://lists.nongnu.org/mailman/listinfo/chicken-users > ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Help solving this phasing problem.
On Sat, Feb 12, 2011 at 16:51, Peter Bex wrote: > This imports module-a (which can be internal and nobody has to know it's > there) both for syntax and normally, and then re-exports the convenience > function. Pardon the interruption, but I wanted to check for my own understanding: is import-for-syntax roughly the Chicken equivalent of the (import (for (module-a) expand)) from chapter 7 of R6RS? (That may be an oversimplification on my part, this gets into some of the parts of Scheme I don't understand very well yet.) Thanks, -- Taylor C. Venable http://metasyntax.net/ ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users