vipsi - sample script
Author: kio@little-bat.de
Keywords: vipsi shell script interpreter programming

# vipsi - shell and script language

## example scripts

### show my source

this example shows a procedure which, when called, prints it's own source. ok, that's not that useful, but try the same with another language of your choice.

    localhost: vipsi
    _______________________________________________________________________
    vipsi - VIP script interpreter 0.7.1 (c) 2001-2003 kio@little-bat.de
    development release. please set your terminal to utf-8 and vt100.
    see <>http://vipsi.sourceforge.net> for latest documentation.

            vipsi is waiting for your commands.
            type an expression to calculate the result.
            type «words» for a list of words.
            type «info "foo"» for info on word «foo».
            type ctrl-D to quit.
    _______________________________________________________________________

    vipsi> proc sms ( ) { log sms }
    vipsi>
    vipsi> // that's it was. now let's try it:
    vipsi>
    vipsi> sms()      proc sms ( ) { log sms }
    vipsi>

just to make it harder we'll now require additionally, that it must not use `log sms` for introspection. so we'll have to do it in a way how it works for most other languages too:

    // this program prints it's own source
    // (c) 1998-2002 kio@little-bat.de
    proc sms() {
      proc p(s) { if f convert s to quoted; s="    p("#s#")"; then log s,nl; }
      proc q() { log "  loop",nl,"  q()",nl,"}",nl }
      var f=-1 do while ++f<=1
        p("")
        p("// this program prints it's own source")
        p("// (c) 1998-2002 kio@little-bat.de")
        p("proc sms() {")
        p("  proc p(s) { if f convert s to quoted; s=\"    p(\"#s#\")\"; then log s,nl; }")
        p("  proc q() { log \"  loop\",nl,\"  q()\",nl,\"}\",nl }")
        p("  var f=-1 do while ++f<=1")
      loop
      q()
    }

copy and paste this example into a file e.g. sms.txt and include and start it within a vipsi shell:

    vipsi> include "/Users/kio/projects/vipsi/examples/sms.txt"
    vipsi> sms()
    // this program prints it's own source
    // (c) 1998-2002 kio@little-bat.de
    proc sms() {
      proc p(s) { if f convert s to quoted; s="    p("#s#")"; then log s,nl; }
      proc q() { log "  loop",nl,"  q()",nl,"}",nl }
      var f=-1 do while ++f<=1
        p("")
        p("// this program prints it's own source")
        p("// (c) 1998-2002 kio@little-bat.de")
        p("proc sms() {")
        p("  proc p(s) { if f convert s to quoted; s=\"    p(\"#s#\")\"; then log s,nl; }")
        p("  proc q() { log \"  loop\",nl,\"  q()\",nl,\"}\",nl }")
        p("  var f=-1 do while ++f<=1")
      loop
      q()
    }

    vipsi>

Yee! it works. great! :-)

there are some people who add even more requirements to this job. i leave it as an excercise to the reader to add some lines so that they get an executable program (script) that can be started from the command line and print's it's source to stdout. i'd like to ask those people to add some lines to their (non-vipsi) programs so that they recompile themself. just to compare. B-)

you may also modify the script so that it prints a version number, which increases with each run. ;-)