From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ian Price Newsgroups: gmane.lisp.guile.user Subject: Re: Module reflection and the list of bound symbols Date: Sun, 30 Sep 2012 14:21:13 +0100 Message-ID: <87ehljr6ie.fsf@googlemail.com> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-2022-jp X-Trace: ger.gmane.org 1349011292 5907 80.91.229.3 (30 Sep 2012 13:21:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 30 Sep 2012 13:21:32 +0000 (UTC) Cc: guile-user@gnu.org To: Panicz Maciej Godek Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Sep 30 15:21:38 2012 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TIJSg-0001PQ-Kt for guile-user@m.gmane.org; Sun, 30 Sep 2012 15:21:34 +0200 Original-Received: from localhost ([::1]:41824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TIJSb-0006UH-4X for guile-user@m.gmane.org; Sun, 30 Sep 2012 09:21:29 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57012) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TIJSV-0006Tf-W1 for guile-user@gnu.org; Sun, 30 Sep 2012 09:21:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TIJSU-0000hS-Vo for guile-user@gnu.org; Sun, 30 Sep 2012 09:21:23 -0400 Original-Received: from mail-wg0-f41.google.com ([74.125.82.41]:38463) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TIJSU-0000ga-Oc for guile-user@gnu.org; Sun, 30 Sep 2012 09:21:22 -0400 Original-Received: by mail-wg0-f41.google.com with SMTP id ds1so937194wgb.0 for ; Sun, 30 Sep 2012 06:21:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=nXFpdTRiJzxgXK9JoxaoJAC35XIcMSOaex3r0uCKi28=; b=M44C1SOnTo1b1DkgL4/u38lXkkGFLqyPBlZCunsi9+DNoU+NK8NJdwpZ6eCLZkLzko kTGqxBZGjrJJ2r3W+8lbeLctv0zQ8n3BR1XCW/25guCYUDTez2UL62anjA3DOSIhizp5 GyQLG6eqM4Qbayf+nfe9FKhJZ5L6vBTNxrB2/Yf9oxcg2T5du1vVP3YJkiM3tDMSLZwa WQbUYGmvFrrhRkO6RvtgSw0m+1yz7mAfcJIJmDiV6IiAn+G1a7mczrtFPNV0RRikmJiJ UfGj0YAtv5f+SG9apaRhgWHQ857oLx4dNUNGkUO+SNkqSOMvNRpm/8vytUjcS/65esBF Rjdg== Original-Received: by 10.216.213.100 with SMTP id z78mr6328069weo.180.1349011281456; Sun, 30 Sep 2012 06:21:21 -0700 (PDT) Original-Received: from Kagami (host86-173-112-225.range86-173.btcentralplus.com. [86.173.112.225]) by mx.google.com with ESMTPS id l6sm10837316wiz.4.2012.09.30.06.21.19 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 30 Sep 2012 06:21:20 -0700 (PDT) In-Reply-To: (Panicz Maciej Godek's message of "Fri, 28 Sep 2012 19:37:17 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.125.82.41 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:9599 Archived-At: Panicz Maciej Godek writes: > On the other hand, there is no way (or I haven't found one) > to list the bound symbols explicitly. It seems tempting to > have a reflection function `module-symbols' or `environment-symbols' > that would return the names of bound symbols, > or to have functions like environment->list or module->list that > would return assoc lists mapping symbols to their values. Hmm, no, but you are able to get the "obarray" for the module which is a hash of symbols -> variables. (define (hash-keys hash) (hash-fold (lambda (key val prev) (cons key prev)) '() hash)) (define (module-exports module) (hash-keys (module-obarray module))) scheme@(guile−user)> (module-exports (resolve-module '(pfds queues))) $20 = (queue−>list queue−empty−condition? enqueue &queue−empty queue−length make−queue rotate queue−l∧ dummy queue−l make−queue−empty−condition %module−public−interface list−>queue dequeue queue−empty? queue? queue %make−queue queue−r makeq) This lists _all_ the bindings, even the non-public ones. I'm sure there is a way to get only the public (exported) ones using the interfaces, but that is beyond my knowledge at the moment. -- Ian Price -- shift-reset.com "Programming is like pinball. The reward for doing it well is the opportunity to do it again" - from "The Wizardy Compiled"