expr -->constant symbol expr --> path expr -> localvar expr => symbol [ values | ]--> path [ values | ]-> localvar delete: path File: muf.c, jobbuild.c, job.t Status: alpha
Muq MUF uses a different and variable reference syntax from traditional muf or forth, one which I believe to be more readable.
One important difference between Muq MUF and traditional MUF or Forth is that Muq MUF has true local variables with scope limited to the function within which they are declared -- what C calls "automatic" variables.
I believe lack of true local variables and consequent abuse
of the data stack via obscure sequences of operators like
rot, swap, dup, over
contributed mightily to making
traditional MUF and Forth code less readable than it
should be. I have worked hard to make Muq MUF local
variables efficient enough that programmers will not
hesitate to use them, and to give them a syntax that
promotes readability of the resulting code.
Local variables within a function are referenced simply by mentioning their name, and are assigned values by using a short right-arrow followed by their name:
salary savings + -> new-salary
I believe this exhibits better visual flow and less noise than the traditional
salary @ savings @ + new-salary !
quite aside from the complete lack of local variables in traditional MUF and Forth.
The Muq MUF ->
operator will automatically
create a local variable of the given name if none currently
exists within the function. This again reduces the amount
of syntactic noise and busywork involved in using local
variables. Such automatic declaration of variables at need
is accepted practice in value-typed application languages,
where no type need be specified for a variable, and where
the emphasis is on convenience of interactive hacking rather
than strong type-checking of large programs.
In Muq MUF, global variables (that is, symbols in the currently open package) and properties on objects are set using a similar syntax:
value --> global ( Store into a symbol. ) value --> .u["cynbe"].tmp.x ( Store into a property. ) value --> me.tmp.x ( Same as above when done by cynbe. )
Note that this arrow is longer than that used for local variables. This is a reflection of the fact that access to symbols and properties is a slower and more dangerous operation: Programmers, like most people, tend to follow the path of least resistance, and we wish to encourage them to use local variables in preference to symbols or object properties, when given a choice.
Stack: makeIndex --> o Stack: 1 --> o.a 2 --> o.b 3 --> o.c Stack: o.a o.b o.c Stack: 1 2 3
A convenient syntax for deleting properties is
delete: .u["cynbe"].tmp.x
which removes property x
from object .u["cynbe"].tmp
.
The --
and ++
are short notations for
incrementing or decrementing a symbol or local variable.
-- my-local-var ( Subtract one from given local variable. ) ++ *my-symbol* ( Add one to value of given symbol. )
These produce exactly the same code as
my-local-var 1 - -> my-local-var *my-symbol* 1 + --> *my-symbol*
The point is only to improve readability by providing a more concise notation for a common operation.
The -->constant
operator works exactly like the
-->
except that it should only be applied to symbols,
and it marks the symbol as being a constant. Declaring a
symbol to be a constant is a promise to the compiler that
you will never change its value. More specifically:
As a deliberate exception, you may change a constant's value
using -->constant
, but in such a case it is strictly
up to you to ensure that all affected code gets recompiled.
(This exception is motivated primarily by a wish to let
files be reloaded without producing error messages.)
The =>
operator is a borrowing from Lisp: It binds a
value to the given symbol. In CommonLisp nomenclature, this
binding has indefinite scope and dynamic
extent: This means roughly that the binding is visible in
all other functions, not just the current one, but ends when
the current function exits. (More precisely, when the
current function, {}
-scope or if/else/fi
clause is exited.) Binding is handy when you want to change
a global value temporarily, but want it automatically
restored to the previous value when you are done.
Binding has some special quirks in the Muq context:
The ]->
operator is simply a shorthand for
]shift ->
. See section ]shift.
The ]-->
operator is simply a shorthand for
]shift -->
.
Go to the first, previous, next, last section, table of contents.