[Chicken-users] Problem with http-client egg sample code
Hi guys, For my next side project, I wanted to use Chicken to improve my knowledge of Scheme, and to see how fast Chicken scheme can get. I installed Chicken on my Mac (Snow Leopard) by compiling from source, since the Macports version gave segmentation faults on installing eggs. Afterwards, I installed the http egg (specifically, this one: http://wiki.call-cc.org/eggref/3/http), and copied the test code for the client into the file test.scm, whose contents look like this: #!/usr/local/bin/csi -s (require-extension http-client) (define-values (h a i o) (http:send-request http://google.com;)) (pretty-print (http:read-body a i)) (close-input-port i) (close-output-port o) Afterwards, I ran ./test.scm in the command line, and got the following error output: Error: unbound variable: http:send-request Call history: make-string make-parameter syntax (define-values (h a i o) (http:send-request http://google.com;)) syntax (##sys#call-with-values (##core#lambda () (http:send-request http://google.com;)) (##core#lambda (h.. syntax (##core#lambda () (http:send-request http://google.com;)) syntax (##core#begin (http:send-request http://google.com;)) syntax (http:send-request http://google.com;) syntax (##core#lambda (h176 a177 i178 o179) (##core#set! h h176) (##core#set! a a177) (##core#set! i i178) ... syntax (##core#begin (##core#set! h h176) (##core#set! a a177) (##core#set! i i178) (##core#set! o o179)) syntax (##core#set! h h176) syntax (##core#set! a a177) syntax (##core#begin (##core#set! i i178) (##core#set! o o179)) syntax (##core#set! i i178) syntax (##core#set! o o179) eval(##sys#call-with-values (##core#lambda () (http:send-request http://google.com;)) (##core#lambda (h.. eval(http:send-request http://google.com;) -- What am I doing wrong here? Thanks in advance for any help ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Problem with http-client egg sample code
Hi Ulas, On Thu, 24 May 2012 13:40:43 +0200 Ulas Türkmen afroisalready...@googlemail.com wrote: For my next side project, I wanted to use Chicken to improve my knowledge of Scheme, and to see how fast Chicken scheme can get. I installed Chicken on my Mac (Snow Leopard) by compiling from source, since the Macports version gave segmentation faults on installing eggs. Afterwards, I installed the http egg (specifically, this one: http://wiki.call-cc.org/eggref/3/http), and copied the test code for the client into the file test.scm, whose contents look like this: #!/usr/local/bin/csi -s (require-extension http-client) (define-values (h a i o) (http:send-request http://google.com;)) (pretty-print (http:read-body a i)) (close-input-port i) (close-output-port o) Afterwards, I ran ./test.scm in the command line, and got the following error output: Error: unbound variable: http:send-request Call history: make-string make-parameter syntax (define-values (h a i o) (http:send-request http://google.com;)) syntax (##sys#call-with-values (##core#lambda () (http:send-request http://google.com;)) (##core#lambda (h.. syntax (##core#lambda () (http:send-request http://google.com;)) syntax (##core#begin (http:send-request http://google.com;)) syntax (http:send-request http://google.com;) syntax (##core#lambda (h176 a177 i178 o179) (##core#set! h h176) (##core#set! a a177) (##core#set! i i178) ... syntax (##core#begin (##core#set! h h176) (##core#set! a a177) (##core#set! i i178) (##core#set! o o179)) syntax (##core#set! h h176) syntax (##core#set! a a177) syntax (##core#begin (##core#set! i i178) (##core#set! o o179)) syntax (##core#set! i i178) syntax (##core#set! o o179) eval(##sys#call-with-values (##core#lambda () (http:send-request http://google.com;)) (##core#lambda (h.. eval(http:send-request http://google.com;) -- What am I doing wrong here? It seems that you are using an egg from CHICKEN version 3, which is pretty old and not maintained anymore. The /eggref/3 part in the URL indicates that it is a CHICKEN 3 egg. The current major version is 4. You can get it from http://code.call-cc.org Check http://wiki.call-cc.org/eggref/4/http-client for the http-client for version 4 of CHICKEN. You can install it with: $ chicken-install http-client `chicken-install' is the egg management tool for version 4. If you have `chicken-setup', you have a CHICKEN version 3. I hope that helps. Best wishes. Mario -- http://parenteses.org/mario ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Problem with http-client egg sample code
Hi Mario, Thanks a lot for you quick response. This solved the problem. Cheers, Ulas On Thu, May 24, 2012 at 1:59 PM, Mario Domenech Goulart mario.goul...@gmail.com wrote: Hi Ulas, On Thu, 24 May 2012 13:40:43 +0200 Ulas Türkmen afroisalready...@googlemail.com wrote: For my next side project, I wanted to use Chicken to improve my knowledge of Scheme, and to see how fast Chicken scheme can get. I installed Chicken on my Mac (Snow Leopard) by compiling from source, since the Macports version gave segmentation faults on installing eggs. Afterwards, I installed the http egg (specifically, this one: http://wiki.call-cc.org/eggref/3/http), and copied the test code for the client into the file test.scm, whose contents look like this: #!/usr/local/bin/csi -s (require-extension http-client) (define-values (h a i o) (http:send-request http://google.com;)) (pretty-print (http:read-body a i)) (close-input-port i) (close-output-port o) Afterwards, I ran ./test.scm in the command line, and got the following error output: Error: unbound variable: http:send-request Call history: make-string make-parameter syntax (define-values (h a i o) (http:send-request http://google.com;)) syntax (##sys#call-with-values (##core#lambda () (http:send-request http://google.com;)) (##core#lambda (h.. syntax (##core#lambda () (http:send-request http://google.com;)) syntax (##core#begin (http:send-request http://google.com;)) syntax (http:send-request http://google.com;) syntax (##core#lambda (h176 a177 i178 o179) (##core#set! h h176) (##core#set! a a177) (##core#set! i i178) ... syntax (##core#begin (##core#set! h h176) (##core#set! a a177) (##core#set! i i178) (##core#set! o o179)) syntax (##core#set! h h176) syntax (##core#set! a a177) syntax (##core#begin (##core#set! i i178) (##core#set! o o179)) syntax (##core#set! i i178) syntax (##core#set! o o179) eval (##sys#call-with-values (##core#lambda () (http:send-request http://google.com;)) (##core#lambda (h.. eval (http:send-request http://google.com;) -- What am I doing wrong here? It seems that you are using an egg from CHICKEN version 3, which is pretty old and not maintained anymore. The /eggref/3 part in the URL indicates that it is a CHICKEN 3 egg. The current major version is 4. You can get it from http://code.call-cc.org Check http://wiki.call-cc.org/eggref/4/http-client for the http-client for version 4 of CHICKEN. You can install it with: $ chicken-install http-client `chicken-install' is the egg management tool for version 4. If you have `chicken-setup', you have a CHICKEN version 3. I hope that helps. Best wishes. Mario -- http://parenteses.org/mario ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] chicken-bind: working with structs
Hi guys! I've been looking at chicken-bind's way of working with C-structs for a while now, and I'm in the works of something I think will be useful. I want to have chicken-bind generate code for struct-by-values. Thanks to all who helped me out in this tricky process! *Allocating memory for new structs* Chicken-bind needs to allocate structs: 1. In its make-struct construct 2. When a function returns a struct by value 3. When a struct has a struct field (aka nested structs, effectively a struct-by-value return type) I have decided to use make-blob to allocate memory in all cases because it's easy and seems to have very good performance. I haven't looked at the code, but I believe make-blob allocates on the stack whenever it can. I have made a new version of chicken-bind's make-struct which now uses make-blob, replacing the old C_malloc. Please take a peek at https://github.com/kristianlm/chicken-bind/commit/f7dde10bdb40aa00ae776f23570aa1001ddde26d. I like the set-point! naming convention but I'm open to suggestions of course. *Struct-by-value return type =? locative* You typically have code like this: struct point {float x,y}; float distance (point *a, point *b); To use distance, you wanna do something like: (distance (make-point 1 2) (make-point 2 3)) This means that all struct-bindings should return types compatible with pointers so they can be used seamlessly on the other functions. The only way I have found to achieve this is to return locatives. It's not ideal because you lose type information at runtime. Any ideas on how to keep this without forcing the user to convert? Do tagged locatives exist, like tagged pointers? *Struct by value return types* This is my proposal: $ echo struct point getPoint(); | chicken-bind - -o - (begin (begin (begin (define getPoint/overwrite! (foreign-lambda* void (((c-pointer (struct point)) dest)) *dest=(getPoint());)) (define (getPoint) (let ((dest (location (make-blob (foreign-value sizeof(struct point) int) (getPoint/overwrite! dest) dest) I wish to export the overwrite-version (and set-point! above) because I assume it can be useful in tight loops where you only need to allocate once. Any objections? And what might be a better name than /overwrite!? *Compatibility* The new patches should not change any behavior except that make-struct now returns a locative instead of a c-pointer. Looking forward to hear your thoughts and get this patch out there! Kris ___ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users