Re: functions versus statements (from WIKI)

"Mark Hahn" <[email protected]>
Newsgroups gmane.comp.lang.prothon.user
Message-ID <[email protected]>
Paul Prescod wrote:

> Having the function return its value is a convenience for debugging.
> If it will simplify life (it seems it will) then I propose a separate
> function called "debug" that returns its result. Here's the situation.
>
> x = f( 5 + 32 * Z(abc[23]))
>
> Now you want to add something that will help you see what Z(abc[23])
> is while you are debugging. Usually you have to refactor and you could
> introduce an error doing so. With debug you just do this:
>
> print "XXX"
> x = f( 5 + 32 * debug(Z(abc[23])))

I implemented dbgPrt to return what was printed and it did not help in your
example becuase it returns a string which is useless.  Do you want me to
just pass through the first argument unchanged?  What if the first argument
is a string you meant to be a header and the second one is the one you want
passed through?  I know, I'll pass the last positional argument through so
you can put headers in if you wish.

At this point the debug routine is starting to get pretty specialized.  It
would also be nice for it to print out the source of the first argument as a
header.

Z(abc[23]) : 38

This isn't really a print issue any more.  This is a whole seperate language
feature.  One I like, but not a print feature.

------------ wild-idea warning --------

How about using some simple symbol instead of function calls to make it
really easy to add debug prints. It could be ugly like the @ symbol so that
you'd have no trouble finding it to remove later.  This way it could be
added to a full line without making the line run over.  With a prefix symbol
in the syntax you wouldn't even need to add parens!  It would mean to add
whatever expression it immediately prefixes.  I think this is
non-amibiguous.

 x = f( 5 + 32 * @Z(abc[23]))  -> print Z(abc[23])
 x = f( 5 + 32 * Z(@abc[23]))  -> print abc[23]
 x = @f( 5 + 32 * Z(abc[23]))  ->  print  f( 5 + 32 * Z(abc[23]))

It would print out "@source = str_(result)"  such as  @Z(abc[23]) = 37,
@abc[23] = 12.32

You could pepper the code with as many as you want and it would print them
in the order it parses them:

 x = @f( 5 + 32 * @Z(@abc[23]))

would print something like:

@abc[23] = 12.32,  @Z(abc[23]) = 37, @f( 5 + 32 * Z(abc[23])) = 93.212

Notice that it stripped the @ signs from the prints where it wasn't
relevant.

I'll prepare this as a proposal.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.