From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2971 invoked from network); 6 Oct 2002 16:47:44 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 6 Oct 2002 16:47:44 -0000 Received: (qmail 19226 invoked by alias); 6 Oct 2002 16:47:30 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 17778 Received: (qmail 19183 invoked from network); 6 Oct 2002 16:47:27 -0000 From: "Bart Schaefer" Message-Id: <1021006164658.ZM11928@candle.brasslantern.com> Date: Sun, 6 Oct 2002 16:46:58 +0000 In-Reply-To: Comments: In reply to Oliver Kiddle "Re: db module" (Sep 30, 3:39pm) References: <20021006053229.GA14350@dman.com> <20021006122451.GV24160@malachi.theoscape.net> In-Reply-To: <20021006053229.GA14350@dman.com> Comments: In reply to Clint Adams "Re: db module" (Oct 6, 1:32am) In-Reply-To: <20021006122451.GV24160@malachi.theoscape.net> Comments: In reply to Hans Dieter Pearcey "Re: db module" (Oct 6, 8:24am) X-Mailer: Z-Mail (5.0.0 30July97) To: Zsh workers Subject: Re: db module MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Sep 30, 3:39pm, Oliver Kiddle wrote: } Subject: Re: db module } } On Thu, 12 Sep 2002, Clint wrote: } } > This allows one to "tie" a Berkeley DB to an associative array (or is } > that the other way around?) } } It's a nice idea. Could be an interesting way to do completion caching. } Thinking of it from the perspective of cached variables, it is actually } quite similar to mapfile. The mapfile module could easily have been } implemented with a builtin. On Oct 6, 1:32am, Clint Adams wrote: } Subject: Re: db module } } Someone suggested tying assocs to functions It would seem to me that all of this stuff can be accomplished by the equivalent of ksh discipline functions (plus, in the DB case, a module to do the actual database access). Rather than implementing each of these things as different typeset variants, we should work on adding discipline functions. (Was it Andrej who's working on a parameter code rewerite?) } f() { print $(( $1 * 2 )) } } typeset -A twice -S function -f f } print $f[2] You mean "print $twice[2]", yes? Obviously you'd not put a "print" inside the function. Instead it would be something like f() { REPLY=$(($1 * 2)) } where the typeset magic would do twice[2]=$REPLY upon successful return from the function, all of which would happen before the parameter code finally expands the value of $twice[2]. } I'm not sure that there are any useful applications for this though. Consider the case where you have some arbitrarily complex function such as a big quadratic equation which you want to refer to in some other expression. Instead of quadratic() { # Do hairy computation and assign to REPLY print $REPLY } (( foo = bar * $(quadratic $foo) )) which requires forking an external process and reading back its output, you can just write quadratic_f() { # Do hairy computation and assign to REPLY } typeset quadratic ... (( foo = bar * $quadratic[$foo] )) One can also envision cases where it would be nice if a function could return text instead of an exit code, so that you could "inline" the function call in a larger print statement or in a here-document or the like, again without forking. It's making the shell more perl-like. On Oct 6, 8:24am, Hans Dieter Pearcey wrote: } Subject: Re: db module } } However, if the function got an extra argument when an element was } assigned to, it could be pretty neat, e.g.: } } f() { [ "$2" ] && echo $2 > $1; cat $1 } I confess to having no idea what that's supposed to mean. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net