Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: db module

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   

Messages sorted by: Reverse Date, Date, Thread, Author