Re: [PHP] Re: Using constructs like unset() in expressions like ()()

2004-12-20 Thread Richard Lynch
Tomas Tintera wrote:
 Richard Lynch wrote:
  Perhaps something like this:
  
  function my_unset($var){
   global $$var;
   $wasset = isset($$var);
   unset($$var);
   return $wasset;
  }
  
  my_unset(‘a‘); //unset($a);
  
  
  
  Or, in a more general way:
  
  function forcereturn ($php){
   return eval($php);
  }
  
  
  Damned if I understand *why* you want this, mind you. :-)

 Thank you, Richard. That's what I am looking for.

 Your first solution may not be usable, because the variable to unset may
 not be a global variable.

Well it most certainly cannot be a local variable, and you have to use
'global' inside your function to see it if it's going to be seen at all.

If you want this to apply to variables inside the scope of another
function calling this function, you'd still want 'global', I think to have
any hope of making it work.

 The second solution (that using eval()) may
 have a bug, because the unset() is called in a local-scope of the
 function forcereturn() (and so the variable unset()ted differs from
 the variable that we really want to unset()).

You would need to include 'global $a' in the $php code to be eval-ed.

 However, there can be used eval() instead of forcereturn():

 ?php (True==False) or (eval('unset($a);')); ?

 Nevertheless, this solution has defects for general use: A lot of
 expressions with no return value can't be called with eval() (e.g.
 eval('break;') is not a good idea).

eval in general is usually not a good idea. :-)

 ps. I want it because it seems to be practical to write the whole
 program in a one expression (usually composed of AND and OR
 operators). And it's nice. When reading such a code, you can feel as
 when reading poetry ;).

It sounds to me like you would be happier programming in a language such
as Lisp, Forth, or Scheme, or maybe even Prolog.

These languages all conform (more or less) to your desired syntax goal.

PHP doesn't.

Trying to hack something in there that will do what you desire will
probably only lead to bugs and big-time maintenance problems.

Or you could write your own language, sort of like PHP, only with none of
the specialized language constructs and make everything a function (like
Lisp and all those mentioned above).

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: Using constructs like unset() in expressions like ()()

2004-12-17 Thread Richard Lynch
Tomas Tintera wrote:
 Thanks for your answers (you probably don't understand me).

 I am looking for some construct (or statement or function) which allows
 to do this:

 ?php (True==False) or (construct_i_am_looking_for(unset($a))); ?

 Note that the unset() has no return value (and so it can't be used as a
 part of other expression; it can be only used as a stand-alone
 statement), so I thing it could be good if there were some construct
 which makes expression with return value from expression with no return
 value.

 It is not possible to use just
 ?php (True==False) or (unset($a)); ?

Perhaps something like this:

function my_unset($var){
  global $$var;
  $wasset = isset($$var);
  unset($$var);
  return $wasset;
}

my_unset('a'); //unset($a);



Or, in a more general way:

function forcereturn ($php){
  return eval($php);
}


Damned if I understand *why* you want this, mind you. :-)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php