Re: [Chicken-users] C_truep( C_fixnump( w ))
On Feb 25, 2008, at 5:55 AM, felix winkelmann wrote: On Mon, Feb 25, 2008 at 1:28 PM, Heinrich Taube <[EMAIL PROTECTED]> wrote: thank you both very much. just to be sure: (1) should i be using a C_truep() around C_immediatep() like the other predicate tests or is this ok: if ( C_immediatep(w) ) { if ( C_truep(C_fixnump(w)) ) { ... } else if ( C_truep(C_blockp(w)) && C_truep( C_flonump ( w ) )) { Yes, this is correct. It is obviously inconsistent, but C_immediatep was intended to be used from C and C_fixnump from compiled code. Changing this will break old (compiled) code. I didn't bother to check for immediate or block since 1) We assume it is a Chicken numeric value 2) An immediate value is an invalid address of a block/special item 3) So checking 1st for a fixnum & then for flonum is enough but real argument checking should be more stringent than my example. (2) how can i test for strictly #f #t boolean value inside the immedatep clause? (x == C_SCHEME_FALSE || x == C_SCHEME_TRUE) #define C_truep(x) ((x) != C_SCHEME_FALSE) Most of the C_*p are wrapped in a C_mk_bool which is why I used C_truep for the test. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users Best Wishes, Kon ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] C_truep( C_fixnump( w ))
On Mon, Feb 25, 2008 at 1:28 PM, Heinrich Taube <[EMAIL PROTECTED]> wrote: > thank you both very much. just to be sure: > > (1) should i be using a C_truep() around C_immediatep() like the other > predicate tests or is this ok: > > if ( C_immediatep(w) ) { >if ( C_truep(C_fixnump(w)) ) { >... >} > > else if ( C_truep(C_blockp(w)) && C_truep( C_flonump( w ) )) { > Yes, this is correct. It is obviously inconsistent, but C_immediatep was intended to be used from C and C_fixnump from compiled code. Changing this will break old (compiled) code. > > (2) how can i test for strictly #f #t boolean value inside the > immedatep clause? > (x == C_SCHEME_FALSE || x == C_SCHEME_TRUE) cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] C_truep( C_fixnump( w ))
thank you both very much. just to be sure: (1) should i be using a C_truep() around C_immediatep() like the other predicate tests or is this ok: if ( C_immediatep(w) ) { if ( C_truep(C_fixnump(w)) ) { ... } else if ( C_truep(C_blockp(w)) && C_truep( C_flonump( w ) )) { (2) how can i test for strictly #f #t boolean value inside the immedatep clause? ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] C_truep( C_fixnump( w ))
On Sun, Feb 24, 2008 at 8:15 PM, Jim Ursetto <[EMAIL PROTECTED]> wrote: > On 2/24/08, Heinrich Taube <[EMAIL PROTECTED]> wrote: > > im sure this must be something stupid but i dont understand why it > > crashes if its not float data > > > > C_word w = C_u_i_car( lyst ); > > if (C_truep( C_flonump( w ) )) { > > > Heinrich, > > Try if (C_truep(C_blockp(w)) && C_truep(C_flonump(w))) {...} > and see if it helps. > > Since you're doing this completely in C, you don't really > have to convert to a scheme boolean either: > > if (!C_immediatep(w) && C_block_header(x) == C_FLONUM_TAG) { ... } > > Right. C_flonump does not check whether the argument is non-immediate and fetches the header of the object pointed to. If the argument is immediate it naturally will not point to a valid block. This may appear as some kind of premature optimization, but doing the check in the C_flonump macro would evaluate the argument twice, and this might result in invalid behaviour in case the argument is a ("direct") call to an optimized function. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] C_truep( C_fixnump( w ))
On 2/24/08, Heinrich Taube <[EMAIL PROTECTED]> wrote: > im sure this must be something stupid but i dont understand why it > crashes if its not float data > C_word w = C_u_i_car( lyst ); > if (C_truep( C_flonump( w ) )) { Heinrich, Try if (C_truep(C_blockp(w)) && C_truep(C_flonump(w))) {...} and see if it helps. Since you're doing this completely in C, you don't really have to convert to a scheme boolean either: if (!C_immediatep(w) && C_block_header(x) == C_FLONUM_TAG) { ... } ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] C_truep( C_fixnump( w ))
hmmm it has nothing to do with the C_truep( C_fixnump( w )) test -- even if the else clause is empty it still crashes if the data are NOT floats. im sure this must be something stupid but i dont understand why it crashes if its not float data #> #include "Csound.h" void cs_event (int type, int len, C_word lyst) { // MYFLT buf[len]; printf("IN CS_EVENT, BEFORE LOOP LEN=%d\n", len); int i=0; for (; C_SCHEME_END_OF_LIST != lyst; lyst = C_u_i_cdr( lyst ) ) { if (i==len) break; C_word w = C_u_i_car( lyst ); if (C_truep( C_flonump( w ) )) { printf("FLO: buf[%d]=%f\n", i++, (float)C_flonum_magnitude( w )); } else { } } // ((GraceApp *)GraceApp::getInstance())->getCsoundPort()- >sendEvent(typ, len, buf); } <# (define (cs:i . args) (if (not (null? args)) ((foreign-lambda void "cs_event" int int scheme-object) 1 (length args) args)) (values)) --- (cs:i 1.0 0.0 1.0 60.0 1000.0) IN CS_EVENT, BEFORE LOOP LEN=5 FLO: buf[0]=1.00 FLO: buf[1]=0.00 FLO: buf[2]=1.00 FLO: buf[3]=60.00 FLO: buf[4]=1000.00 (cs:i 1 0 1 60 1000) <<>> ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] C_truep( C_fixnump( w ))
hi im using chicken 3.0.0 im trying to parse a list of floats and/or ints that come from scheme. in the example below the floating point test: if (C_truep( C_flonump( w ) )) works fine but the integer test else if (C_truep( C_fixnump( w ) )) crashes my app. im not sure what is wrong and ive spent about an hour trying to figure this out. aplogies if its somethig stupid that my eyes are not seeing! note that its the actuall test not the printf thats crashing, (if i comment out the printf it still crashes). int i=0; for (; C_SCHEME_END_OF_LIST != lyst; lyst = C_u_i_cdr( lyst ) ) { C_word w = C_u_i_car( lyst ); if (C_truep( C_flonump( w ) )) { printf("FLO: buf[%d]=%f\n", i++, (float)C_flonum_magnitude( w )); } else if (C_truep( C_fixnump( w ) )) { printf("FIX: buf[%d]=%d\n", i++, C_unfix( w )); } else { } } ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users