From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Cedric Cellier Newsgroups: gmane.lisp.guile.user Subject: Re: Best way to call a user defined hook (written in guile) from C when the hook need plenty parameters Date: Wed, 7 Jul 2010 16:33:17 +0200 Message-ID: <20100707143317.GA4783@securactive.net> References: <20100705085635.GB9492@apc> <87wrtantcw.fsf@ambire.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1278513222 9939 80.91.229.12 (7 Jul 2010 14:33:42 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 7 Jul 2010 14:33:42 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Jul 07 16:33:41 2010 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OWVgy-0005Zw-8H for guile-user@m.gmane.org; Wed, 07 Jul 2010 16:33:40 +0200 Original-Received: from localhost ([127.0.0.1]:51975 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OWVgx-0007ET-Fz for guile-user@m.gmane.org; Wed, 07 Jul 2010 10:33:39 -0400 Original-Received: from [140.186.70.92] (port=43831 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OWVgp-0007D3-1W for guile-user@gnu.org; Wed, 07 Jul 2010 10:33:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OWVgn-0001RI-JF for guile-user@gnu.org; Wed, 07 Jul 2010 10:33:30 -0400 Original-Received: from smtp5-g21.free.fr ([212.27.42.5]:36945) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OWVgn-0001Pt-0Z for guile-user@gnu.org; Wed, 07 Jul 2010 10:33:29 -0400 Original-Received: from apc.happyleptic.org (unknown [82.67.194.89]) by smtp5-g21.free.fr (Postfix) with ESMTP id 1B815D480CD for ; Wed, 7 Jul 2010 16:33:15 +0200 (CEST) Original-Received: from ccellier.rd.securactive.lan (extranet.securactive.org [82.234.213.170]) by apc.happyleptic.org (Postfix) with ESMTP id A69403347D for ; Wed, 7 Jul 2010 16:33:28 +0200 (CEST) Original-Received: from rixed by ccellier.rd.securactive.lan with local (Exim 4.71) (envelope-from ) id 1OWVgb-0001Fk-98 for guile-user@gnu.org; Wed, 07 Jul 2010 16:33:17 +0200 Mail-Followup-To: guile-user@gnu.org Content-Disposition: inline In-Reply-To: <87wrtantcw.fsf@ambire.localdomain> User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:7972 Archived-At: (resend since previous mail was not delivered) First, let's give more details about what we are trying to implement. The main C program is continuously measuring some realtime evolving values, and periodically (lets say every 30 seconds) it must dump all measurements in a CSV file. As there are many such measurements to dump (say several tens of thousands) the dump itself must be reasonably fast so that the measurement are not halted for too long. Now, the C program measure an awful lot of things, and we are not always interested in every value, and we would like to have the ability to perform some hot reconfiguration of the CSV format in order to : - skip entries when the measurement looks suspicious - apply some numerical operations on individual values (for instance, dump the sum of two values instead of each one individually) - reorder the fields - etc... That's where guile enter the stage. Given a list of field names, the user enter (in a configuration file or live on a socket) the list of fields (or any other scheme expressions) he wants in the CSV file. Every time the program wants to dump its values into a CSV file it will loop over all the measurement and call a guile hook that must print the required fields. And by user I mean another in-house program so this configuration must not be monkey proof. :) Hope it's clearer now. > For "a set of named values", you can use an association list. I though of this, but I'm afraid the linear lookups in the alist would take too much time (we want to call the hook that write a CSV line approx 50k times in a loop, for every dump, so getting the value of foo should take a constant (small) time). I think (but haven't checked yet) that the binding between arguments values and argument names is much faster than that, since basically arguments are accessed directly by number (the fact that argument foo is the nth argument is known at "compile" time). Thank you very much for your suggestion that I'm now going to study more closely :-)