HELLO (terminate and relaunch)

Home Forums SwiftForth Forum HELLO (terminate and relaunch)

This topic contains 0 replies, has 1 voice, and was last updated by  Roelf 8 months, 2 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #13185

    Roelf
    Participant

    The following code for macOS SwftForth and perhaps the Linux version is usefull for perhaps only one person, me. Still…

    
    { ====================================================================
    terminate and relaunch
    
    SwiftForth version
    
    Copyrught (c) 1999-2018 Roelf Toxopeus
    
    Last: 25 March 2018 at 11:50:55 CEST  -rt
    ==================================================================== }
    
    0 [IF]  --------------------------------------------------------------
    First in PowerMacForth.
    
    HELLO -- Sends a request to the OS to 'terminate _and_ relaunch us'.
    This can be done in the form of an Applescript or a string of commands
    for the shell. The latter is used here. Relaunches in a new shell window.
    Another implementation using NSWorkspace can be found in hotcoco/launches.f
    But see bash alternative at end!
    
    Note: if you launched sf with  shell> sf;exit  the shell window will be
    closed after BYE. The newly launched sf with HELLO is launched this way
    by the   open  shell command.
    
    Where do I need this?
    I short-circuit Forth systems many times a day.
    This means terminating and re-launching the used Forth system with a
    minimum of fuzz.
    In nearly an eye wink you're back in a fresh pristine Forth system.
    Used when I think I messed up too much. For instance, I redefine a lot,
    1000 x the same word if I have too. Can't be bothered (anymore) with
    ANEW, MARKER, REMEMBER, FORGET etc. and even EMPTY. Just terminate and
    relaunch, OS cleans after me (mostly).
    
    Alternative for Darwin Forth systems is executing BYE, hit up-arrow
    in shell to retrieve last ran command (do a Forth) and hit return.
    Same shell window is used!
    
    Even better, launch <forth> in a loop in bash.
    
    You can add the following to your shell profile:
    function hello {
       (exit 0)              # clear exitstatus
       while [ $? = 0 ]
       do eval $1
       done
    }
    alias HELLO=hello
    
    Usage:  HELLO sf   hello vfx   HELLO i4 etc.
    
    BYE will end current <forth> and a new one will be launched ad infinitum.
    Close terminal window or quit Terminal to stop, or exit out of <forth>
    with a non-zero exitcode.
    SwfitForth:  1 EXITSTATUS ! BYE
    VFX:         1 EXITCODE ! BYE
    iForth:      1 TERMINATE
    
    A simple but effective HELLO !
    --------------------------------------------------------------- [THEN]
    
    /FORTH
    DECIMAL
    
    : HELLO ( -- )
       HERE DUP >R 1024 ERASE
       S\" open \""  R@ PLACE           
       THIS-EXE-NAME R@ APPEND                      
       S\" \""       R@ APPEND
       R> COUNT >SHELL BYE ;
    
    \\ ( eof)
    
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.