zsh-users
 help / color / mirror / code / Atom feed
* creating user defined special parameters?
@ 2011-01-08 12:38 Atom Smasher
  2011-01-08 19:55 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Atom Smasher @ 2011-01-08 12:38 UTC (permalink / raw)
  To: zsh-users

is there a way, from within the shell, to create a special parameter?

in other words; is there a way to create a variable that refers to a 
function, and execute the function when the variable is used?

eg...
 	date_func () { date }
 	typeset  [options]  date  date_func

so that:
 	echo $date

would return the _current_ date & time?


-- 
         ...atom

  ________________________
  http://atom.smasher.org/
  762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
  -------------------------------------------------

 	"No two men are alike, and both of them are happy for it."
 		-- Morris Mandel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: creating user defined special parameters?
  2011-01-08 12:38 creating user defined special parameters? Atom Smasher
@ 2011-01-08 19:55 ` Bart Schaefer
  2011-01-11  8:36   ` Atom Smasher
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2011-01-08 19:55 UTC (permalink / raw)
  To: zsh-users

On Jan 9,  1:38am, Atom Smasher wrote:
}
} is there a way, from within the shell, to create a special parameter?

No; zsh has not yet implemented ksh "discipline functions," nor the
compound-type semantics of ksh's "typeset -T".

In part this is because of what should be a simple parsing issue; the
syntax Korn invented for compound variables is to embed a "." in the
name, e.g. ${foo.fud} is the "fud" field of base variable "foo".  But
zsh's parser for parameter names inside ${ } is the same as that used
for "bare" $foo.fud, which historically must be parsed ${foo}.fud --
and this same parser is used all over the internals as a test for valid
"identifier" token syntax, so simply adding "." to the list of allowed
characters in an identifier induces massive breakage.

It would be possible to implement an equivalent of discipline functions
as a module, but whenever it has come up it's been backburnered until
the naming syntax problem can be addressed -- no point in deliberately
inventing a differently-shaped version of this wheel.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: creating user defined special parameters?
  2011-01-08 19:55 ` Bart Schaefer
@ 2011-01-11  8:36   ` Atom Smasher
  2011-01-11 16:27     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Atom Smasher @ 2011-01-11  8:36 UTC (permalink / raw)
  To: zsh-users

On Sat, 8 Jan 2011, Bart Schaefer wrote:

> } is there a way, from within the shell, to create a special parameter?
>
> No; zsh has not yet implemented ksh "discipline functions," nor the 
> compound-type semantics of ksh's "typeset -T".
================

it's not my desire to emulate ksh's discipline functions or compound 
variables, i just want a way to define a "simple" variable as a function.

basically i want to do thing like roll my own $RANDOM and $EPOCHSECONDS. 
i'm not seeing how that has anything to do with parsing compound 
variables...?


-- 
         ...atom

  ________________________
  http://atom.smasher.org/
  762A 3B98 A3C3 96C9 C6B7 582A B88D 52E4 D9F5 7808
  -------------------------------------------------

 	"If you want total security, go to prison. There you're fed, clothed,
 	 given medical care and so on. The only thing lacking is freedom."
 		-- Dwight Eisenhower


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: creating user defined special parameters?
  2011-01-11  8:36   ` Atom Smasher
@ 2011-01-11 16:27     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2011-01-11 16:27 UTC (permalink / raw)
  To: zsh-users

On Jan 11,  9:36pm, Atom Smasher wrote:
}
} it's not my desire to emulate ksh's discipline functions or compound 
} variables, i just want a way to define a "simple" variable as a function.

Yes, I understand.  I was explaining why a simple implementation has
not been pursued:  because there's already an example of a more
thoughtfully designed feature that it would be preferable to emulate,
rather than have yet another case of several incompatible ways to
do the same thing.

Ksh discipline functions solve several problems, not the least of
which is the question of how, inside the discipline function, to
refer to the variable associated with the function without causing
either namespace collisions or an infinite recursion.  The compound
variable syntax is central to that solution.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-01-11 16:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-08 12:38 creating user defined special parameters? Atom Smasher
2011-01-08 19:55 ` Bart Schaefer
2011-01-11  8:36   ` Atom Smasher
2011-01-11 16:27     ` Bart Schaefer

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).