Version 33 of snobol

Updated 2011-07-13 22:12:53 by RLE

Having actually tried to learn this language, I'm astounded by its pattern matching facilities. Makes grep look primitive.

Being a slow starter with Tcl, where would I start trying to

  1. write a snobol interpreter in Tcl, or
  2. write snobol pattern matching tools in Tcl?

BMA


LV Well, the quick approach would be to scavange one of the free snobol interpreter source trees for their code, write or wrap the code with Tcl binding, and invoke it directly.

The tougher approach would be to study the language, determine what features from the language you want, decide upon the Tcl API you want to use to achieve similar functionality, then write that functionality, write a test suite, and get it all running.


escargo 30 Dec 2003 - I will just note that the successor to Snobol, Icon, also has a page on this wiki. Its pattern matching is different than Snobol's, but also very powerful. It is not based on regular expressions, but does pattern matching with other facilities.

If it ain't regular expressions, it ain't no good. - LES

Les's ideas are no better than his grammar. The only advantage of regular expressions over Snobol pattern matching and Icon string scanning is that regular expressions are very terse. Perhaps because of their terseness, they quickly become unreadable as they become more complex. Pattern matching and string scanning are far more powerful, are quicker to write, and are far easier to debug. One writer said that if you have a problem and you solve it with a regular expression, you end up with two problems. If you need to do anything complex with strings, your best bet is Icon string scanning. Larry


Perhaps someone could put up some examples of the power of snobol, demonstrating the power being described specifically. Then if someone wants to wander by and contribute regular expression equivalents, the reader will more easily be able to take sides in the debate.


Furthermore, Icon has a regular expression package, so you can use both Icon string scanning and regular expressions as you find convenient.WJP


There's the beginnings of a Snobol wiki at [L1 ] BMA (a dead link?)

And a site about Snobol in general at [L2 ]. escargo


There's a brilliant editor/IDE for Snobol written in Tcl/Tk at Rafal M. Sulejman's site [L3 ] BMA 15 Mar 2005


"http://www.snobol4.org/csnobol4/README mentions a version of snobol4 with Tcl library routines"


Ralph Griswold created both SNOBOL and Icon.


CSnobol4 has a TCL/Tk interface. (escargo 20 Nov 2006 - I saw mention of snoboltcl, but nothing about tk.)

I use Snobol4 TCL/Tk interface. Check snobol4tcl manual page in the CSnobol4 package.

It includes also an example:

  -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(NOTK)
        DIFFER(TK_VERSION)                              :S(HAVETK)

  NOTK    OUTPUT = "Could not find tk_version"            :(END)

  HAVETK  OUTPUT = "Tk version: " TK_VERSION
        SEP = ';'

        STCL_EVAL(INTERP,
  +               'button .hello -text "Hello, world" -command {set foo 1}' SEP
  +               "pack .hello" SEP
  +               'button .other -text "Other Choice" -command {set foo 2}' SEP
  +               "pack .other" SEP
  +               "global foo" SEP
  +               "vwait foo")

        OUTPUT = STCL_GETVAR(INTERP, "foo")
  END


[Should we say something about COMIT?]