|
| |
|
One of the most powerful tools when developing pike programs
is hilfe, the "Incremental Pike Frontend". Although there is
little to be said about hilfe, it is important to mention it.
And the fact that there isn't much you need to know in order
to use hilfe is probably one of its greatest strengths. Not
only is hilfe a good "laboratory" for people just learning pike,
it is also great as a reference manual complement and as a
decent pocket calculator.
The Basics
In short hilfe is a command line version of pike, allowing
you to do real time evaluation of pike code. Simply write a
line of pike code and press return. If you gave hilfe a complete
block of code it will be evaluated and the result will be returned.
Side effects will also be effective, hence changing a variable
will indeed change the variables value. You are of course not limited
to basic variable types like integers and strings, or reference
data types like mappings and arrays. You can just as well define
functions and classes, enabling you to experiment with inherits,
operator overloading and other object oriented things. To start hilfe,
just execute the pike binary without any arguments.
|
|
| |
Pike v7.1 release 5 running Hilfe v2.0 (Incremental Pike Frontend)
> int a=5;
Result: 5
> float b=3.14;
Result: 3.140000
> mixed c=a+b;
Result: 8.140000
> c;
Result: 8.140000
>
|
|
|
|
Beware that on top level, i.e. outside functions and objects, all
types are actually mixed, even if declared otherwise. That means
however nothing in practice unless you are experimenting with types.
| |
> int x;
> typeof(x);
Result: mixed
> class Test { int x; }
> typeof(Test()->x);
Result: int
|
|
|
My wish is your Command
Pike has a few non-pike commands that you can give. The only
one you really have to remember is help, but it isn't a challange
to get them all. This is what you get if you give the help command.
| |
Hilfe is a tool to evaluate Pike interactively and incrementally.
Any Pike function, expression or variable declaration can be entered
at the command line. There are also a few extra commands:
help - show this text
quit - exit this program
. - abort current input batch
dump - dump variables
new - clear all function and variables
See the Pike reference manual for more information.
|
|
|
|
I don't think I have to explain the first two more, but the third is as useful
as it is poorly described. In hilfe you can write input that are longer than just
one line, since hilfe does not begin to evaluate until it gets a complete program
block. If you've lost a character, or whant to cancel the current input
for any other reason, just type a period dot on a single row.
| |
> Parser.HTML->add_tag( "img", lambda(string t, mapping m) {
>> return m->alt }
>> ->finish(x);
>> .
Input buffer flushed.
>
|
|
|
|
The return m->alt is missing a semicolon, thus hilfe does not consider
the code a complete program block until it gets another semicolon. By pressing the
arrow up key you can select all the right lines and correct the incorrect ones.
The dump command shows a list with all the currently defined variables and their
values. The command new clears this list.
| |
> int a,b,c;
> sscanf("0236230936","%4x%4d%f",a,b,c);
Result: 3
> dump
b :2309
c :36.000000
a :566
> new
> dump
>
|
|
|
|
Note that it is a good idea to avoid using any of the commands in your pike-code
(I'm not talking about "."). E.g. int quit=0; will exit your hilfe.
Encyclopedia Hilfe
Even people who programs daily in pike uses hilfe. One common use is still
to experiment with constructions but often also to remind them of the name and
syntax the instructions. The first trick is that undefined functions return an
error when you try to write them out, while defined functions do not.
| |
> String.trim_whitespaces;
-:1:Index 'trim_whitespaces' not present in module 'String'.
> String.trim_whites;
Result: trim_whites
>
|
|
|
|
The second trick is the typeof-function, with which you can see how many
arguments, and of which types, a function takes and what it returns.
| |
Result: function(string, void | mixed ... : void)
> typeof(String.trim_whites);
Result: function(string : string)
> typeof(werror);
Result: function(string, void | mixed ... : void)
>
|
|
|
|
Last but not least, do not underestimate the power of indices.
| |
> indices(String);
Result: ({ /* 11 elements */
"capitalize",
"sillycaps",
"common_prefix",
"String_buffer",
"fuzzymatch",
"trim_whites",
"trim_all_whites",
"strmult",
"count",
"width",
"implode_nicely"
})
|
|
|
|
|  |