zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Zsh workers <zsh-workers@sunsite.dk>
Subject: Re: db module
Date: Sun, 6 Oct 2002 16:46:58 +0000	[thread overview]
Message-ID: <1021006164658.ZM11928@candle.brasslantern.com> (raw)
In-Reply-To: <E17w1iC-00012d-00@bimbo.logica.co.uk>
In-Reply-To: <20021006053229.GA14350@dman.com>
In-Reply-To: <20021006122451.GV24160@malachi.theoscape.net>

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   


  reply	other threads:[~2002-10-06 16:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-30 14:39 Oliver Kiddle
2002-10-02  7:37 ` Clint Adams
2002-10-06  5:32 ` Clint Adams
2002-10-06 12:24   ` Hans Dieter Pearcey
2002-10-06 16:46     ` Bart Schaefer [this message]
2002-10-06 17:03       ` Clint Adams
2002-10-06 17:14         ` Bart Schaefer
2002-10-06 17:31           ` Clint Adams
2002-10-06 20:19             ` Bart Schaefer
  -- strict thread matches above, loose matches on Subject: below --
2002-10-07 13:58 Oliver Kiddle
2002-09-12  5:19 Clint Adams

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1021006164658.ZM11928@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).