Next: , Previous: Focus value, Up: Command processor


2.4.5 Command levels

The Scheme48 command processor maintains a stack of command levels, or recursive invocations of the command processor. Each command level retains information about the point from the previous command level at which it was pushed: the threads that were running — which the command processor suspends —, including the thread of that command level itself; the continuation of what pushed the level; and, if applicable, the condition that caused the command level to be pushed. Each command level has its own thread scheduler, which controls all threads running at that level, including those threads' children.

Some beginning users may find command levels confusing, particularly those who are new to Scheme or who are familiar with the more simplistic interaction methods of other Scheme systems. These users may disable the command level system with the levels switch by writing the command `,set levels off'.

— command: ,push
— command: ,pop
— command: ,resume
— command: ,resume level
— command: ,reset
— command: ,reset level

`,push' pushes a new command level. `,pop' pops the current command level. C-d/^D, or EOF, has the same effect as the ,pop command. Popping the top command level inquires the user whether to exit or to return to the top level. `,resume level' pops all command levels down to level and resumes all threads that were running at level when it was suspended to push another command level. `,reset level' resets the command processor to level, terminating all threads at that level but the command reader thread. ,resume & ,reset with no argument use the top command level.

— command: ,condition
— command: ,threads

`,condition' sets the focus value to the condition that caused the command level to be pushed, or prints `no condition' if there was no relevant condition. `,threads' invokes the inspector on the list of threads of the previous command level, or on nothing if the current command level is the top one.

     > ,push
     1> ,push
     2> ,pop
     1> ,reset
     
     Top level
     > ,open threads formats
     > ,push
     1> ,push
     2> (spawn (lambda ()
                 (let loop ()
                   (sleep 10000)    ; Sleep for ten seconds.
                   (format #t "~&foo~%")
                   (loop)))
               'my-thread)
     2>
     foo
     ,push
     3> ,threads
     ; 2 values returned
      [0] '#{Thread 4 my-thread}
      [1] '#{Thread 3 command-loop}
     3: q
     '(#{Thread 4 my-thread} #{Thread 3 command-loop})
     3> ,resume 1
     
     foo
     2>
     foo
     ,push
     3> ,reset 1
     Back to 1> ,pop
     >