Re: [Chicken-users] low level strings
Am 06.09.2005, 15:56 Uhr, schrieb Michael Benfield [EMAIL PROTECTED]: Is it possible within Scheme code to get pointers to Scheme strings that can be passed to C? I don't want to just pass it as a c-string; I need [...] Just pass the string as a scheme-object and manipulate it by hand then. Example: $ cat my-string-ref.scm (define my-string-ref (foreign-lambda* scheme-object ((scheme-object str) (int idx)) #EOD if (C_stringp(str) != C_SCHEME_TRUE || idx 0 || idx C_header_size(str)) return C_SCHEME_FALSE; else return C_make_character(C_c_string(str)[idx]); EOD )) (define-macro (show-eval expr) `(begin (display ;; ) (write ',expr) (newline) (write ,expr) (newline))) (define my-string Hello world!) (show-eval (my-string-ref 'my-string 0)) (show-eval (my-string-ref my-string -42)) (show-eval (my-string-ref my-string +42)) (show-eval (my-string-ref my-string +06)) $ csc -O2 -d0 my-string-ref.scm -o my-string-ref $ ./my-string-ref ;; (my-string-ref (quote my-string) 0) #f ;; (my-string-ref my-string -42) #f ;; (my-string-ref my-string 42) #f ;; (my-string-ref my-string 6) #\w ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Bug in the numbers egg?
Hello, thank you for the patch. I don't even think it is too slow, as it is still comparable in speed with dc, which is really fast. With this problem removed, the numbers egg is really cool! cu, Thomas Chust Alex Shinn wrote: At Wed, 10 Aug 2005 20:37:21 -0500, Alex Shinn wrote: (define (power base e) ; like expt but e must be an integer Might as well go all the way. Attached is a patch to numbers-base.scm which modifies the above power function to work on any real numbers and defines the default expt case in terms of that. It's not the fastest implementation but it's probably better to be correct first then optimize later. ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] SQLite3 bindings
Hello, I fixed two type conversion problems in the sqlite3 egg. The new version is available at the same place as the old one. cu, Thomas Chust Thomas Chust wrote: [...] The egg is available at http://www.chust.org/projects/sqlite3.egg, the documentation, which is also included in the egg, at http://www.chust.org/projects/sqlite3.html. [...] ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Bug in the numbers egg?
Hello, consider the following example session: $ csi ___ _ __ / ___/ / (_)___/ /_ ___ / /__/ _ \/ / __/ '_/ -_) _ \ \___/_//_/_/\__/_/\_\\__/_//_/ Version 2, Build 104 - macosx-unix-gnu-ppc - [ dload ] (c)2000-2005 Felix L. Winkelmann #;1 (use numbers) ; loading /usr/local/lib/chicken/numbers.scm ... ; loading /usr/local/lib/chicken/numbers-base.so ... #;2 (expt 10 100) 10110891155767964156222877689497504522960006971153529700550125477736178357726682741211136 This result is apparently wrong. Nevertheless it has the correct magnitude. I wonder whether this is some kind of amplified rounding error or a more serious problem. Any idea or work around is appreciated. cu, Thomas Chust ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Bug in the numbers egg?
John.Cowan wrote: [...] According to the GMP home page at http://swox.com/gmp/ , many versions of gcc miscompile GMP due to too-aggressive optimizations. We may need another library (or, Ghu forbid, a different C compiler). Try reinstalling libgmp from source. Hello, as a matter of fact, I had gmp 4.1.4 installed from source anyway, but I just rerun the test suite of the library and it worked flawlessly -- so the problem must lie somewhere else. I suppose the expt code should be the culprit because the following works: $ csi ___ _ __ / ___/ / (_)___/ /_ ___ / /__/ _ \/ / __/ '_/ -_) _ \ \___/_//_/_/\__/_/\_\\__/_//_/ Version 2, Build 104 - macosx-unix-gnu-ppc - [ dload ] (c)2000-2005 Felix L. Winkelmann #;1 (use numbers) ; loading /usr/local/lib/chicken/numbers.scm ... ; loading /usr/local/lib/chicken/numbers-base.so ... #;2 (do ((n 1 (* n 10)) (i 0 (add1 i))) ((= i 100) n)) 1 cu, Thomas Chust ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] SQLite3 bindings
Hello, as the API for SQLite changed significantly from version 2.x to 3.x because stronger typing was made possible as well as BLOB support, I thought it may be nice to have a CHICKEN binding for the new API as well as the old one. The egg is available at http://www.chust.org/projects/sqlite3.egg, the documentation, which is also included in the egg, at http://www.chust.org/projects/sqlite3.html. I have done some basic tests with the code but its most likely not bug-free yet, so feel free to report any problems. cu, Thomas Chust ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] External representation of strings with non-printable characters
Hello, I just came across this slightly strange behaviour of CHICKEN on a terminal: $ csi __ __ ____ | | |--.|__|..| |--.-.-. | ---| || || __||| -__| | |__|__|__||__||||__|__|_|__|__| Version 2, Build 101 - macosx-unix-gnu-ppc - [ dload ] (c)2000-2005 Felix L. Winkelmann #;1 (define str (string #\nul #\x02 #\1)) #;2 (string-list str) (#\nul #\x2 #\1) #;3 str \\1 #;4 (string-list \\1) (#\\ #\1) #;5 (string-list \x00\x021) (#\nul #\x2 #\1) Similar behaviour can also be seen if you apply string-symbol to the above string and write the symbol. Although writing all sorts of special characters to the output port as themselves works fine for file ports, terminals may get confused by this. I think it would be nicer to output characters 32 and 128 as hexadecimal or octal escape sequences, at least on a terminal port. cu, Thomas Chust ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] non-blocking (read)
Hello, why don't you just use (file-select ...) on the STDIN descriptor (descriptor number 0) directly? You could also cook up some code using fcntl to switch descriptor 0 into non-blocking mode, checking for EWOULDBLOCK returns from read calls and ensuring proper multithreading with the builtin ##sys#thread-block-for-i/o primitive. For an example how that can be done and neatly wrapped into a custom input port, I suggest you read the sourcecode of CHICKEN's tcp unit. cu, Thomas Chust ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] foreign-lambda* ?
Raffael Cavallaro wrote: [...] Can someone provide a simple 5 line example of how to correctly embed C code in Scheme using foreign-lambda* and/or friends? Just a simple function will do. I'm trying to figure out a persistent linker error when I use these, and I want to make sure It isn't my test code that is the problem. [...] Hello, you could try something along these lines: imurph:~ murphy$ csi -version __ __ ____ | | |--.|__|..| |--.-.-. | ---| || || __||| -__| | |__|__|__||__||||__|__|_|__|__| Version 1, Build 942 - macosx-unix-gnu-ppc - [ dload ] (c)2000-2005 Felix L. Winkelmann imurph:~ murphy$ cat flt.scm (define my-strlen (foreign-lambda* int ((c-string str)) int n = 0; while(*(str++)) ++n; return(n);)) (print (my-strlen one two three)) ; prints 13 imurph:~ murphy$ csc -O2 -v -o flt flt.scm /usr/local/bin/chicken flt.scm -output-file flt.c -quiet -optimize-level 2 gcc flt.c -o flt.o -DHAVE_CHICKEN_CONFIG_H -Os -fomit-frame-pointer -fno-strict-aliasing -Wall -Wno-unused -Wno-uninitialized -DHAVE_ALLOCA_H -no-cpp-precomp -DC_STACK_GROWS_DOWNWARD=1 -DC_INSTALL_LIB_HOME=\/usr/local/lib/chicken\ -DC_INSTALL_HOME=\/usr/local/share/chicken\ -DC_USE_C_DEFAULTS -c -DC_NO_PIC_NO_DLL rm flt.c gcc -o flt flt.o -lchicken -L/usr/local/lib -ldl -lm -ldl rm flt.o imurph:~ murphy$ ./flt 13 By the way, I'm running Mac OS X 10.4.1 with gcc-4.0 as well, so it shouldn't be a system problem. cu, Thomas Chust ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users