How to Program/en

Aus expecco Wiki (Version 2.x)
Zur Navigation springen Zur Suche springen

Introduction to Programming in expecco[Bearbeiten]

Before you start programming, please read this document, which describes how program code is handled in expecco. Unless you are familiar with the dynamics of a Smalltalk development environment, some of it may be unknown to you. You will have more fun and be more productive, if you know the power of the tools.

Executing Code Fragments[Bearbeiten]

Most of the tools inside expecco (especially the editor, notepad, data inspector and debugger) are able to execute code fragments.

To do this, select the piece of code to be executed and choose one of the "doIt", "printIt" or "inspectIt" menu functions. If no text is selected, the full cursor text line is evaluated. The ESC-key selects everything from the start of the line up to the current cursor position.

"DoIt" will simply execute the code, "printIt" will paste the returned value and "inspectIt" will open a data inspector on the result. The syntax depends on the context: in a workspace, it is selectable via a menu setting, in a debugger, it will be the language of the function being shown, in an inspector it is usually Smalltalk syntax. To get a feeling for this, try the following:

  • open a workspace (Mainmenu: "Extras" -> "Tools" -> "Notepad")
  • select Smalltalk syntax (Workspacemenu: "Workspace" -> "Smalltalk")
  • enter a piece of Smalltalk code (for example: "1024 hexPrintString")
  • select this code
  • apply "PrintIt"
  • the text "400" (which is the hexadecimal representation of the integer 1024) will be pasted at the text cursor position.

Try the same with the code fragment: " 'hello world' copyTo: 5 ".

Opening a notepad (workspace)[Bearbeiten]

Opening workspace.png

Evaluating a code fragment[Bearbeiten]

Workspace printit.png


If you prefer JavaScript syntax, change it via (Workspacemenu: "Workspace" -> "JavaScript"). Of course, you have to enter "hello world".copyTo(5) then, to get the above result.

Inspecting Data[Bearbeiten]

Now do the same, but apply the "inspectIt" menu function; an inspector will appear, which shows the result (another string, containing the first 5 characters):

Inspector tool.png

The inspector's left subview presents the internal slots of the object plus some meta-info (class and size) as a list. When an item is selected, that slot's value is shown in the right subview. This is another workspace (so "doIt" is again possible there). Double-click on a left entry navigates into it. Use the back-button to see the previous object again.

Hot-Swapping Code[Bearbeiten]

One of the coolest feature of expecco is its how-swap capability. Code can be edited and recompiled while the program (test) is running, without a need to stop the execution. However, it is not possible to hot-swap the one function which is currently being executed: it has to be either returned from, or restarted after a change. When an elementary function's code is changed, the new version will be activated with the next call.

Programming "in the Debugger"[Bearbeiten]

To demonstrate the above, create a Smalltalk elementary block (give it any name, such as "Testblock"), give it one input and one output parameter, and define its code as:

execute
    out1 value:(in1 value * 2)

if you prefer JavaScript, the code should be:

execute() {
    out1.value( in1.value() * 2);
}

Testblock's schema:
Defining TestBlock scheme.png
Then create a compound action block (say "Testblock-Runner"), and drop the above TestBlock-action into its network, freeze its input value with some number, add a "Transcripter" which shows the output and add a delay step. Connect the steps to be executed sequentially.

Defining TestRunSetup1.png

Now switch to the "Test/Demo" tab, add a loop-counter pin to the test step with a value of (say 100). Run it:

Defining TestRunSetup2.png

As you can see, the running network outputs the input value multiplied by 2 once a second.

Let it continue to run, while opening another expecco window, and navigate to your test block there. Change the code to multiply by 3 instead of 2, and "accept" it. Go back to the still running test-loop and notice that the generated output values have changed.

Congratulation: you have changed the code, while it has been executed.



Copyright © 2014-2024 eXept Software AG