[Chicken-users] easyffi usage
Hi, I'm learning how to use the easyffi.egg. With the following code: (foreign-declare " double my_pi; ") (foreign-parse " double my_pi = 3.14; ") (print (sin my_pi)) Built with `csc -X easyffi foo.scm', when I try to run it, i got: , | Error: (sin) bad argument type - not a number: # ` What's the problem here? Also, the first example at http://chicken.wiki.br/easyffi#usage seems not very good: 1) Both math.h and csi have defined "sin" function, one can't verify that he'd call "sin" from which. 2) It defined "#define my_pi 3.14" first, but the call "(print (sin 3.14))" doesn't use my_pi at all. So i doubt the following clam that it'll generated this equivalent code: (define-foreign-variable my_pi float "my_pi") -- William http://williamxu.net9.org You can fool all the people all of the time if the advertising is right and the budget is big enough. -- Joseph E. Levine ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] easyffi usage
William Xu wrote: [...] (foreign-declare " double my_pi; ") (foreign-parse " double my_pi = 3.14; ") (print (sin my_pi)) [...] Hello, if I'm not mistaken, easyffi generates parameter style procedures to acces global C variables, probably because it is impossible in CHICKEN to create "magic" Scheme variables that map directly to C variables. Therefore the correct way to use my_pi in your example would be (print (sin (my_pi))) As my_pi isn't declared constant you could also modify its value using a call like (my_pi 3.1415) cu, Thomas ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Re: easyffi usage
Thomas Chust <[EMAIL PROTECTED]> writes: > if I'm not mistaken, easyffi generates parameter style procedures to acces > global C variables, probably because it is impossible in CHICKEN to create > "magic" Scheme variables that map directly to C variables. > > Therefore the correct way to use my_pi in your example would be > > (print (sin (my_pi))) Hm, this seems hiding the error. Now, my_pi is 0.0, ... (use format-modular) (display (format "(my_pi) = ~A, (sin (my_pi)) = ~A\n" (my_pi) (sin (my_pi => (my_pi) = 0.0, (sin (my_pi)) = 0.0 -- William http://williamxu.net9.org ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] getopt, getopt_long?
Hi, Does chicken have some egg for wrapping getopt, getopt_long? -- William http://williamxu.net9.org Men are always ready to respect anything that bores them. -- Marilyn Monroe ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] getopt, getopt_long?
2008/7/8 William Xu <[EMAIL PROTECTED]>: > Hi, > > Does chicken have some egg for wrapping getopt, getopt_long? I don't know specifically for getopt, but you might be interested by http://chicken.wiki.br/tool or http://chicken.wiki.br/args-doc. Cheers, Thu ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Re: easyffi usage
William Xu wrote: [...] Hm, this seems hiding the error. Now, my_pi is 0.0, [...] Hello, well, of course my_pi is zero in your code, because you never set its value to anything else than its default initializer, which is zero in almost any sensible C compiler. You write (foreign-declare " double my_pi; ") (foreign-parse " double my_pi = 3.14; ") which means "Include 'double my_pi;' verbatim in the C code, parse 'double my_pi = 3.14' as a C declaration and generate Scheme bindings for it". The parser of easyffi discards the initializer, because it is none of its business to deal with it. That would be the job of the C compiler, but the C compiler never gets to see the constant 3.14. You should either write (foreign-parse " double my_pi; ") (foreign-declare " double my_pi = 3.14; ") or simply (foreign-parse/declare " double my_pi = 3.14; ") to achieve the desired effect. cu, Thomas ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] getopt, getopt_long?
The args egg provides getopt-like functionality: (require-extension args) (define opt_v #f) (define opts `( ,(args:make-option (v) #:none "set verbose mode" (set! opt_v #t)) ,(args:make-option (h help) #:none "Print help" (usage ;; Use args:usage to generate a formatted list of options (from OPTS), ;; suitable for embedding into help text. (define (usage) (print "Usage: " (car (argv)) " [options...] commands ") (newline) (print "The following options are recognized: ") (newline) (print (parameterize ((args:indent 5)) (args:usage opts))) (exit 1)) ;; Process arguments and collate options and arguments into OPTIONS ;; alist, and operands (filenames) into OPERANDS. You can handle ;; options as they are processed, or afterwards. (set!-values (options operands) (args:parse (command-line-arguments) opts)) William Xu <[EMAIL PROTECTED]> writes: > Hi, > > Does chicken have some egg for wrapping getopt, getopt_long? -- "Their eyes met, and his heart soared, like the price of gas before a long weekend." --Cornered, by Mike Baldwin ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Re: easyffi usage
Thomas Chust <[EMAIL PROTECTED]> writes: > which means "Include 'double my_pi;' verbatim in the C code, parse 'double > my_pi > = 3.14' as a C declaration and generate Scheme bindings for it". The parser of > easyffi discards the initializer, because it is none of its business to deal > with it. That would be the job of the C compiler, but the C compiler never > gets > to see the constant 3.14. That clarifies my question. Thanks a lot! -- William http://williamxu.net9.org There are many people today who literally do not have a close personal friend. They may know something that we don't. They are probably avoiding a great deal of pain. ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Re: getopt, getopt_long?
Ivan Raikov <[EMAIL PROTECTED]> writes: > The args egg provides getopt-like functionality: Hmm, i tried both srfi-37 and args, both don't seem very satisfactory. For example, in the following code, "file" option requires an arg, but when I run as it "./foo -f", it can't detect the missing required arg at all... (define opts `( ,(args:make-option (v) #:none "set verbose mode" (set! opt_v #t)) ,(args:make-option (h help) #:none "Print help" (usage)) ,(args:make-option (f file) #:required "filename, required" (print "Did it detect missing required arg and shout?")) )) -- William http://williamxu.net9.org ... of course, this probably only happens for tcsh which uses wait4(), which is why I never saw it. Serves people who use that abomination right 8^) -- Linus Torvalds, about a patch that fixes getrusage for 1.3.26 ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] Re: getopt, getopt_long?
That appears to be a bug in srfi-37 or args, thanks for catching it. I will look at fixing it later today. Other than that, what doesn't seem very satisfactory? -Ivan William Xu <[EMAIL PROTECTED]> writes: > > Hmm, i tried both srfi-37 and args, both don't seem very satisfactory. > For example, in the following code, "file" option requires an arg, but > when I run as it "./foo -f", it can't detect the missing required arg at > all... > > (define opts > `( > ,(args:make-option (v) #:none "set verbose mode" > (set! opt_v #t)) > ,(args:make-option (h help) #:none "Print help" > (usage)) > > ,(args:make-option (f file) #:required "filename, required" > (print "Did it detect missing required arg and shout?")) > > )) ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Re: getopt, getopt_long?
Ivan Raikov <[EMAIL PROTECTED]> writes: > That appears to be a bug in srfi-37 or args, thanks for catching > it. I will look at fixing it later today. Great! > Other than that, what doesn't seem very satisfactory? Nothing more at present. I'll give it a try again after your fix. :-) -- William http://williamxu.net9.org Proboscis: The rudimentary organ of an elephant which serves him in place of the knife-and-fork that Evolution has as yet denied him. For purposes of humor it is popularly called a trunk. -- Ambrose Bierce ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users