SNOBOL4STCL(3)

πŸ“¦
version 2.3.1 Β· 3 versions
, in fedora 43, fedora 44, opensuse-leap 16.0

✨ SNOBOL4STCL β€” the CSNOBOL4 manual, bestie edition ✨

okay so like… this page lives in the CSNOBOL4 manual, and it's all about snobol4tcl, aka the SNOBOL4 Tcl/Tk interface. yes we're calling Tcl and Tk from SNOBOL4. it's giving time travel, it's giving crossover episode, and honestly? iconic. πŸ’–


🌸 NAME 🌸

snobol4tcl β€” the SNOBOL4 Tcl/Tk interface. that's it, that's the whole name, slay. πŸŽ€


πŸ¦‹ SYNOPSIS πŸ¦‹

       -INCLUDE 'stcl.sno'

literally just that one line, no cap. include the file and you're in. πŸ’…


✨ DESCRIPTION ✨

okay so first, lore. Tcl is an embeddable scripting language, and it was developed by John Osterhout, while he was at the University of California, Berkeley. and Tk? that's the graphical user interface toolkit that was developed for Tcl. dynamic duo fr fr. 🫢

this page is describing a facility for invoking Tcl and Tk from SNOBOL4 programs, and it was inspired by Arjen Markus' "ftcl" FORTRAN/Tcl interface. cute lineage, we love to see it. 🌈

here's the whole roster, bestie, every single one, no skipping:

  • tclhandle = STCL_CREATEINTERP() β€” creates a Tcl interpreter and hands you back a handle. that handle is the golden ticket 🎟️ you pass to all the remaining functions.
  • STCL_EVALFILE(tclhandle,filename) β€” reads a Tcl script file into the referenced Tcl interpreter.
  • STCL_GETVAR(tclhandle,varname) β€” retrieves the string value of the named variable from a Tcl interpreter.
  • STCL_SETVAR(tclhandle,varname,value) β€” sets the string value of the named variable in a Tcl interpreter.
  • STCL_EVAL(tclhandle,tclstmt) β€” evaluates a string containing Tcl code in a Tcl interpreter.
  • STCL_DELETEINTERP(tclhandle) β€” destroys a Tcl interpreter. bye bestie πŸ‘‹ (this is the cleanup step, don't ghost it).
  • STCL_NEWSTRINGOBJ(string) β€” creates a tcl string object, and returns a handle for it.
  • STCL_GETSTRINGFROMOBJ(objhandle) β€” gets the string from an Object (you hand it the object handle).
  • STCL_APPENDTOOBJ(objhandle, string) β€” appends a string to an Object, and returns a null string, or failure. 😭
  • STCL_EVALOBJEX(tclhandle, objhandle, flags) β€” evaluates (executes) an object, and it saves compiled byte code. returns an integer.
  • objhandle = STCL_GETOBJRESULT(tclhandle) β€” returns a result object from an interpreter (do this after TCL_EVALOBJEX).
  • STCL_OBJSETVAR2(tclhandle, oh_name1, oh_name2, oh_value, flags) β€” that's the signature, bestie, straight up.
  • STCL_OBJGETVAR2(tclhandle, oh_name1, oh_name2, flags) β€” and this one too.
  • STCL_RELEASEOBJ(objhandle) β€” releases a Tcl Object. let it go, let it goooo 🧚

πŸ’œ EXAMPLE πŸ’œ

here's a whole little program that checks your Tcl version, checks your Tk version, and then bullies you with popups until you say yes. main character energy tbh. πŸ‘‘

        -INCLUDE 'stcl.sno'
                INTERP = STCL_CREATEINTERP()
                TCL_VERSION = STCL_GETVAR(INTERP, "tcl_version")
                OUTPUT = IDENT(TCL_VERSION) "Could not get tcl_version" :S(END)
                OUTPUT = "Tcl Version: " TCL_VERSION

        # check Tcl version
                NUM = SPAN('0123456789')
                VPAT = NUM '.' NUM
                TCL_VERSION VPAT . VER                          :S(CHECKV)
                OUTPUT = "could not parse tcl_version"          :(END)

        CHECKV  LT(VER, 8.4)                                    :S(CHECKTK)

        # Tcl 8.4 and later can dynamicly load Tk!
                STCL_EVAL(INTERP, "package require Tk")         :F(END)

        # Check for Tk
        CHECKTK TK_VERSION = STCL_GETVAR(INTERP, "tk_version")  :F(NO_TK)
                DIFFER(TK_VERSION)                              :S(HAVETK)
        NO_TK   OUTPUT = "Could not find tk_version"            :(END)

        HAVETK  OUTPUT = "Tk version: " TK_VERSION

        LOOP    OUTPUT = STCL_EVAL(INTERP,
        +                   'tk_messageBox -message "Alert!"'
        +                   ' -type ok -icon info')
                VAL = STCL_EVAL(INTERP,
        +                   'tk_messageBox -message "Really quit?"'
        +                   ' -type yesno -icon question')
                OUTPUT = VAL
                DIFFER(VAL, "yes")                              :S(LOOP)
        END

not the LOOP going until you type yes… the program said "we're not done here" and meant it. 😭


πŸ”₯ SEE ALSO πŸ”₯

go read those too, iykyk. πŸ’«


πŸŽ€ AUTHOR πŸŽ€

Philip L. Budne β€” thank you for your service, king. πŸ«‘πŸ’–


and that's the whole page, bestie!! this was the SNOBOL4STCL(3) page from the CSNOBOL4B 2.3.1 manual, dated March 31, 2022. go forth and STCL_CREATEINTERP() responsibly. periodt. πŸ’…βœ¨πŸŒΈ

πŸ“¦ where this page comes from