Re: [q-lang-users] Another Simple Question
Brought to you by:
agraef
From: <Dr....@t-...> - 2004-11-01 08:26:42
|
Larry Gregg wrote: > def F = fopen c:\test\mytest.txt "w" ; > fwrites F "Hello, world." ; > fclose F; > > Why does it give me this error in Qpad? > > % C:\Program Files\QPAD\TEST\Filew01.q > Error Filew01.q, line 1: parse error at or near symbol `:' > Error Filew01.q, line 2: parse error at or near symbol `;' > Error Filew01.q, line 3: parse error at or near symbol `;' As Tim already pointed out, you have to put the filename in double quotes and escape the backslashes (or replace them with slashes). Probably you'll also want a newline at the end of the string. You can enter this directly in the interpreter by running an empty script and then entering these commands at the interpreter prompt: ==> def F = fopen "c:/test/mytest.txt" "w" ==> fwrites F "Hello, world.\n" ==> fclose F You also have to distinguish between the *programming language* in which you write a Q script (the "upper pane" in Qpad), and the *command language* of the interpreter which allows you (among other things) to type expressions to be evaluated (the "lower pane" in Qpad). In the manual, something to be entered in the interpreter is usually shown with the ==> prompt in front of it, just like I did above. If you want to put the above into a script, you'll have to wrap it up in a function definition (i.e., a collection of equations). Scripts can only contain variable definitions and equations, not just an expression by itself. So you can write something like: test = fwrites F "Hello, world.\n" where F = fopen "mytest.txt" "w"; Once you enter this script, save it to a file and run it with the interpreter, you can call the test function in the interpreter: ==> test Some important differences between the programming language and the interpreter's command language are: - The programming language is free-format, while the command language is line-oriented, to facilitate interactive usage. - The programming language allows you to define functions, while the command language allows you to evaluate expressions. - The programming language has a lot of additional constructs to declare functions, variables and types, while in the command language you have some special commands for interactive usage (such as debugger and profiling commands). I know that this can be a little confusing for beginners since a subset of the Q language (expression and variable definition syntax) is used both in the programming and in the command language. A closer description of the command language of the interpreter can be found in Appendix B.2 of the manual, see http://q-lang.sourceforge.net/qdoc/qdoc_14.html#SEC143. HTH Albert -- Dr. Albert Gr"af Dept. of Music-Informatics, University of Mainz, Germany Email: Dr....@t-..., ag...@mu... WWW: http://www.musikwissenschaft.uni-mainz.de/~ag |