Re: [q-lang-users] First Q
Brought to you by:
agraef
From: Rob H. <hub...@gm...> - 2007-07-05 11:54:20
|
Hello Abram, Alternatively, you could use defs with lambdas in the interpreter: ==> def Square = \X . X * X ==> Square 3 9 What Albert has described is superior though, and is the way you'd normally use Q. My suggestion may come in handy sometimes when you want to just try something quickly. By the way, if you wish to repeatedly try the same "commands", or rather evaluations, on your source, you can also put those in a separate "source" file [somewhat confusing terminology perhaps]. I usually use a <.qs> extension for these. So, <square.q> would contain (amongst your many other equations or definitions) square X = X * X; whilst the file <square.qs> might contain lines such as square 3; square 0; square (-1); Then in a command shell, you'd issue the command q square.q --source=square.qs or q square.q -s square.qs to run the interpreter on you files. To open the interpreter from the shell with you file pre-loaded, you'd probably just use q square.q I hope that helps to clarify things, and doesn't add to your confusion... [I can remember being a little confused by the separate interpreter command language when I first came across Q.] Rob. On 05/07/07, Albert Graef <Dr....@t-...> wrote: > Abram wrote: > > ==> square X = X * X; > > The interpreter only accepts expressions to evaluate. So '=' will be > interpreted as the equality operator here (which isn't by default > defined on symbolic expressions, hence the expression 'square X=X*X' is > in normal form). > > To enter a script with definitions, you must save it to a file and load > it with the interpreter (similar to Hugs or ghci). For instance: > > ==> edit square.q > > <<enter the script in vi and save it>> > > ==> run square.q > > ==> square 3 > 9 > > Albert |