Re: [Chicken-users] coops / override initialize-instance
From: John J Foerch jjfoe...@earthlink.net Subject: [Chicken-users] coops / override initialize-instance Date: Tue, 08 Mar 2011 16:30:32 -0500 Hello, What is the recommended way to perform complex initialization of object instances in coops? Say I need to initialize a certain slot based on the values of other slots in the object. Is the initialize-instance generic designed in a way that it is safe to do something like this: (define-method (initialize-instance (o myobject)) ;; initialization code here ) or is it recommended to write a wrapper function like this: (define (make-myobject a b c) (let ((o (make myobject 'a a 'b b 'c c))) ;; initialization code here o)) initialize-instance is the right way to do it. You just should make sure to use call-next-method before you you can refer to other slots, because the default method initializes all slots with their default values. cheers, felix ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] Re: coops / override initialize-instance
Felix fe...@call-with-current-continuation.org writes: From: John J Foerch jjfoe...@earthlink.net Subject: [Chicken-users] coops / override initialize-instance Date: Tue, 08 Mar 2011 16:30:32 -0500 Hello, What is the recommended way to perform complex initialization of object instances in coops? Say I need to initialize a certain slot based on the values of other slots in the object. Is the initialize-instance generic designed in a way that it is safe to do something like this: (define-method (initialize-instance (o myobject)) ;; initialization code here ) or is it recommended to write a wrapper function like this: (define (make-myobject a b c) (let ((o (make myobject 'a a 'b b 'c c))) ;; initialization code here o)) initialize-instance is the right way to do it. You just should make sure to use call-next-method before you you can refer to other slots, because the default method initializes all slots with their default values. cheers, felix elegant; thank you very much. -- John Foerch ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] raw packet interface
Hello Chickenistas, As part of testing a network appliance (router/firewall etc...), I'd like to be able to read and write arbitrary data to the network. So I'm wondering if somebody has already some tools to interface to low-level networking services, such as BPF, libpcap... I am trying to find error cases in the handling of incoming packets in the appliance; I do not need throughput performance nor very precise timings. I am running under FreeBSD 8.1. I'd be grateful for any advice. Thanks in advance, -- Nicolas ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
[Chicken-users] foreign-lambda* question
Hello, I'm writing a program that uses xlib and have hit a question that I cannot make heads or tails of from the web docs. I have a procedure that takes a window and a list of numbers and sets a property on the window which is an array of those numbers. The array must be an array of unsigned long, and foreign-lambda* seems to be the tool for the job to make this object. In an earlier version, I hardcoded the length of the array (commented out in the version below), but in the interest of code-reuse, I want to generalize it to work on any size list. I malloc memory and copy the data into the block, then return the pointer to the block for use in scheme. My question is, what is the idiomatic way in Chicken to free the allocated memory, or turn it over to the garbage collector? Code follows: (define (set-struts win strut-spec) (let ((values ((foreign-lambda* c-pointer ((u32vector s) (int length)) ;;unsigned long strut[12] = ;;{ s[0], s[1], s[2], s[3], s[4], s[5], ;; s[6], s[7], s[8], s[9], s[10], s[11] }; unsigned long * strut = malloc(sizeof(unsigned long) * length); int i; for (i = 0; i length; i++) { strut[i] = s[i]; } C_return(strut);) (list-u32vector strut-spec) (length strut-spec (window-property-set win _NET_WM_STRUT_PARTIAL (vector CARDINAL 32 values (length strut-spec) Thank you, -- John Foerch ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] raw packet interface
On Mar 9, 2011, at 10:29 PM, Nicolas Pelletier wrote: Hello Chickenistas, As part of testing a network appliance (router/firewall etc...), I'd like to be able to read and write arbitrary data to the network. So I'm wondering if somebody has already some tools to interface to low-level networking services, such as BPF, libpcap... I am trying to find error cases in the handling of incoming packets in the appliance; I do not need throughput performance nor very precise timings. I am running under FreeBSD 8.1. I'd be grateful for any advice. I am not aware anyone doing raw packet access in Scheme. Do you think that bindings for libpcap would be enough for your purposes? -- Stephen ___ Chicken-users mailing list Chicken-users@nongnu.org http://lists.nongnu.org/mailman/listinfo/chicken-users
Re: [Chicken-users] foreign-lambda* question
John, Presuming you no longer need the contents of values after the call to window-property-set, you can then use free from unit lolevel to free the memory. Is that the case? On Mar 9, 2011, at 21:35, John J Foerch jjfoe...@earthlink.net wrote: Hello, I'm writing a program that uses xlib and have hit a question that I cannot make heads or tails of from the web docs. I have a procedure that takes a window and a list of numbers and sets a property on the window which is an array of those numbers. The array must be an array of unsigned long, and foreign-lambda* seems to be the tool for the job to make this object. In an earlier version, I hardcoded the length of the array (commented out in the version below), but in the interest of code-reuse, I want to generalize it to work on any size list. I malloc memory and copy the data into the block, then return the pointer to the block for use in scheme. My question is, what is the idiomatic way in Chicken to free the allocated memory, or turn it over to the garbage collector? Code follows: (define (set-struts win strut-spec) (let ((values ((foreign-lambda* c-pointer ((u32vector s) (int length)) ;;unsigned long strut[12] = ;;{ s[0], s[1], s[2], s[3], s[4], s[5], ;; s[6], s[7], s[8], s[9], s[10], s[11] }; unsigned long * strut = malloc(sizeof(unsigned long) * length); int i; for (i = 0; i length; i++) { strut[i] = s[i]; } C_return(strut);) (list-u32vector strut-spec) (length strut-spec (window-property-set win _NET_WM_STRUT_PARTIAL (vector CARDINAL 32 values (length strut-spec) Thank you, -- John Foerch ___ 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