Getting Started: Command Line Interaction (cont'd)


 

Taking one step

With BETA assignment syntax, data flows from the left to the right just like we read from the left to the right. This is very unusual, but after a while you might think (like me :-) that it is the way to do it. Anyway, the syntax:

'world!'->s

is an assignment which takes the literal string value 'world!' and puts it into the object s. In many programming languages, this would look more like:

s := 'world!' (* NB: not BETA syntax *)

To execute this imperative, just press [ENTER], giving the response:

 
====================
(#`196
   s: @string;
   hello: (#`74
      exit 'Hello'
      #)
do 'world!'->s;
   hello+', '+s->stdio
#)
====================

executing~1> _ 

Note that it is the second imperative which is emphasized now. To check that something actually happened, try to look at s:

 
executing~1> print s

          object, string object slice~4 = "world!"

executing~1> _ 

This basically says that, as seen from the current imperative and in the current execution state, the name s denotes an object, and the state of this object is the string value "world!".

We can investigate information known from static analysis:

 
executing~1> assigninfo s

Assignment type: s

                 string static transient

executing~1> _ 

This tells us that s can accept a string value in assignments. Consequently, anything whose evalinfo is also a string static transient can be assigned to it. (Try "help evalinfo".)

A constant, an expression, and a primitive

The BETA way to express a constant is to declare a pattern which simply delivers ("exit"s) a value, like the pattern hello:

hello: (# exit 'Hello' #)

This constant, a literal string, and the string object s are used in an expression whose value is "inserted into" stdio:

hello+', '+s -> stdio

stdio is the primitive entity which makes it possible to read the standard input and write to the standard output. Again, the arrow, "->", signals data flow, and the values flow in the direction of the arrow, into stdio.

If you execute this imperative:

 
executing~1> step
Hello, world!

terminated> _ 

you can see that the imperative was executed (the expression was evaluated and the computed string value "Hello, world!" was delivered to the standard output), and since we reached the end of the program, gbeta entered the terminated state.

Modern conveniences..

Often you can just press [ENTER] when executing a program interactively. The reason why we had to type step this time was that the previous command "print s" would be the default command. For convenience, the default command is step initially, so we could choose to type step or just press [ENTER] at the first step of execution.

In general, commands can be abbreviated. If an abbreviated command matches more than one command name, the first mathing command is executed (no warning about ambiguities!). To find out what command matches a given abbreviation, e.g. "n", use the help command:

help n

The response tells you that n abbreviates the command next, and it gives some general information about the next command as well.

This is best for one-file programs

At the command line, gbeta can only pretty-print the enclosing source code to show you what part of the program is currently being executed. Since pretty-printing drops all comments and reshapes the source code formatting to a strictly regular style, lots of information is lost, and this approach gets tedious and confusing when running any but the smallest programs interactively. The next section presents the integration of gbeta with GNU Emacs which gives a much more useful environment for larger programs.

 


Signed by: eernst@cs.auc.dk. Last Modified: 3-Jul-01