Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/infix?V=24
QUERY_STRINGV=24
CONTENT_TYPE
DOCUMENT_URI/revision/infix
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.69.6.156
REMOTE_PORT29010
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR3.141.8.247
HTTP_CF_RAY87ef0b6b38fb61b1-ORD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTMozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; [email protected])
HTTP_CF_CONNECTING_IP3.141.8.247
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit infix One\ of\ the\ styles\ for\ writing\ expressions,\ with\ operations\ '''in-between'''\ the\ operands\ (e.g.\ `6\ *\ 7`),\ as\ contrasted\ to\ ''postfix''\ (e.g.\ `6\ 7\ *`\;\ operations\ follow\ operands,\ as\ in\ \[RPN\])\ and\ ''prefix''\ (e.g.\ `*\ 6\ 7`\;\ operations\ come\ before\ operands,\ as\ in\ \[Tcl\]\ in\ general).\ Infix\ notation\ for\ mathematical\ expressions\ is\ by\ far\ the\ most\ common,\ and\ is\ in\ Tcl\ supported\ by\ \[expr\].\n\n----\nAs\ of\ 2006-10-14,\ \[infix\]\ is\ also\ the\ name\ of\ a\ Tcl\ package\ (and\ command\ defined\ by\ this\ package)\ that\ lets\ programmers\ write\ sequences\ of\ mathematical\ formulae\ in\ the\ familiar\ infix\ form.\ A\ short\ example:\n\ \ package\ require\ infix\ 0.2\n\ \ ::infix::core::setup\ base\ numconst\ expr::ops\ expr::fun\n\ \ proc\ ngon_corner\ \{num_sides\ radius\}\ \{\n\ \ \ \ \ infix\ \{\n\ \ \ \ \ \ \ \ n\ <-\ num_sides\n\ \ \ \ \ \ \ \ r\ <-\ radius\n\ \ \ \ \ \}\ \{\n\ \ \ \ \ \ \ \ alpha\ =\ acos(-1)\ /\ n\ \;\ \ #\ acos(-1)\ =\ pi\n\ \ \ \ \ \ \ \ r*cos(alpha),\ r*sin(alpha)\n\ \ \ \ \ \}\n\ \ \}\n\ \ ngon_corner\ 6\ 10\ \;\ #\ Returns\ \"8.66025403784\ 5.0\"\ -\ a\ two\ element\ list\n\nA\ notable\ feature\ is\ that\ the\ \[little\ language\]\ implemented\ by\ this\ package\ is\ completely\ configurable\ (setting\ it\ up\ for\ \[expr\]-like\ operations\ is\ what\ the\ ::infix::core::setup\ command\ does),\ so\ you\ can\ define\ new\ operations,\ or\ define\ the\ usual\ ones\ to\ do\ something\ unusual.\ A\ setting\ that\ turns\ +,\ -,\ etc.\ into\ the\ operations\ of\ the\ \[math::bignum\]\ package\ is\ included\ with\ the\ infix\ package.\n\nThe\ code\ is\ available\ at\n\ \ http://abel.math.umu.se/~lars/tcl/infix.tar.gz\n(requires\ tcllib,\ tcllib\ 1.8\ is\ sufficient).\n\nA\ paper\ on\ the\ package\ (which\ includes\ the\ entire\ source\ code,\ commented\ and\ explained)\ is\ available\ at\n\ \ http://abel.math.umu.se/~lars/tcl/infix.pdf\n\n--\ \[Lars\ H\]\n\n----\n\n**Some\ kind\ of\ a\ user's\ manual\ (incomplete)**\n\nThe\ user\ commands\ created\ by\ the\ package\ are\n\n****'''::infix::core::setup'''\ ''?module\ ...?''****\nCreates\ a\ command\ '''infix'''\ in\ the\ namespace\ it\ is\ called\ from,\ \nand\ loads\ the\ listed\ ''module''s\ of\ settings\ for\ the\ little\ language\ \nof\ that\ '''infix'''\ command.\ See\ below\ for\ lists\ of\ defined\ modules\ and\ \nthe\ syntax\ of\ the\ '''infix'''\ command.\n\n****'''::infix::core::opalias'''\ \ ''name\ type\ cmd\ ?arg\ ...?''****\nDefine\ a\ new\ operation\ ''name''\ of\ type\ \n''type''\ that\ gets\ implemented\ by\ appending\ the\ operand(s)\ to\ \nthe\ command\ prefix\ ''cmd\ ?arg\ ...?'',\ as\ specified.\ Any\ previous\ \nmeaning\ of\ the\ token\ ''name''\ gets\ overwritten.\n\nThe\ possible\ ''type''s\ include:\n\ \ \ binary\ ''priority'':\ \ \ A\ binary,\ left-associative\ operation\ with\ priority\ as\ specified.\n\ \ \ binary\ ''priority\ associativity'':\ \ \ A\ binary\ operation\ with\ priority\ and\ associativity\ as\ specified.\ Possibilities\ for\ ''associativity''\ include\ '''right-associative''',\ '''non-associative''',\ and\ '''n-ary'''.\n\ \ \ prefix\ ''priority'':\ \ \ A\ unary\ prefix\ operation\ with\ priority\ as\ specified.\n\ \ \ postfix\ ''priority'':\ \ \ A\ unary\ postfix\ operation\ with\ priority\ as\ specified.\nThe\ priorities\ should\ be\ Tcl\ numbers\ (non-integers\ are\ fine).\ Higher\ priority\ means\ tighter\ binding\ to\ the\ operands.\ In\ case\ of\ equal\ priority,\ the\ associativity\ setting\ is\ used\ to\ resolve\ which\ operation\ acts\ on\ which\ operands.\ The\ standard\ modules\ uses\ priorities\ in\ the\ range\ -2\ (for\ \;)\ to\ 14\ (for\ factorial),\ with\ +\ at\ 10,\ *\ at\ 11,\ and\ **\ (right-associative)\ at\ 12.\n\nExample\ (requires\ Tcl\ 8.5):\n\ \ ::infix::core::opalias\ ++\ \{binary\ 10\}\ ::tcl::mathfunc::hypot\n(\[MetaFont\]\ uses\ `++`\ for\ \"Pythagorean\ addition\":\ length\ of\ hypothenuse\ in\ right\ triangle\ where\ other\ sides\ have\ these\ lengths.\ C\ programmers\ no\ doubt\ find\ this\ very\ strange.)\n\n****'''::infix::core::funalias'''\ ''name\ numargs\ cmd\ ?arg\ ...?''****\nDefine\ a\ new\ function\ ''name''\ with\ \n''numargs''\ arguments\ that\ gets\ implemented\ by\ appending\ the\ \nargument(s)\ to\ the\ command\ prefix\ ''cmd\ ?arg\ ...?'',\ as\ specified.\ \nAny\ previous\ meaning\ of\ the\ token\ ''name''\ gets\ overwritten.\ \n''numargs''\ may\ be\ '''any'''\ (in\ which\ case\ any\ number\ of\ arguments\ \nare\ accepted)\ or\ an\ integer.\n\n\n***The\ infix\ command***\n\nThe\ '''infix'''\ command\ has\ the\ syntax\n\ \ \ \ :\ \ \ '''infix'''\ ''symlinks\ body''\nThe\ ''body''\ is\ where\ the\ actual\ expressions\ in\ the\ infix\ little\ language\ \nare\ written\;\ the\ infix\ command\ returns\ the\ value\ of\ (the\ last\ statement\ in)\ \nthe\ body.\ The\ ''symlinks''\ argument\ links\ symbolic\ names\ appearing\ in\ \nthe\ ''body''\ to\ Tcl\ variables\ in\ the\ context\ from\ which\ ''infix''\ was\ called.\n\nThe\ format\ of\ the\ ''symlinks''\ is\ a\ list\ with\ a\ multiple\ of\ three\ elements.\ \nThe\ first\ element\ in\ a\ triplet\ is\ the\ infix\ body\ symbolic\ name.\ The\ last\ \nelement\ in\ a\ triplet\ is\ the\ external\ quantity\ to\ which\ the\ symbolic\ name\ \nis\ linked.\ The\ middle\ element\ of\ the\ triplet\ is\ an\ \"arrow\"\ that\ determines\ \nhow\ the\ two\ are\ linked:\n\ \ \ `<-`:\ \ \ Input-only\ value\;\ the\ external\ quantity\ is\ the\ name\ of\ a\ variable\ whose\ value\ is\ copied\ to\ the\ symbol.\n\ \ \ `->`:\ \ \ Output-only\ value\;\ the\ external\ quantity\ is\ the\ name\ of\ a\ variable\ which\ is\ set\ to\ the\ final\ value\ of\ the\ symbol.\n\ \ \ `<->`:\ \ \ Input&output\ value\;\ combines\ `<-`\ and\ `->`.\n\ \ \ `<=`:\ \ \ Input-only\ constant\;\ the\ external\ quantity\ becomes\ the\ value\ of\ the\ symbol.\ Useful\ for\ constants\ that\ don't\ fit\ into\ the\ infix\ body\ syntax.\n\ \ \ `<e`:\ \ \ The\ external\ quantity\ is\ evaluated\ as\ a\ script,\ and\ the\ symbol\ is\ set\ to\ the\ result\ of\ that\ script.\ (This\ is\ somewhat\ like\ using\ command\ substitution\ in\ \[expr\]\ expressions.)\nTo\ increment\ variable\ \$a\ by\ \$b\ one\ could\ do\n\ \ infix\ \{\n\ \ \ \ \ a\ <->\ a\n\ \ \ \ \ b\ <-\ \ b\n\ \ \}\ \{\ a\ :=\ a\ +\ b\ \}\nbut\ also\n\ \ infix\ \{\n\ \ \ \ \ a\ <-\ a\n\ \ \ \ \ b\ <-\ b\n\ \ \ \ \ c\ ->\ a\n\ \ \}\ \{\ c\ =\ a\ +\ b\ \}\n\n\nTo\ Be\ Continued...\n\n\n***List\ of\ modules***\n\nEach\ module\ ''module''\ is\ implemented\ by\ the\ package\ `infix::''module''`,\ so\ anyone\ can\ define\ new\ modules.\ The\ following\ are\ those\ that\ come\ with\ the\ infix\ package\ itself.\n+++\nbase\ \ \ \ \ Basic\ definitions:\ parentheses\ for\ grouping,\ `=`\ for\ definition,\ `:=`\ for\ assignment,\ semicolon\ as\ separator,\ and\ comma\ as\ list\ constructor.\nexpr::ops\ \ \ \ \ The\ unary\ and\ binary\ operations\ of\ \[expr\].\nexpr::fun\ \ \ \ \ The\ \[expr\]\ built-in\ functions.\nexpr::ternary\ \ \ \ \ The\ \[expr\]\ ternary\ `?:`\ operation.\ (See\ `ifthen`\ for\ an\ alternative.)\nsoftsemicolon\ \ \ \ \ A\ more\ forgiving\ statement\ seprator.\ The\ `base`\ semicolons\ may\ only\ appear\ ''between''\ expressions,\ but\ this\ relaxes\ the\ syntax\ so\ that\ a\ semicolon\ is\ effectively\ ignored\ if\ there\ is\ no\ expression\ after\ it.\nifthen\ \ \ \ \ Implements\ expression\ choices\ of\ the\ form\ '''if'''\ ''condition''\ '''then'''\ ''expression''\ '''else'''\ ''expression''\ '''fi'''\ (also\ allowing\ '''elseif'''\ clauses\ and\ omitting\ the\ '''else'''\ clause).\ Unlike\ `?:`,\ this\ can\ have\ semicolons\ and\ the\ like\ in\ the\ ''expression''s\ without\ a\ need\ to\ wrap\ them\ up\ in\ parentheses.\nnumconst\ \ \ \ \ Makes\ symbols\ that\ look\ like\ numeric\ constants\ be\ interpreted\ as\ such.\ (Without\ it,\ e.g.\ `0`,\ `1`,\ and\ `3.5`\ behave\ just\ like\ `x`\ and\ `y`.)\ Underscore\ is\ a\ substitute\ for\ minus\ sign\ in\ exponents:\ `3.2e_1`\ is\ 3.2*10**-1.\nbignum\ \ \ \ \ Operations\ as\ for\ `expr::ops`,\ but\ implemented\ using\ the\ \[math::bignum\]\ commands,\ with\ their\ representation\ for\ values.\ Numeric\ constants\ are\ supported,\ as\ are\ the\ postfix\ operations\ `!`\ (\[factorial\])\ and\ `!!`\ (semifactorial),\ and\ functions\ `sqrt`,\ `powm`,\ `fromstr`,\ and\ `tostr`.\ Compatible\ with\ the\ `ifthen`\ module.\nTeX::semi\ \ \ \ \ Changes\ the\ tokenizer,\ so\ that\ \[TeX\]-style\ control\ sequences\ such\ `\\alpha`\ and\ `\\cdot`\ count\ as\ tokens.\nexpr::delim\ \ \ \ \ Some\ \[expr\]-functions\ written\ as\ delimiters.\nlistbracket\ \ \ \ \ Brackets\ for\ list\ construction\ and\ indexing.\n+++\n\n**Example:\ complex\ numbers**\n\nIn\ want\ of\ a\ module\ for\ this,\ operations\ on\ complex\ numbers\ (as\ implemened\ using\ the\ \[math::complexnumbers\]\ package)\ are\ fairly\ easy\ to\ set\ up\ using\ '''opalias'''\ and\ '''funalias'''.\ First\ we\ need\ the\ basic\ \[package\ require\]s:\n\ package\ require\ infix\n\ infix::core::setup\ base\n\ package\ require\ math::complexnumbers\n\nThen\ we\ can\ define\ the\ operations\ `+`,\ `-`,\ `*`,\ `/`,\ and\ `**`:\n\ infix::core::opalias\ +\ \{binary\ 10\}\ math::complexnumbers::+\n\ infix::core::opalias\ -\ \{try\ \{binary\ 10\}\ -\ \{prefix\ 13\}\ -\}\ math::complexnumbers::-\n\ infix::core::opalias\ *\ \{binary\ 11\}\ math::complexnumbers::*\n\ infix::core::opalias\ /\ \{binary\ 11\}\ math::complexnumbers::/\n\ infix::core::opalias\ **\ \{binary\ 12\ right-associative\}\ math::complexnumbers::pow\nThe\ `try`\ part\ in\ the\ definition\ of\ `-`\ is\ because\ there\ are\ two\ common\ operations\ denoted\ by\ minus:\ subtraction\ (binary)\ and\ negation\ (unary\ prefix).\ Both\ interpretations\ are\ tried,\ in\ that\ order.\n\nDefining\ the\ functions\ should\ be\ equally\ straightforward,\ but\ as\ it\ turns\ out\ version\ 0.2\ of\ infix\ has\ a\ bug\ in\ the\ definition\ of\ infix::core::funalias,\ so\ we\ need\ to\ fix\ that\ first:\n\ proc\ ::infix::core::funalias\ \{name\ numargs\ cmd\ args\}\ \{\n\ \ \ \ set\ ns\ \[uplevel\ 1\ \{::namespace\ eval\ infix\ \{::namespace\ current\}\}\]\n\ \ \ \ set\ fcmd\ \[uplevel\ 1\ \[list\ ::namespace\ which\ -command\ \$cmd\]\]\n\ \ \ \ if\ \{\$fcmd\ eq\ \"\"\}\ then\ \{\n\ \ \ \ \ \ \ return\ -code\ error\ \"Undefined\ command:\ \$cmd\"\n\ \ \ \ \}\n\ \ \ \ set\ \$\{ns\}::tokentype(\$name)\ function\n\ \ \ \ set\ \$\{ns\}::function(\$name)\ \[list\ \$numargs\ byvalue\\\n\ \ \ \ \ \ \[list\ ::concat\ \[linsert\ \$args\ 0\ \$fcmd\]\]\]\n\ \}\nAfter\ that,\ the\ complex-valued\ functions\ are\ trivial.\n\ foreach\ fun\ \{exp\ log\ conj\ sqrt\ sin\ cos\ tan\}\ \{\n\ \ \ \ infix::core::funalias\ \$fun\ 1\ math::complexnumbers::\$fun\n\ \}\nThere\ are\ however\ also\ some\ real-valued\ functions\ which\ make\ things\ trickier,\ as\ their\ results\ cannot\ be\ used\ as\ arguments\ to\ any\ of\ the\ operations\ provided\ by\ the\ package.\ A\ solution\ in\ this\ case\ is\ to\ define\ companion\ commands\ which\ return\ complex\ numbers\ (that\ however\ has\ imaginary\ part\ 0)\ and\ let\ the\ infix\ functions\ refer\ to\ these\ instead.\n\ foreach\ fun\ \{real\ imag\ mod\ arg\}\ \{\n\ \ \ \ proc\ ::math::complexnumbers::c\$\{fun\}\ \{z\}\ \[format\ \{\n\ \ \ \ \ \ \ complex\ \[%s\ \$z\]\ 0\n\ \ \ \ \}\ \$fun\]\n\ \}\n\ foreach\ fun\ \{real\ imag\ mod\ arg\}\ \{\n\ \ \ \ infix::core::funalias\ \$fun\ 1\ math::complexnumbers::c\$\{fun\}\n\ \}\n(Here\ I'm\ putting\ the\ companions,\ e.g.\ `cimag`\ of\ `imag`,\ in\ the\ \[math::complexnumbers\]\ namespace\ too.\ A\ well-behaved\ complexnumbers\ module\ would\ rather\ put\ such\ auxilliary\ commands\ in\ its\ own\ private\ namespace\ ::infix::complexnumbers.)\n\nSome\ examples:\n\ %\ infix\ \{z\ <=\ \{2\ 0\}\}\ \{-z*z+z\}\n\ -2.0\ 0.0\n\ %\ infix\ \{z\ <=\ \{2\ 1\}\}\ \{conj(-z)\}\n\ -2.0\ 1.0\n\ %\ infix\ \{z\ <=\ \{2\ 1\}\}\ \{exp(-z)*z+z\}\n\ 2.26012464526\ 0.845360537469\n\ %\ infix\ \{z\ <=\ \{2\ 1\}\}\ \{log(-z)*z+z\}\n\ 6.28738295702\ -3.55117113296\n\ %\ infix\ \{z\ <=\ \{3\ 4\}\}\ \{mod(z)\}\n\ 5.0\ 0\n\ %\ infix\ \{z\ <=\ \{3\ 4\}\}\ \{arg(z)\}\n\ 0.927295218002\ 0\n\ %\ infix\ \{z\ <=\ \{3\ 0\}\}\ \{z**z**z\}\n\ 7.62559748499e+12\ 0.0\n\n'''Next\ step:'''\ Modify\ the\ parser\ so\ that\ complex\ constants\ can\ be\ inlined\ into\ the\ expressions.\n\n----\n**Discussion**\n\n\[Sarnold\],\ 2008-01-13:\ \[math::bignum\]\ is\ deprecated\ in\ Tcl\ 8.5,\ isn't\ it?\ But\ I\ see\ a\ real\ interest\ for\ complex\ numbers\ and\ \[math::bigfloat\]\ extension,\ for\ instance,\ to\ be\ infix'd.\ Nice\ and\ interesting\ work\ you've\ done!\n\n\[Lars\ H\]:\ Well,\ \[infix\]\ was\ written\ under\ 8.4,\ and\ (if\ memory\ serves)\ it\ wouldn't\ be\ too\ hard\ to\ get\ it\ running\ under\ 8.3\ as\ well.\ But\ the\ main\ reson\ for\ doing\ math::bignum\ was\ as\ a\ proof-of-concept\;\ demonstrating\ that\ infix\ didn't\ rely\ on\ having\ \[expr\]\ do\ the\ parsing\ or\ calculations.\ An\ extra\ module\ for\ math::complexnumber\ is\ fairly\ straightforward,\ but\ at\ the\ time\ I\ wrote\ the\ stuff\ I\ found\ \[math::bignum\]\ more\ appealing\ for\ a\ demo\ (maybe\ it\ was\ better\ documented,\ or\ had\ more\ features,\ or\ something).\ \;-)\nUpdate,\ 2008-01-14:\ See\ above\ for\ implementing\ math::complexnumbers\ operations.\n\n----\n\n\[Larry\ Smith\],\ 2008-07-01:\ I\ just\ noticed\ that\ the\ infix\ command\ sports\ a\ piece\ of\ ambiguous\ syntax.\ \ \"a<-5\"\ could\ be\ read\ as\ either\ \"a:=5\"\ OR\ as\ \"a\ <\ -5\".\ \ \n\n''\[Lars\ H\]:\ Not\ really.\ The\ arrows\ belong\ in\ the\ symlinks\ argument,\ which\ is\ strictly\ a\ list\ (hence\ spaces\ are\ required)\;\ think\ of\ it\ as\ the\ arguments\ part\ of\ a\ subroutine\ declaration.\ Expressions,\ which\ might\ involve\ less-than\ or\ minus,\ are\ written\ in\ the\ body\ argument.''\n\n\[Larry\ Smith\]\ Okay,\ I\ see\ that.\ \ I'm\ not\ sure\ what\ it\ buys,\ though.\ \ It's\ nice\ to\ have\ that\ kind\ of\ control,\ but\ not\ at\ the\ expense\ of\ a\ great\ deal\ of\ complexity\ or\ code.\ \ Why\ not\ something\ like:\n\n\ infix\ \{\n\ \ in\ a\ b\ c\n\ \ out\ d\ e\ f\n\ \ inout\ g\n\ \}\ ...\n\nIt\ does\ not\ require\ people\ to\ know\ your\ convention\ using\ arrows.\ \ It\ lacks\ the\ ability\ to\ specify\ mappings\ in\ great\ detail,\ but\ that\ seems\ to\ be\ a\ feature\ in\ search\ of\ a\ problem.\ \ Even\ the\ in/out\ lists\ seem\ a\ little\ over-specified\ to\ me.\n\n\[Lars\ H\]:\ Yes,\ that's\ the\ kind\ of\ thing\ I'm\ aiming\ at\ myself,\ although\ for\ slightly\ different\ reasons.\ In\ the\ present\ version,\ the\ \"infix\ variables\"\ are\ simply\ entires\ in\ an\ array\ that\ the\ compiled\ body\ accesses,\ so\ it\ makes\ sense\ for\ the\ symlinks\ to\ simply\ specify\ what\ to\ copy\ into\ the\ array\ at\ start\ and\ what\ to\ copy\ out\ of\ it\ at,\ but\ when\ I\ had\ completed\ the\ system\ it\ became\ apparent\ that\ this\ simple\ model\ had\ its\ flaws.\ In\ particular,\ several\ things\ could\ be\ compiled\ much\ better\ if\ I\ could\ know\ for\ sure\ whether\ a\ particular\ symbol\ would\ be\ defined\ at\ a\ particular\ point\ in\ the\ program\ or\ not.\n\nFor\ efficiency\ reasons,\ I\ want\ to\ use\ the\ ''body''\ argument\ as\ index\ into\ the\ array\ that\ stores\ compiled\ code\ (its\ hash\ gets\ cached\ in\ the\ \[Tcl_Obj\]).\ This\ is\ only\ possible\ if\ the\ compiled\ code\ depends\ only\ on\ the\ ''body''\ argument,\ so\ it\ needs\ to\ contain\ all\ '''in''',\ '''out''',\ and\ '''inout'''\ declarations,\ pretty\ much\ as\ in\ your\ example\ above.\ The\ tricky\ part\ for\ which\ I\ have\ not\ yet\ found\ a\ satisfactory\ solution\ is\ how\ to\ combine\ the\ totally\ flexible\ syntax\ of\ \[infix\]\ bodies\ with\ the\ fixed\ roles\ of\ '''in''',\ '''out''',\ and\ '''inout'''\ declarations.\ Some\ possibilities\ include:\n\ \ \ 1.\ Make\ '''in''',\ '''out''',\ and\ '''inout'''\ tokens\ of\ some\ new\ type,\ that\ are\ declared\ in\ the\ `base`\ module.\ This\ has\ the\ disadvantage\ that\ these\ names\ are\ then\ not\ available\ for\ symbols.\n\ \ \ 2.\ Designate\ a\ \"delimiter\",\ such\ that\ text\ before\ it\ is\ declarations\ and\ can\ follow\ other\ syntax\ rules\ than\ the\ expressions\ below\ it.\ This\ has\ the\ disadvantage\ that\ it\ feels\ like\ a\ hack.\nMy\ undecidedness\ on\ this\ matter\ is\ the\ primary\ reason\ \[infix\]\ hasn't\ evolved\ further.\ (A\ close\ second\ is\ the\ many\ other\ projects\ I've\ been\ working\ on\ in\ the\ meantime.)\n\n\[Larry\ Smith\]\ And\ another\ thing:\ we\ go\ to\ a\ lot\ of\ trouble\ to\ support\ unicode\ and\ then\ we\ use\ \"<-\"\ instead\ of\ \\u2190\ (←)?\ \ As\ Ice-T\ would\ say,\ \"Whut's\ up\ wid\ dat?\"\ \n\n\[Lars\ H\]:\ Even\ if\ the\ language\ (and\ package)\ have\ no\ problem\ with\ them,\ the\ same\ need\ not\ be\ true\ for\ users'\ Development\ Environment\ as\ a\ whole:\ editors\ may\ be\ restricted\ to\ 8-bit\ character\ sets,\ and\ even\ if\ they\ aren't\ there\ needn't\ be\ a\ convenient\ way\ to\ type\ ←.\ Requiring\ users\ to\ type\ it\ (or\ \\u2190\ which\ would\ work\ fine\ ''as\ the\ symlinks\ is\ just\ a\ list'')\ is\ far\ less\ unfriendly,\ especially\ as\ it\ is\ part\ of\ the\ fixed\ syntax\ of\ the\ \[infix\]\ command.\ For\ the\ configurable\ \[little\ language\]\ found\ in\ the\ body,\ Unicode\ symbols\ are\ sometimes\ obvious\ choices\ —\ when\ coding\ the\ math::complexnumbers\ stuff\ above\ I\ actually\ considered\ defining\ a\ Weierstrass\ ℘\ or\ Euler\ Γ\ function\ just\ to\ show\ off\ this\ aspect,\ but\ I\ skipped\ that\ since\ I\ couldn't\ find\ an\ ready-to-use\ implementation.\n\n\[Larry\ Smith\](again)\ This\ brings\ up\ an\ interesting\ point\ that\ I\ will\ just\ throw\ out\ for\ discussion:\ when,\ I\ ask,\ ''will''\ it\ be\ reasonable\ to\ expect\ that\ any\ user\ could\ reasonably\ be\ expected\ to\ type\ a\ unicode\ character\ as\ ''as\ such''\ in\ a\ program?\ \ In\ my\ opinion\ we\ are\ already\ past\ this\ point:\ virtually\ all\ the\ editors\ I\ use\ regularly\ have\ no\ problem\ at\ all\ with\ unicode.\ \ vi\ does,\ but\ I\ suspect\ there\ are\ few\ die-hard\ vi\ users\ that\ use\ a\ lot\ of\ tcl.\ \ Unicode\ presents\ a\ cornucopia\ of\ symbols\ that\ can\ be\ made\ to\ serve\ useful\ ends\ -\ admittedly\ some\ of\ those\ ends\ could\ be\ evil\ (there\ are\ thousands\ of\ characters\ to\ abuse).\ \ It's\ been\ in\ the\ language\ now\ for\ years,\ so\ when\ can\ the\ cobbler's\ children\ use\ them?\n\n\[Lars\ H\]:\ FWIW,\ my\ particular\ editor\ of\ choice\ (\[Alpha\])\ unfortunately\ still\ doesn't\ support\ Unicode\ in\ documents\ (although\ it\ uses\ Tcl\ as\ scripting\ language,\ and\ thus\ can\ handle\ Unicode\ for\ internal\ processing,\ the\ text\ buffer\ code\ is\ written\ in\ C\ and\ years\ overdue\ for\ a\ rewrite).\ Also,\ one\ shouldn't\ underestimate\ the\ portability\ problems\ encountered\ when\ code\ is\ not\ pure\ ASCII\;\ the\ default\ for\ \[source\]\ is\ \[encoding\ system\],\ and\ as\ long\ as\ you\ find\ systems\ where\ that\ is\ iso8859-1,\ there\ will\ be\ problems.\n\n----\n\[AM\]\ (16\ march\ 2010)\ Here\ is\ a\ simple\ example\ of\ how\ you\ can\ apply\ this\ package.\ The\ program\ below\ uses\ it\ to\ implement\ the\ kind\ of\ array\ processing\ one\ finds\ in\ MATLAB\ or\ Fortran\ (90/95/2003):\n\n======\n#\ example.tcl\ --\n#\ \ \ \ \ Example\ of\ the\ use\ of\ the\ infix\ package\n#\npackage\ require\ infix\n\n#\ add\ --\n#\ \ \ \ \ Add\ the\ elements\ of\ two\ lists\n#\n#\ Arguments:\n#\ \ \ \ \ alist\ \ \ \ \ \ \ First\ list\n#\ \ \ \ \ blist\ \ \ \ \ \ \ Second\ list\n#\n#\ Returns:\n#\ \ \ \ \ List\ of\ the\ sum\ of\ the\ elements\ of\ the\ two\ lists\n#\n#\ Note:\n#\ \ \ \ \ The\ arguments\ may\ also\ be\ scalars\n#\nproc\ add\ \{alist\ blist\}\ \{\n\ \ \ \ set\ result\ \{\}\n\n\ \ \ \ if\ \{\ \[llength\ \$alist\]\ ==\ \[llength\ \$blist\]\ \}\ \{\n\ \ \ \ \ \ \ \ foreach\ a\ \$alist\ b\ \$blist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ +\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ elseif\ \{\ \[llength\ \$alist\]\ ==\ 1\ \}\ \{\n\ \ \ \ \ \ \ \ set\ a\ \$alist\n\ \ \ \ \ \ \ \ foreach\ b\ \$blist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ +\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ elseif\ \{\ \[llength\ \$blist\]\ ==\ 1\ \}\ \{\n\ \ \ \ \ \ \ \ set\ b\ \$blist\n\ \ \ \ \ \ \ \ foreach\ a\ \$alist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ +\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ +\ \$b\}\]\n\ \ \ \ \}\n\ \ \ \ return\ \$result\n\}\n\n#\ mult\ --\n#\ \ \ \ \ Multiply\ the\ elements\ of\ two\ lists\n#\n#\ Arguments:\n#\ \ \ \ \ alist\ \ \ \ \ \ \ First\ list\n#\ \ \ \ \ blist\ \ \ \ \ \ \ Second\ list\n#\n#\ Returns:\n#\ \ \ \ \ List\ of\ the\ product\ of\ the\ elements\ of\ the\ two\ lists\n#\n#\ Note:\n#\ \ \ \ \ The\ arguments\ may\ also\ be\ scalars\n#\nproc\ mult\ \{alist\ blist\}\ \{\n\ \ \ \ set\ result\ \{\}\n\n\ \ \ \ if\ \{\ \[llength\ \$alist\]\ ==\ \[llength\ \$blist\]\ \}\ \{\n\ \ \ \ \ \ \ \ foreach\ a\ \$alist\ b\ \$blist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ *\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ elseif\ \{\ \[llength\ \$alist\]\ ==\ 1\ \}\ \{\n\ \ \ \ \ \ \ \ set\ a\ \$alist\n\ \ \ \ \ \ \ \ foreach\ b\ \$blist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ *\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ elseif\ \{\ \[llength\ \$blist\]\ ==\ 1\ \}\ \{\n\ \ \ \ \ \ \ \ set\ b\ \$blist\n\ \ \ \ \ \ \ \ foreach\ a\ \$alist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ *\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ *\ \$b\}\]\n\ \ \ \ \}\n\ \ \ \ return\ \$result\n\}\n\n#\ main\ --\n#\ \ \ \ \ Test\ it\n#\n::infix::core::setup\ base\n::infix::core::opalias\ +\ \{binary\ 10\}\ add\n::infix::core::opalias\ *\ \{binary\ 15\}\ mult\n\nset\ a\ \{1\ 2\ 3\ 4\}\nset\ b\ \{2\ 4\ 6\ 7\}\nset\ c\ 2\n\nputs\ \[infix\ \{a\ <-\ a\ b\ <-\ b\}\ \{\ \n\ \ \ \ \ \ \ \ \ \ a\ +\ b\ \}\]\nputs\ \[infix\ \{a\ <-\ a\ b\ <-\ b\ c\ <-\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ a\ +\ c*b\ \}\]\n\n#\n#\ Timing\n#\nproc\ addmult\ \{alist\ blist\ c\}\ \{\n\ \ \ \ set\ result\ \{\}\n\ \ \ \ foreach\ a\ \$alist\ b\ \$blist\ \{\n\ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ +\ \$c\ *\ \$b\}\]\n\ \ \ \ \}\n\ \ \ \ return\ \$result\n\}\n\nputs\ \"Direct:\ \ \ \ \[time\ \{addmult\ \$a\ \$b\ \$c\}\ 1000\]\"\nputs\ \"Via\ infix:\ \[time\ \{infix\ \{a\ <-\ a\ b\ <-\ b\ c\ <-\ c\}\ \{\ a\ +\ c*b\ \}\}\ 1000\]\"\ \ \ \ \ \ \n======\n\nThe\ output:\n======\n3\ 6\ 9\ 11\n5\ 10\ 15\ 18\nDirect:\ \ \ \ 3.48\ microseconds\ per\ iteration\nVia\ infix:\ 15.999\ microseconds\ per\ iteration\n=======\n\n(Just\ to\ get\ an\ impression)\n----\n!!!!!!\n%|\ \[Category\ Package\]\ |\ \[Category\ Mathematics\]\ |%\n!!!!!! regexp2} CALL {my render infix One\ of\ the\ styles\ for\ writing\ expressions,\ with\ operations\ '''in-between'''\ the\ operands\ (e.g.\ `6\ *\ 7`),\ as\ contrasted\ to\ ''postfix''\ (e.g.\ `6\ 7\ *`\;\ operations\ follow\ operands,\ as\ in\ \[RPN\])\ and\ ''prefix''\ (e.g.\ `*\ 6\ 7`\;\ operations\ come\ before\ operands,\ as\ in\ \[Tcl\]\ in\ general).\ Infix\ notation\ for\ mathematical\ expressions\ is\ by\ far\ the\ most\ common,\ and\ is\ in\ Tcl\ supported\ by\ \[expr\].\n\n----\nAs\ of\ 2006-10-14,\ \[infix\]\ is\ also\ the\ name\ of\ a\ Tcl\ package\ (and\ command\ defined\ by\ this\ package)\ that\ lets\ programmers\ write\ sequences\ of\ mathematical\ formulae\ in\ the\ familiar\ infix\ form.\ A\ short\ example:\n\ \ package\ require\ infix\ 0.2\n\ \ ::infix::core::setup\ base\ numconst\ expr::ops\ expr::fun\n\ \ proc\ ngon_corner\ \{num_sides\ radius\}\ \{\n\ \ \ \ \ infix\ \{\n\ \ \ \ \ \ \ \ n\ <-\ num_sides\n\ \ \ \ \ \ \ \ r\ <-\ radius\n\ \ \ \ \ \}\ \{\n\ \ \ \ \ \ \ \ alpha\ =\ acos(-1)\ /\ n\ \;\ \ #\ acos(-1)\ =\ pi\n\ \ \ \ \ \ \ \ r*cos(alpha),\ r*sin(alpha)\n\ \ \ \ \ \}\n\ \ \}\n\ \ ngon_corner\ 6\ 10\ \;\ #\ Returns\ \"8.66025403784\ 5.0\"\ -\ a\ two\ element\ list\n\nA\ notable\ feature\ is\ that\ the\ \[little\ language\]\ implemented\ by\ this\ package\ is\ completely\ configurable\ (setting\ it\ up\ for\ \[expr\]-like\ operations\ is\ what\ the\ ::infix::core::setup\ command\ does),\ so\ you\ can\ define\ new\ operations,\ or\ define\ the\ usual\ ones\ to\ do\ something\ unusual.\ A\ setting\ that\ turns\ +,\ -,\ etc.\ into\ the\ operations\ of\ the\ \[math::bignum\]\ package\ is\ included\ with\ the\ infix\ package.\n\nThe\ code\ is\ available\ at\n\ \ http://abel.math.umu.se/~lars/tcl/infix.tar.gz\n(requires\ tcllib,\ tcllib\ 1.8\ is\ sufficient).\n\nA\ paper\ on\ the\ package\ (which\ includes\ the\ entire\ source\ code,\ commented\ and\ explained)\ is\ available\ at\n\ \ http://abel.math.umu.se/~lars/tcl/infix.pdf\n\n--\ \[Lars\ H\]\n\n----\n\n**Some\ kind\ of\ a\ user's\ manual\ (incomplete)**\n\nThe\ user\ commands\ created\ by\ the\ package\ are\n\n****'''::infix::core::setup'''\ ''?module\ ...?''****\nCreates\ a\ command\ '''infix'''\ in\ the\ namespace\ it\ is\ called\ from,\ \nand\ loads\ the\ listed\ ''module''s\ of\ settings\ for\ the\ little\ language\ \nof\ that\ '''infix'''\ command.\ See\ below\ for\ lists\ of\ defined\ modules\ and\ \nthe\ syntax\ of\ the\ '''infix'''\ command.\n\n****'''::infix::core::opalias'''\ \ ''name\ type\ cmd\ ?arg\ ...?''****\nDefine\ a\ new\ operation\ ''name''\ of\ type\ \n''type''\ that\ gets\ implemented\ by\ appending\ the\ operand(s)\ to\ \nthe\ command\ prefix\ ''cmd\ ?arg\ ...?'',\ as\ specified.\ Any\ previous\ \nmeaning\ of\ the\ token\ ''name''\ gets\ overwritten.\n\nThe\ possible\ ''type''s\ include:\n\ \ \ binary\ ''priority'':\ \ \ A\ binary,\ left-associative\ operation\ with\ priority\ as\ specified.\n\ \ \ binary\ ''priority\ associativity'':\ \ \ A\ binary\ operation\ with\ priority\ and\ associativity\ as\ specified.\ Possibilities\ for\ ''associativity''\ include\ '''right-associative''',\ '''non-associative''',\ and\ '''n-ary'''.\n\ \ \ prefix\ ''priority'':\ \ \ A\ unary\ prefix\ operation\ with\ priority\ as\ specified.\n\ \ \ postfix\ ''priority'':\ \ \ A\ unary\ postfix\ operation\ with\ priority\ as\ specified.\nThe\ priorities\ should\ be\ Tcl\ numbers\ (non-integers\ are\ fine).\ Higher\ priority\ means\ tighter\ binding\ to\ the\ operands.\ In\ case\ of\ equal\ priority,\ the\ associativity\ setting\ is\ used\ to\ resolve\ which\ operation\ acts\ on\ which\ operands.\ The\ standard\ modules\ uses\ priorities\ in\ the\ range\ -2\ (for\ \;)\ to\ 14\ (for\ factorial),\ with\ +\ at\ 10,\ *\ at\ 11,\ and\ **\ (right-associative)\ at\ 12.\n\nExample\ (requires\ Tcl\ 8.5):\n\ \ ::infix::core::opalias\ ++\ \{binary\ 10\}\ ::tcl::mathfunc::hypot\n(\[MetaFont\]\ uses\ `++`\ for\ \"Pythagorean\ addition\":\ length\ of\ hypothenuse\ in\ right\ triangle\ where\ other\ sides\ have\ these\ lengths.\ C\ programmers\ no\ doubt\ find\ this\ very\ strange.)\n\n****'''::infix::core::funalias'''\ ''name\ numargs\ cmd\ ?arg\ ...?''****\nDefine\ a\ new\ function\ ''name''\ with\ \n''numargs''\ arguments\ that\ gets\ implemented\ by\ appending\ the\ \nargument(s)\ to\ the\ command\ prefix\ ''cmd\ ?arg\ ...?'',\ as\ specified.\ \nAny\ previous\ meaning\ of\ the\ token\ ''name''\ gets\ overwritten.\ \n''numargs''\ may\ be\ '''any'''\ (in\ which\ case\ any\ number\ of\ arguments\ \nare\ accepted)\ or\ an\ integer.\n\n\n***The\ infix\ command***\n\nThe\ '''infix'''\ command\ has\ the\ syntax\n\ \ \ \ :\ \ \ '''infix'''\ ''symlinks\ body''\nThe\ ''body''\ is\ where\ the\ actual\ expressions\ in\ the\ infix\ little\ language\ \nare\ written\;\ the\ infix\ command\ returns\ the\ value\ of\ (the\ last\ statement\ in)\ \nthe\ body.\ The\ ''symlinks''\ argument\ links\ symbolic\ names\ appearing\ in\ \nthe\ ''body''\ to\ Tcl\ variables\ in\ the\ context\ from\ which\ ''infix''\ was\ called.\n\nThe\ format\ of\ the\ ''symlinks''\ is\ a\ list\ with\ a\ multiple\ of\ three\ elements.\ \nThe\ first\ element\ in\ a\ triplet\ is\ the\ infix\ body\ symbolic\ name.\ The\ last\ \nelement\ in\ a\ triplet\ is\ the\ external\ quantity\ to\ which\ the\ symbolic\ name\ \nis\ linked.\ The\ middle\ element\ of\ the\ triplet\ is\ an\ \"arrow\"\ that\ determines\ \nhow\ the\ two\ are\ linked:\n\ \ \ `<-`:\ \ \ Input-only\ value\;\ the\ external\ quantity\ is\ the\ name\ of\ a\ variable\ whose\ value\ is\ copied\ to\ the\ symbol.\n\ \ \ `->`:\ \ \ Output-only\ value\;\ the\ external\ quantity\ is\ the\ name\ of\ a\ variable\ which\ is\ set\ to\ the\ final\ value\ of\ the\ symbol.\n\ \ \ `<->`:\ \ \ Input&output\ value\;\ combines\ `<-`\ and\ `->`.\n\ \ \ `<=`:\ \ \ Input-only\ constant\;\ the\ external\ quantity\ becomes\ the\ value\ of\ the\ symbol.\ Useful\ for\ constants\ that\ don't\ fit\ into\ the\ infix\ body\ syntax.\n\ \ \ `<e`:\ \ \ The\ external\ quantity\ is\ evaluated\ as\ a\ script,\ and\ the\ symbol\ is\ set\ to\ the\ result\ of\ that\ script.\ (This\ is\ somewhat\ like\ using\ command\ substitution\ in\ \[expr\]\ expressions.)\nTo\ increment\ variable\ \$a\ by\ \$b\ one\ could\ do\n\ \ infix\ \{\n\ \ \ \ \ a\ <->\ a\n\ \ \ \ \ b\ <-\ \ b\n\ \ \}\ \{\ a\ :=\ a\ +\ b\ \}\nbut\ also\n\ \ infix\ \{\n\ \ \ \ \ a\ <-\ a\n\ \ \ \ \ b\ <-\ b\n\ \ \ \ \ c\ ->\ a\n\ \ \}\ \{\ c\ =\ a\ +\ b\ \}\n\n\nTo\ Be\ Continued...\n\n\n***List\ of\ modules***\n\nEach\ module\ ''module''\ is\ implemented\ by\ the\ package\ `infix::''module''`,\ so\ anyone\ can\ define\ new\ modules.\ The\ following\ are\ those\ that\ come\ with\ the\ infix\ package\ itself.\n+++\nbase\ \ \ \ \ Basic\ definitions:\ parentheses\ for\ grouping,\ `=`\ for\ definition,\ `:=`\ for\ assignment,\ semicolon\ as\ separator,\ and\ comma\ as\ list\ constructor.\nexpr::ops\ \ \ \ \ The\ unary\ and\ binary\ operations\ of\ \[expr\].\nexpr::fun\ \ \ \ \ The\ \[expr\]\ built-in\ functions.\nexpr::ternary\ \ \ \ \ The\ \[expr\]\ ternary\ `?:`\ operation.\ (See\ `ifthen`\ for\ an\ alternative.)\nsoftsemicolon\ \ \ \ \ A\ more\ forgiving\ statement\ seprator.\ The\ `base`\ semicolons\ may\ only\ appear\ ''between''\ expressions,\ but\ this\ relaxes\ the\ syntax\ so\ that\ a\ semicolon\ is\ effectively\ ignored\ if\ there\ is\ no\ expression\ after\ it.\nifthen\ \ \ \ \ Implements\ expression\ choices\ of\ the\ form\ '''if'''\ ''condition''\ '''then'''\ ''expression''\ '''else'''\ ''expression''\ '''fi'''\ (also\ allowing\ '''elseif'''\ clauses\ and\ omitting\ the\ '''else'''\ clause).\ Unlike\ `?:`,\ this\ can\ have\ semicolons\ and\ the\ like\ in\ the\ ''expression''s\ without\ a\ need\ to\ wrap\ them\ up\ in\ parentheses.\nnumconst\ \ \ \ \ Makes\ symbols\ that\ look\ like\ numeric\ constants\ be\ interpreted\ as\ such.\ (Without\ it,\ e.g.\ `0`,\ `1`,\ and\ `3.5`\ behave\ just\ like\ `x`\ and\ `y`.)\ Underscore\ is\ a\ substitute\ for\ minus\ sign\ in\ exponents:\ `3.2e_1`\ is\ 3.2*10**-1.\nbignum\ \ \ \ \ Operations\ as\ for\ `expr::ops`,\ but\ implemented\ using\ the\ \[math::bignum\]\ commands,\ with\ their\ representation\ for\ values.\ Numeric\ constants\ are\ supported,\ as\ are\ the\ postfix\ operations\ `!`\ (\[factorial\])\ and\ `!!`\ (semifactorial),\ and\ functions\ `sqrt`,\ `powm`,\ `fromstr`,\ and\ `tostr`.\ Compatible\ with\ the\ `ifthen`\ module.\nTeX::semi\ \ \ \ \ Changes\ the\ tokenizer,\ so\ that\ \[TeX\]-style\ control\ sequences\ such\ `\\alpha`\ and\ `\\cdot`\ count\ as\ tokens.\nexpr::delim\ \ \ \ \ Some\ \[expr\]-functions\ written\ as\ delimiters.\nlistbracket\ \ \ \ \ Brackets\ for\ list\ construction\ and\ indexing.\n+++\n\n**Example:\ complex\ numbers**\n\nIn\ want\ of\ a\ module\ for\ this,\ operations\ on\ complex\ numbers\ (as\ implemened\ using\ the\ \[math::complexnumbers\]\ package)\ are\ fairly\ easy\ to\ set\ up\ using\ '''opalias'''\ and\ '''funalias'''.\ First\ we\ need\ the\ basic\ \[package\ require\]s:\n\ package\ require\ infix\n\ infix::core::setup\ base\n\ package\ require\ math::complexnumbers\n\nThen\ we\ can\ define\ the\ operations\ `+`,\ `-`,\ `*`,\ `/`,\ and\ `**`:\n\ infix::core::opalias\ +\ \{binary\ 10\}\ math::complexnumbers::+\n\ infix::core::opalias\ -\ \{try\ \{binary\ 10\}\ -\ \{prefix\ 13\}\ -\}\ math::complexnumbers::-\n\ infix::core::opalias\ *\ \{binary\ 11\}\ math::complexnumbers::*\n\ infix::core::opalias\ /\ \{binary\ 11\}\ math::complexnumbers::/\n\ infix::core::opalias\ **\ \{binary\ 12\ right-associative\}\ math::complexnumbers::pow\nThe\ `try`\ part\ in\ the\ definition\ of\ `-`\ is\ because\ there\ are\ two\ common\ operations\ denoted\ by\ minus:\ subtraction\ (binary)\ and\ negation\ (unary\ prefix).\ Both\ interpretations\ are\ tried,\ in\ that\ order.\n\nDefining\ the\ functions\ should\ be\ equally\ straightforward,\ but\ as\ it\ turns\ out\ version\ 0.2\ of\ infix\ has\ a\ bug\ in\ the\ definition\ of\ infix::core::funalias,\ so\ we\ need\ to\ fix\ that\ first:\n\ proc\ ::infix::core::funalias\ \{name\ numargs\ cmd\ args\}\ \{\n\ \ \ \ set\ ns\ \[uplevel\ 1\ \{::namespace\ eval\ infix\ \{::namespace\ current\}\}\]\n\ \ \ \ set\ fcmd\ \[uplevel\ 1\ \[list\ ::namespace\ which\ -command\ \$cmd\]\]\n\ \ \ \ if\ \{\$fcmd\ eq\ \"\"\}\ then\ \{\n\ \ \ \ \ \ \ return\ -code\ error\ \"Undefined\ command:\ \$cmd\"\n\ \ \ \ \}\n\ \ \ \ set\ \$\{ns\}::tokentype(\$name)\ function\n\ \ \ \ set\ \$\{ns\}::function(\$name)\ \[list\ \$numargs\ byvalue\\\n\ \ \ \ \ \ \[list\ ::concat\ \[linsert\ \$args\ 0\ \$fcmd\]\]\]\n\ \}\nAfter\ that,\ the\ complex-valued\ functions\ are\ trivial.\n\ foreach\ fun\ \{exp\ log\ conj\ sqrt\ sin\ cos\ tan\}\ \{\n\ \ \ \ infix::core::funalias\ \$fun\ 1\ math::complexnumbers::\$fun\n\ \}\nThere\ are\ however\ also\ some\ real-valued\ functions\ which\ make\ things\ trickier,\ as\ their\ results\ cannot\ be\ used\ as\ arguments\ to\ any\ of\ the\ operations\ provided\ by\ the\ package.\ A\ solution\ in\ this\ case\ is\ to\ define\ companion\ commands\ which\ return\ complex\ numbers\ (that\ however\ has\ imaginary\ part\ 0)\ and\ let\ the\ infix\ functions\ refer\ to\ these\ instead.\n\ foreach\ fun\ \{real\ imag\ mod\ arg\}\ \{\n\ \ \ \ proc\ ::math::complexnumbers::c\$\{fun\}\ \{z\}\ \[format\ \{\n\ \ \ \ \ \ \ complex\ \[%s\ \$z\]\ 0\n\ \ \ \ \}\ \$fun\]\n\ \}\n\ foreach\ fun\ \{real\ imag\ mod\ arg\}\ \{\n\ \ \ \ infix::core::funalias\ \$fun\ 1\ math::complexnumbers::c\$\{fun\}\n\ \}\n(Here\ I'm\ putting\ the\ companions,\ e.g.\ `cimag`\ of\ `imag`,\ in\ the\ \[math::complexnumbers\]\ namespace\ too.\ A\ well-behaved\ complexnumbers\ module\ would\ rather\ put\ such\ auxilliary\ commands\ in\ its\ own\ private\ namespace\ ::infix::complexnumbers.)\n\nSome\ examples:\n\ %\ infix\ \{z\ <=\ \{2\ 0\}\}\ \{-z*z+z\}\n\ -2.0\ 0.0\n\ %\ infix\ \{z\ <=\ \{2\ 1\}\}\ \{conj(-z)\}\n\ -2.0\ 1.0\n\ %\ infix\ \{z\ <=\ \{2\ 1\}\}\ \{exp(-z)*z+z\}\n\ 2.26012464526\ 0.845360537469\n\ %\ infix\ \{z\ <=\ \{2\ 1\}\}\ \{log(-z)*z+z\}\n\ 6.28738295702\ -3.55117113296\n\ %\ infix\ \{z\ <=\ \{3\ 4\}\}\ \{mod(z)\}\n\ 5.0\ 0\n\ %\ infix\ \{z\ <=\ \{3\ 4\}\}\ \{arg(z)\}\n\ 0.927295218002\ 0\n\ %\ infix\ \{z\ <=\ \{3\ 0\}\}\ \{z**z**z\}\n\ 7.62559748499e+12\ 0.0\n\n'''Next\ step:'''\ Modify\ the\ parser\ so\ that\ complex\ constants\ can\ be\ inlined\ into\ the\ expressions.\n\n----\n**Discussion**\n\n\[Sarnold\],\ 2008-01-13:\ \[math::bignum\]\ is\ deprecated\ in\ Tcl\ 8.5,\ isn't\ it?\ But\ I\ see\ a\ real\ interest\ for\ complex\ numbers\ and\ \[math::bigfloat\]\ extension,\ for\ instance,\ to\ be\ infix'd.\ Nice\ and\ interesting\ work\ you've\ done!\n\n\[Lars\ H\]:\ Well,\ \[infix\]\ was\ written\ under\ 8.4,\ and\ (if\ memory\ serves)\ it\ wouldn't\ be\ too\ hard\ to\ get\ it\ running\ under\ 8.3\ as\ well.\ But\ the\ main\ reson\ for\ doing\ math::bignum\ was\ as\ a\ proof-of-concept\;\ demonstrating\ that\ infix\ didn't\ rely\ on\ having\ \[expr\]\ do\ the\ parsing\ or\ calculations.\ An\ extra\ module\ for\ math::complexnumber\ is\ fairly\ straightforward,\ but\ at\ the\ time\ I\ wrote\ the\ stuff\ I\ found\ \[math::bignum\]\ more\ appealing\ for\ a\ demo\ (maybe\ it\ was\ better\ documented,\ or\ had\ more\ features,\ or\ something).\ \;-)\nUpdate,\ 2008-01-14:\ See\ above\ for\ implementing\ math::complexnumbers\ operations.\n\n----\n\n\[Larry\ Smith\],\ 2008-07-01:\ I\ just\ noticed\ that\ the\ infix\ command\ sports\ a\ piece\ of\ ambiguous\ syntax.\ \ \"a<-5\"\ could\ be\ read\ as\ either\ \"a:=5\"\ OR\ as\ \"a\ <\ -5\".\ \ \n\n''\[Lars\ H\]:\ Not\ really.\ The\ arrows\ belong\ in\ the\ symlinks\ argument,\ which\ is\ strictly\ a\ list\ (hence\ spaces\ are\ required)\;\ think\ of\ it\ as\ the\ arguments\ part\ of\ a\ subroutine\ declaration.\ Expressions,\ which\ might\ involve\ less-than\ or\ minus,\ are\ written\ in\ the\ body\ argument.''\n\n\[Larry\ Smith\]\ Okay,\ I\ see\ that.\ \ I'm\ not\ sure\ what\ it\ buys,\ though.\ \ It's\ nice\ to\ have\ that\ kind\ of\ control,\ but\ not\ at\ the\ expense\ of\ a\ great\ deal\ of\ complexity\ or\ code.\ \ Why\ not\ something\ like:\n\n\ infix\ \{\n\ \ in\ a\ b\ c\n\ \ out\ d\ e\ f\n\ \ inout\ g\n\ \}\ ...\n\nIt\ does\ not\ require\ people\ to\ know\ your\ convention\ using\ arrows.\ \ It\ lacks\ the\ ability\ to\ specify\ mappings\ in\ great\ detail,\ but\ that\ seems\ to\ be\ a\ feature\ in\ search\ of\ a\ problem.\ \ Even\ the\ in/out\ lists\ seem\ a\ little\ over-specified\ to\ me.\n\n\[Lars\ H\]:\ Yes,\ that's\ the\ kind\ of\ thing\ I'm\ aiming\ at\ myself,\ although\ for\ slightly\ different\ reasons.\ In\ the\ present\ version,\ the\ \"infix\ variables\"\ are\ simply\ entires\ in\ an\ array\ that\ the\ compiled\ body\ accesses,\ so\ it\ makes\ sense\ for\ the\ symlinks\ to\ simply\ specify\ what\ to\ copy\ into\ the\ array\ at\ start\ and\ what\ to\ copy\ out\ of\ it\ at,\ but\ when\ I\ had\ completed\ the\ system\ it\ became\ apparent\ that\ this\ simple\ model\ had\ its\ flaws.\ In\ particular,\ several\ things\ could\ be\ compiled\ much\ better\ if\ I\ could\ know\ for\ sure\ whether\ a\ particular\ symbol\ would\ be\ defined\ at\ a\ particular\ point\ in\ the\ program\ or\ not.\n\nFor\ efficiency\ reasons,\ I\ want\ to\ use\ the\ ''body''\ argument\ as\ index\ into\ the\ array\ that\ stores\ compiled\ code\ (its\ hash\ gets\ cached\ in\ the\ \[Tcl_Obj\]).\ This\ is\ only\ possible\ if\ the\ compiled\ code\ depends\ only\ on\ the\ ''body''\ argument,\ so\ it\ needs\ to\ contain\ all\ '''in''',\ '''out''',\ and\ '''inout'''\ declarations,\ pretty\ much\ as\ in\ your\ example\ above.\ The\ tricky\ part\ for\ which\ I\ have\ not\ yet\ found\ a\ satisfactory\ solution\ is\ how\ to\ combine\ the\ totally\ flexible\ syntax\ of\ \[infix\]\ bodies\ with\ the\ fixed\ roles\ of\ '''in''',\ '''out''',\ and\ '''inout'''\ declarations.\ Some\ possibilities\ include:\n\ \ \ 1.\ Make\ '''in''',\ '''out''',\ and\ '''inout'''\ tokens\ of\ some\ new\ type,\ that\ are\ declared\ in\ the\ `base`\ module.\ This\ has\ the\ disadvantage\ that\ these\ names\ are\ then\ not\ available\ for\ symbols.\n\ \ \ 2.\ Designate\ a\ \"delimiter\",\ such\ that\ text\ before\ it\ is\ declarations\ and\ can\ follow\ other\ syntax\ rules\ than\ the\ expressions\ below\ it.\ This\ has\ the\ disadvantage\ that\ it\ feels\ like\ a\ hack.\nMy\ undecidedness\ on\ this\ matter\ is\ the\ primary\ reason\ \[infix\]\ hasn't\ evolved\ further.\ (A\ close\ second\ is\ the\ many\ other\ projects\ I've\ been\ working\ on\ in\ the\ meantime.)\n\n\[Larry\ Smith\]\ And\ another\ thing:\ we\ go\ to\ a\ lot\ of\ trouble\ to\ support\ unicode\ and\ then\ we\ use\ \"<-\"\ instead\ of\ \\u2190\ (←)?\ \ As\ Ice-T\ would\ say,\ \"Whut's\ up\ wid\ dat?\"\ \n\n\[Lars\ H\]:\ Even\ if\ the\ language\ (and\ package)\ have\ no\ problem\ with\ them,\ the\ same\ need\ not\ be\ true\ for\ users'\ Development\ Environment\ as\ a\ whole:\ editors\ may\ be\ restricted\ to\ 8-bit\ character\ sets,\ and\ even\ if\ they\ aren't\ there\ needn't\ be\ a\ convenient\ way\ to\ type\ ←.\ Requiring\ users\ to\ type\ it\ (or\ \\u2190\ which\ would\ work\ fine\ ''as\ the\ symlinks\ is\ just\ a\ list'')\ is\ far\ less\ unfriendly,\ especially\ as\ it\ is\ part\ of\ the\ fixed\ syntax\ of\ the\ \[infix\]\ command.\ For\ the\ configurable\ \[little\ language\]\ found\ in\ the\ body,\ Unicode\ symbols\ are\ sometimes\ obvious\ choices\ —\ when\ coding\ the\ math::complexnumbers\ stuff\ above\ I\ actually\ considered\ defining\ a\ Weierstrass\ ℘\ or\ Euler\ Γ\ function\ just\ to\ show\ off\ this\ aspect,\ but\ I\ skipped\ that\ since\ I\ couldn't\ find\ an\ ready-to-use\ implementation.\n\n\[Larry\ Smith\](again)\ This\ brings\ up\ an\ interesting\ point\ that\ I\ will\ just\ throw\ out\ for\ discussion:\ when,\ I\ ask,\ ''will''\ it\ be\ reasonable\ to\ expect\ that\ any\ user\ could\ reasonably\ be\ expected\ to\ type\ a\ unicode\ character\ as\ ''as\ such''\ in\ a\ program?\ \ In\ my\ opinion\ we\ are\ already\ past\ this\ point:\ virtually\ all\ the\ editors\ I\ use\ regularly\ have\ no\ problem\ at\ all\ with\ unicode.\ \ vi\ does,\ but\ I\ suspect\ there\ are\ few\ die-hard\ vi\ users\ that\ use\ a\ lot\ of\ tcl.\ \ Unicode\ presents\ a\ cornucopia\ of\ symbols\ that\ can\ be\ made\ to\ serve\ useful\ ends\ -\ admittedly\ some\ of\ those\ ends\ could\ be\ evil\ (there\ are\ thousands\ of\ characters\ to\ abuse).\ \ It's\ been\ in\ the\ language\ now\ for\ years,\ so\ when\ can\ the\ cobbler's\ children\ use\ them?\n\n\[Lars\ H\]:\ FWIW,\ my\ particular\ editor\ of\ choice\ (\[Alpha\])\ unfortunately\ still\ doesn't\ support\ Unicode\ in\ documents\ (although\ it\ uses\ Tcl\ as\ scripting\ language,\ and\ thus\ can\ handle\ Unicode\ for\ internal\ processing,\ the\ text\ buffer\ code\ is\ written\ in\ C\ and\ years\ overdue\ for\ a\ rewrite).\ Also,\ one\ shouldn't\ underestimate\ the\ portability\ problems\ encountered\ when\ code\ is\ not\ pure\ ASCII\;\ the\ default\ for\ \[source\]\ is\ \[encoding\ system\],\ and\ as\ long\ as\ you\ find\ systems\ where\ that\ is\ iso8859-1,\ there\ will\ be\ problems.\n\n----\n\[AM\]\ (16\ march\ 2010)\ Here\ is\ a\ simple\ example\ of\ how\ you\ can\ apply\ this\ package.\ The\ program\ below\ uses\ it\ to\ implement\ the\ kind\ of\ array\ processing\ one\ finds\ in\ MATLAB\ or\ Fortran\ (90/95/2003):\n\n======\n#\ example.tcl\ --\n#\ \ \ \ \ Example\ of\ the\ use\ of\ the\ infix\ package\n#\npackage\ require\ infix\n\n#\ add\ --\n#\ \ \ \ \ Add\ the\ elements\ of\ two\ lists\n#\n#\ Arguments:\n#\ \ \ \ \ alist\ \ \ \ \ \ \ First\ list\n#\ \ \ \ \ blist\ \ \ \ \ \ \ Second\ list\n#\n#\ Returns:\n#\ \ \ \ \ List\ of\ the\ sum\ of\ the\ elements\ of\ the\ two\ lists\n#\n#\ Note:\n#\ \ \ \ \ The\ arguments\ may\ also\ be\ scalars\n#\nproc\ add\ \{alist\ blist\}\ \{\n\ \ \ \ set\ result\ \{\}\n\n\ \ \ \ if\ \{\ \[llength\ \$alist\]\ ==\ \[llength\ \$blist\]\ \}\ \{\n\ \ \ \ \ \ \ \ foreach\ a\ \$alist\ b\ \$blist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ +\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ elseif\ \{\ \[llength\ \$alist\]\ ==\ 1\ \}\ \{\n\ \ \ \ \ \ \ \ set\ a\ \$alist\n\ \ \ \ \ \ \ \ foreach\ b\ \$blist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ +\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ elseif\ \{\ \[llength\ \$blist\]\ ==\ 1\ \}\ \{\n\ \ \ \ \ \ \ \ set\ b\ \$blist\n\ \ \ \ \ \ \ \ foreach\ a\ \$alist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ +\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ +\ \$b\}\]\n\ \ \ \ \}\n\ \ \ \ return\ \$result\n\}\n\n#\ mult\ --\n#\ \ \ \ \ Multiply\ the\ elements\ of\ two\ lists\n#\n#\ Arguments:\n#\ \ \ \ \ alist\ \ \ \ \ \ \ First\ list\n#\ \ \ \ \ blist\ \ \ \ \ \ \ Second\ list\n#\n#\ Returns:\n#\ \ \ \ \ List\ of\ the\ product\ of\ the\ elements\ of\ the\ two\ lists\n#\n#\ Note:\n#\ \ \ \ \ The\ arguments\ may\ also\ be\ scalars\n#\nproc\ mult\ \{alist\ blist\}\ \{\n\ \ \ \ set\ result\ \{\}\n\n\ \ \ \ if\ \{\ \[llength\ \$alist\]\ ==\ \[llength\ \$blist\]\ \}\ \{\n\ \ \ \ \ \ \ \ foreach\ a\ \$alist\ b\ \$blist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ *\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ elseif\ \{\ \[llength\ \$alist\]\ ==\ 1\ \}\ \{\n\ \ \ \ \ \ \ \ set\ a\ \$alist\n\ \ \ \ \ \ \ \ foreach\ b\ \$blist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ *\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ elseif\ \{\ \[llength\ \$blist\]\ ==\ 1\ \}\ \{\n\ \ \ \ \ \ \ \ set\ b\ \$blist\n\ \ \ \ \ \ \ \ foreach\ a\ \$alist\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ *\ \$b\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ *\ \$b\}\]\n\ \ \ \ \}\n\ \ \ \ return\ \$result\n\}\n\n#\ main\ --\n#\ \ \ \ \ Test\ it\n#\n::infix::core::setup\ base\n::infix::core::opalias\ +\ \{binary\ 10\}\ add\n::infix::core::opalias\ *\ \{binary\ 15\}\ mult\n\nset\ a\ \{1\ 2\ 3\ 4\}\nset\ b\ \{2\ 4\ 6\ 7\}\nset\ c\ 2\n\nputs\ \[infix\ \{a\ <-\ a\ b\ <-\ b\}\ \{\ \n\ \ \ \ \ \ \ \ \ \ a\ +\ b\ \}\]\nputs\ \[infix\ \{a\ <-\ a\ b\ <-\ b\ c\ <-\ c\}\ \{\n\ \ \ \ \ \ \ \ \ \ a\ +\ c*b\ \}\]\n\n#\n#\ Timing\n#\nproc\ addmult\ \{alist\ blist\ c\}\ \{\n\ \ \ \ set\ result\ \{\}\n\ \ \ \ foreach\ a\ \$alist\ b\ \$blist\ \{\n\ \ \ \ \ \ \ \ lappend\ result\ \[expr\ \{\$a\ +\ \$c\ *\ \$b\}\]\n\ \ \ \ \}\n\ \ \ \ return\ \$result\n\}\n\nputs\ \"Direct:\ \ \ \ \[time\ \{addmult\ \$a\ \$b\ \$c\}\ 1000\]\"\nputs\ \"Via\ infix:\ \[time\ \{infix\ \{a\ <-\ a\ b\ <-\ b\ c\ <-\ c\}\ \{\ a\ +\ c*b\ \}\}\ 1000\]\"\ \ \ \ \ \ \n======\n\nThe\ output:\n======\n3\ 6\ 9\ 11\n5\ 10\ 15\ 18\nDirect:\ \ \ \ 3.48\ microseconds\ per\ iteration\nVia\ infix:\ 15.999\ microseconds\ per\ iteration\n=======\n\n(Just\ to\ get\ an\ impression)\n----\n!!!!!!\n%|\ \[Category\ Package\]\ |\ \[Category\ Mathematics\]\ |%\n!!!!!!} CALL {my revision infix} CALL {::oo::Obj5987288 process revision/infix} CALL {::oo::Obj5987286 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4