q-lang-users Mailing List for Q - Equational Programming Language (Page 57)
Brought to you by:
agraef
You can subscribe to this list here.
2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(3) |
Feb
(27) |
Mar
|
Apr
(4) |
May
(11) |
Jun
(5) |
Jul
(5) |
Aug
(6) |
Sep
(15) |
Oct
(28) |
Nov
(8) |
Dec
|
2005 |
Jan
(9) |
Feb
(5) |
Mar
(10) |
Apr
(43) |
May
(8) |
Jun
(31) |
Jul
(45) |
Aug
(17) |
Sep
(8) |
Oct
(30) |
Nov
(2) |
Dec
(6) |
2006 |
Jan
(4) |
Feb
(20) |
Mar
(1) |
Apr
|
May
(92) |
Jun
(179) |
Jul
(26) |
Aug
(65) |
Sep
(36) |
Oct
(38) |
Nov
(44) |
Dec
(68) |
2007 |
Jan
(11) |
Feb
(25) |
Mar
(37) |
Apr
(7) |
May
(83) |
Jun
(77) |
Jul
(44) |
Aug
(4) |
Sep
(28) |
Oct
(53) |
Nov
(12) |
Dec
(21) |
2008 |
Jan
(66) |
Feb
(45) |
Mar
(30) |
Apr
(50) |
May
(9) |
Jun
(18) |
Jul
(11) |
Aug
(6) |
Sep
(4) |
Oct
|
Nov
|
Dec
|
2009 |
Jan
|
Feb
|
Mar
|
Apr
(3) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
From: Tim H. <q...@st...> - 2004-11-22 08:07:09
|
"David vGB" <da...@pu...> writes: > OK, you've got me playing with these regexes now. [snip] > Slightly more usable: > tagify Delim Tag = snr "g" (Delim++"([^"++Delim++"]*)"++Delim) > '(tag Tag (reg 1)); > embolden3 = tagify "\\*" "bold"; > underline = tagify "_" "underline"; Oooh! Thanks a lot for all those. I'm going straight with embolden3 now. > Then we can write: > ==> underline (embolden3 "This has *bold _underlining_*!") > "This has <bold>bold <underline>underlining</underline></bold>!" > > The problem is > ==> underline (embolden3 "This has *bold _underlining*_ !") > "This has <bold>bold <underline>underlining</bold></underline> !" > > And this is malformed html. Well, it's ugly input as well, so it's not that surprising. For my purposes, I can declare this to be erroneous :) > I'm torn between two instincts here: > - A clean way to do it would be to process your wikitext, build a full > parse tree and transform this to html, but > - this doesn't seem in the wiki spirit, where I suspect the ideal would > be to capture the entire conversion to html in a single regex. Well, I've worked with TWiki including some dabblings in the source, and definitely don't want to reproduce something quite like that again. Hence, what I'm actually doing with these tags is to build docbook, which I can XSLT using these new-fangled libxml bindings. :) (And it might not be for an actual wiki, either; I have other web-based document-management ideas in mind that require a markup format for all the content; I'll see how that evolves, although it's been a year or more cooking in my head so far...) Thanks greatly for fixing the regex stuff, though :) ~Tim -- <http://spodzone.org.uk/> |
From: David v. <da...@pu...> - 2004-11-22 05:05:57
|
OK, you've got me playing with these regexes now. Based on the regsplit example, a regex search and replace is: snr Opts OldRE NewRE S = strcat (regex Opts OldRE S (regskip ++ `NewRE) ++ [regskip]); i.e. instead of splitting at a match we're inserting a new regex. Then embolden2 = snr "g" "\\*([^\\*]*)\\*" '(tag "bold" (reg 1)); Note the quote and unquote to delay evaluation of (reg 1) etc. ==> embolden2 "this is some *bold* text, and a lone * at the end" "this is some <bold>bold</bold> text, and a lone * at the end" Slightly more usable: tagify Delim Tag = snr "g" (Delim++"([^"++Delim++"]*)"++Delim) '(tag Tag (reg 1)); embolden3 = tagify "\\*" "bold"; underline = tagify "_" "underline"; Then we can write: ==> underline (embolden3 "This has *bold _underlining_*!") "This has <bold>bold <underline>underlining</underline></bold>!" The problem is ==> underline (embolden3 "This has *bold _underlining*_ !") "This has <bold>bold <underline>underlining</bold></underline> !" And this is malformed html. I'm torn between two instincts here: - A clean way to do it would be to process your wikitext, build a full parse tree and transform this to html, but - this doesn't seem in the wiki spirit, where I suspect the ideal would be to capture the entire conversion to html in a single regex. Cheers, David. |
From: David v. <da...@pu...> - 2004-11-22 03:45:03
|
Tim Haynes wrote: > However, I'm having a bad time trying to get my embolden function to work. > It should be simple; anywhere you see a word surrounded by `*', replace it > with "<bold>whatever</bold>" instead. Making this happen in Q seems to be > rather a hassle, however. Currently, I've got: > > | embolden S = T if #T>0 > | where T=regex "gn" "(.+?)\\*(.+?)\\*(.+?)" S > | (strcat [reg 1, > | tag "bold" (reg 2), > | reg 3]); > | = S otherwise; > | Try: <q> embolden S = (strcat T)++regskip where T=regex "gn" "([^\\*]+?)\\*([^\\*]+?)\\*([^\\*]+?)" S (strcat [reg 1, tag "bold" (reg 2), reg 3]); </q> Which gives ==> embolden "this is some *bold* text, and behold, some *more* of it" "this is some <bold>bold</bold> text, and behold, some <bold>more</bold> of it" Your regex was only giving one match, as the other "*"s also match as part of the "(.+?)". Just replace the "." with "[^\\*]" to match anything but "*". The regskip just adds any leftover text, so instead of: ==> embolden "this is some *bold* text, and a lone * at the end" "this is some <bold>bold</bold> text, and a lone " You get: ==> embolden "this is some *bold* text, and a lone * at the end" "this is some <bold>bold</bold> text, and a lone * at the end" Which may or may not be what you want, this could be considered an error. BTW, Hi there. I'm a maths student, I've been lurking here a while and I just finished my exams for the year, which gives me more time to play with Q and other nice things :) Cheers, David. |
From: Tim H. <q...@st...> - 2004-11-22 00:42:55
|
Hi, I'm playing around with regexes with a view to writing a module to perform wiki-style transformations on text.=20 So far, I've managed, with the help of TFM's `regsplit' example, to write a function that creates paragraphs based on \n\n in the document: | regsplit OPTS REGEX S =3D regex OPTS REGEX S regskip ++ [regskip]; |=20=20=20 | paragraphise S =3D map (tag "para") (regsplit "gn" "\n\n" S); However, I'm having a bad time trying to get my embolden function to work. It should be simple; anywhere you see a word surrounded by `*', replace it with "<bold>whatever</bold>" instead. Making this happen in Q seems to be rather a hassle, however. Currently, I've got: | embolden S =3D T if #T>0 | where T=3Dregex "gn" "(.+?)\\*(.+?)\\*(.+?)" S | (strcat [reg 1, | tag "bold" (reg 2), | reg 3]); | =3D S otherwise; |=20=20=20 | =3D=3D> embolden "this is some *bold* text, and behold, some *more* of= it" | ["this is some *bold* text, and behold, some <bold>more</bold>\n of it= "] ^^^^^^ oops, what happened here? Can anyone help me out with a function that gives the effect of a global substitution like I seem to be wanting? Ultimately I want to be writing=20 | wiki =3D paragraphise.embolden.italicise.handleHeadings or something similar. TIA, ~Tim =2D-=20 <http://spodzone.org.uk/> |
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 |
From: Tim H. <q...@st...> - 2004-10-31 22:20:49
|
Larry Gregg <lg...@ac...> writes: > People: > > I pretty much copied this from the help screen: > > 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 `;' > > The error message is not too helpful. Should the filename be in double > quotes? Yes, it's a string field. Also I think the \ should be doubled-up, as well. > Are there some simple, complete, examples of file I/O? <http://q-lang.sourceforge.net/qdoc/qdoc_12.html#SEC91> might be a reasonable place to start. HTH, ~Tim -- <http://spodzone.org.uk/> |
From: Larry G. <lg...@ac...> - 2004-10-31 22:03:42
|
People: I pretty much copied this from the help screen: 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 `;' The error message is not too helpful. Should the filename be in double quotes? Are there some simple, complete, examples of file I/O? Larry Gregg |
From: <Dr....@t-...> - 2004-10-31 09:19:55
|
Tim Haynes wrote: > I've just got some initial benchmark results - it's still good, it's > still obviously quicker than the naiive baseline (faster about 3.5x as > often as naiive is faster than mine). And when it's faster, it's by a > factor of 2-3, while I've never seen it being over 12% slower at worst. Great! If you have some benchmark results or other comments ready to be added to the script, just send them to me. > Graphs of times taken show a couple of curves much lower than the naiive > algorithm, too. Just remember that all of this is achieved at the expense of O(N log N) memory requirements (whereas the naive algorithm uses only O(1) data). ;-) > Neat :) I agree. :) 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 |
From: Tim H. <q...@st...> - 2004-10-30 21:29:44
|
Dr....@t-... (Albert Graef) writes: > Tim Haynes wrote: >> If it's not too late, I'd like to hold back on that - I'm travelling atm >> and will be back home tomorrowish. Can run yours and mine through the mill >> again then. I'm particularly worried about those error-in-conditional >> problems... :/ > > Hi, Tim, > > unfortunately Q 6.0 was already released last weekend (didn't have the > time to announce this on the ML this time, I'm so busy now that the > semester has begun). That is not unfortunate ... :) > My corrected version of your script is included in the examples. That > versions seems to work ok, though. I'd suggest that if you have a new > version I'll update it in cvs immediately and then release it with the > next Q version. Ok? I've just got some initial benchmark results - it's still good, it's still obviously quicker than the naiive baseline (faster about 3.5x as often as naiive is faster than mine). And when it's faster, it's by a factor of 2-3, while I've never seen it being over 12% slower at worst. Graphs of times taken show a couple of curves much lower than the naiive algorithm, too. Neat :) ~Tim -- <http://spodzone.org.uk/> |
From: <Dr....@t-...> - 2004-10-30 21:18:17
|
(This announcement comes quite late, apologies for that.) Q 6.0 is out. The major news is that SWIG (http://www.swig.org) is now supported, which greatly facilitates interfacing to existing C/C++ code. You'll need a custom SWIG version to make this work, available as a source tarball from http://q-lang.sf.net at this time. As soon as I have the time, I will try to persuade the SWIG developers to include the Q language module in the official SWIG version. Please note that if you use any add-on modules, you'll have to recompile/reinstall those as the libq ABI has changed (but is fully backward-compatible at the source level). You'll know that you have to do this when you cannot load a module (because the libq library version has changed, the interpreter now uses libq-6.0.0 and so must your add-on modules). The binary packages of all the latest module versions at q-lang.sf.net have already been updated. More information can be found, as usual, at http://q-lang.sf.net Enjoy! 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 |
From: <Dr....@t-...> - 2004-10-30 21:01:47
|
Andrew Berg wrote: > From the documentation on the website and the idea that Q is a little > like Haskell, but friendlier, I've implemented SHA-1 in Q. Well, almost > implemented it. I've got it working fine for messages that fit into a > single 512 byte block, but somehow it seems to get confused when > spanning the blocks. I rewrote the block spanning code because I > thought maybe I was doing the recursion wrong, but still I'm getting > answers that don't match the sample data from > http://www.faqs.org/rfcs/rfc3174.html . I've attached my code in case > someone would like to take a look at it and tell me what I'm doing > wrong. I tried to use the debugger, but I could never make sense of its > output. Hi, Andrew, disclaimer: I only took a quick glance at your code, and I don't know the algorithm being implemented. That said, I'd guess that some of the conversion operations could in fact be sped up by utilizing some of the byte string operations, but I'm too lazy to figure out the details right now. To speed things up a little more, you could also try to get rid of some of the lambdas, where they are employed as local variable binders. A "where" clause is more readable (IMHO) and also usually faster in Q. E.g., in the definition of sh_wt, 3rd eqn you could write something like (warning: unchecked code): = Ws++[sha_w16 Ws T] where Ws = sha_wt M (T-1) otherwise; Similarly, the 2nd eqn for sha_aet would become: = [ sha_temp Ws A B C D E T, A, sha_rotl B 30, C, D ] where [A,B,C,D] = sha_aet Hs Ws AE (T-1) otherwise; (BTW, a few lines further down there seem to be two identical definitions of sha_add_hash. And a few lines up there are two functions sha_w and sha_ws which seem to do the same thing. Glitch?) As for the block spanning bug, I think that the following two eqns near the end of the script look suspicious: sha_process_end H Ml [] = H; sha_process H Ml M = sha_process_end H Ml (sha_pad_msg Ml M) if #M < 65; In both cases you seem to expect a list value as the 3rd parameter, but isn't that parameter supposed to be a byte string? (Note that, in difference to Haskell, Q is dynamically typed, so it won't complain about this!) In any case, become friends with the debugger. It's not perfect but a lot better than it looks at first sight. ;-) 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 |
From: <Dr....@t-...> - 2004-10-30 19:31:21
|
Tim Haynes wrote: > If it's not too late, I'd like to hold back on that - I'm travelling atm > and will be back home tomorrowish. Can run yours and mine through the mill > again then. I'm particularly worried about those error-in-conditional > problems... :/ Hi, Tim, unfortunately Q 6.0 was already released last weekend (didn't have the time to announce this on the ML this time, I'm so busy now that the semester has begun). My corrected version of your script is included in the examples. That versions seems to work ok, though. I'd suggest that if you have a new version I'll update it in cvs immediately and then release it with the next Q version. Ok? 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 |
From: Tim H. <q...@st...> - 2004-10-26 16:23:29
|
Dr....@t-... (Albert Graef) writes: > Tim Haynes wrote: >> def HASH = ref emptyhdict; >> public hashed F X; >> hashed F X = get HASH!(F,X) if member (get HASH) (F,X); >> = put HASH (update (get HASH) (F,X) Y) || Y >> where Y = F X otherwise; >> hashed isprime = hisprime; >> hisprime N = not (any ((=0).(N mod))) (primes (intsqrt N)) ; >> hashed primes = hprimes; >> hprimes N = [2] if N=2; = [2,3] if N=3; >> = [2,3|filter isprime [5,7..N]] otherwise; > > Hmm, when I run this code over here, the hashed function is apparently > never invoked. Very strange! THe performance was completely different from the unhashed version - I observed it staying all-but linear when the all-the-odds algorithm, or even the unhashed one, were showing increases, here.. And yes it seemed to be producing the right answers, for a few random spot-checks, too :) > In fact, with filter isprime [5000000..5000100] I even get a failed > condition: > > ! Error in conditional > 0> stdlib.q, line 134: filter isprime [5000011,5000012,5000013,...] ==> > [5000011|filter isprime [...]] if isprime 5000011 Very weird. I did actually see a glitch with one large number, so I'll have to go back and investigate it more... > I think the applications of hashed are the wrong way round (it's easy to > fall into this trap, it has happened to me, too). I've attached my > (hopefully corrected) version of the script to this post. This one *does* > invoke hashed now (verified with tbreak). > > I'm ready to add this version to the examples now (if you don't complain > -- better do that quickly, as I'm currently doing the final touches for Q > 6.0 ;-). If it's not too late, I'd like to hold back on that - I'm travelling atm and will be back home tomorrowish. Can run yours and mine through the mill again then. I'm particularly worried about those error-in-conditional problems... :/ ~Tim -- <http://spodzone.org.uk/> |
From: Andrew B. <and...@ya...> - 2004-10-26 07:08:43
|
From the documentation on the website and the idea that Q is a little like Haskell, but friendlier, I've implemented SHA-1 in Q. Well, almost implemented it. I've got it working fine for messages that fit into a single 512 byte block, but somehow it seems to get confused when spanning the blocks. I rewrote the block spanning code because I thought maybe I was doing the recursion wrong, but still I'm getting answers that don't match the sample data from http://www.faqs.org/rfcs/rfc3174.html . I've attached my code in case someone would like to take a look at it and tell me what I'm doing wrong. I tried to use the debugger, but I could never make sense of its output. Also, I know that it is really slow. The bulk of the time is spent calculating the final value of the A-E registers. I don't see obvious repeated computation of the same values in sha_aet, but there might be some way to write that which would not require building all the little arrays. Thanks, -andrew |
From: <Dr....@t-...> - 2004-10-23 09:20:58
|
Tim Haynes wrote: > def HASH = ref emptyhdict; > > public hashed F X; > hashed F X = get HASH!(F,X) if member (get HASH) (F,X); > = put HASH (update (get HASH) (F,X) Y) || Y > where Y = F X otherwise; > > hashed isprime = hisprime; > > hisprime N = not (any ((=0).(N mod))) (primes (intsqrt N)) ; > > hashed primes = hprimes; > > hprimes N = [2] if N=2; > = [2,3] if N=3; > = [2,3|filter isprime [5,7..N]] otherwise; Hmm, when I run this code over here, the hashed function is apparently never invoked. In fact, with filter isprime [5000000..5000100] I even get a failed condition: ! Error in conditional 0> stdlib.q, line 134: filter isprime [5000011,5000012,5000013,...] ==> [5000011|filter isprime [...]] if isprime 5000011 I think the applications of hashed are the wrong way round (it's easy to fall into this trap, it has happened to me, too). I've attached my (hopefully corrected) version of the script to this post. This one *does* invoke hashed now (verified with tbreak). I'm ready to add this version to the examples now (if you don't complain -- better do that quickly, as I'm currently doing the final touches for Q 6.0 ;-). Cheers, 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 |
From: <Dr....@t-...> - 2004-10-22 16:28:54
|
Tim Haynes wrote: > Yeah, I'll bear it in mind. Actually, I was rather hoping to run it against > GTK.. :) Well, while SWIG-Q seems to work pretty well now, and I've written my first Qt hello world program in Q, my first experiments with wrapping the entire Qt and GTK libraries have been rather sobering. :( The problem is not with SWIG-Q, but with SWIG itself. Neither the GTK nor the Qt headers are SWIG-friendly at all, so I'd have to manually extract all relevant declarations from that gazillion of header files. While this is already a lot better than writing wrapper modules by hand, it's still a big amount of work. And I haven't been able to find ready-made SWIG interfaces for GTK and Qt on the web either. Maybe I should just release the SWIG-enabled Q version as it is now (it's already in cvs, I just need to build/test it on Windows and I plan to do that tonight), and sit back and see what you and others can do with it. ;-) > Meanwhile, I'm working on the core algorithms for the RSS-reader... the > integration with libxml2 is coming into its own :) Feedback on that module is appreciated, of course. Also, I'm awaiting some nifty new Q-CGI examples to be included in a future Q release ... :) 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 |
From: Tim H. <q...@st...> - 2004-10-21 08:31:49
|
Dr....@t-... (Albert Graef) writes: > Hi, Tim, > >> Oh wow. If it's really capable of coping with something that size, it'll >> be amazing. I'm already wondering about writing a tiny graphical app in >> Q (an RSS aggregator with a difference) as it is :) > > You could also use the tk module for that. I've already written some > substantial applications with that module, so it's fairly well-tested. I > also use vtcl as a GUI builder, the necessary boilerplate code to load > the created Tcl scripts from Q is quite simple. While Tcl/Tk looks quite > old and ugly when compared to Qt, it's easy to program it and you have > the added benefit of cross-platform portability. Yeah, I'll bear it in mind. Actually, I was rather hoping to run it against GTK.. :) Meanwhile, I'm working on the core algorithms for the RSS-reader... the integration with libxml2 is coming into its own :) ~Tim -- <http://spodzone.org.uk/> |
From: <Dr....@t-...> - 2004-10-21 00:53:58
|
Larry Gregg wrote: > Thank you, Dr. Graef, that worked. I thank you, too, Walt, for your > help. I am sure I will have more questions, so I hope you will not mind > when I ask . That's what this list is for. :) 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 |
From: <Dr....@t-...> - 2004-10-21 00:48:25
|
Hi, Tim, > Oh wow. If it's really capable of coping with something that size, it'll be > amazing. I'm already wondering about writing a tiny graphical app in Q (an > RSS aggregator with a difference) as it is :) You could also use the tk module for that. I've already written some substantial applications with that module, so it's fairly well-tested. I also use vtcl as a GUI builder, the necessary boilerplate code to load the created Tcl scripts from Q is quite simple. While Tcl/Tk looks quite old and ugly when compared to Qt, it's easy to program it and you have the added benefit of cross-platform portability. >>Care to post your final algorithm here? > > Sure. :) I think this is the best of all worlds so far: Thanks a lot, I'll add this as an example to the next Q release. Which is imminent, as I'm almost finished with Q-SWIG. 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 |
From: Larry G. <lg...@ac...> - 2004-10-21 00:20:37
|
Albert Graef wrote: >> ==> fac N = N*fac (N - 1) if N>0; >> ! Syntax error >> >>> fac N = N*fac (N - 1) if N>0; > > > You can't enter the script directly in the interpreter (which is just > an expression evaluator). Enter it in the upper pane of Qpad, save the > script, then run it. At the prompt, you can now enter something like > fac 100. > > HTH > Albert > Thank you, Dr. Graef, that worked. I thank you, too, Walt, for your help. I am sure I will have more questions, so I hope you will not mind when I ask . I've been an imperative language programmer for some time. I thought I would stretch my mind, and try learning a functional programming language. This started off badly, but it is looking better, now! Larry |
From: <Dr....@t-...> - 2004-10-20 17:24:34
|
> ==> fac N = N*fac (N - 1) if N>0; > ! Syntax error > >>> fac N = N*fac (N - 1) if N>0; You can't enter the script directly in the interpreter (which is just an expression evaluator). Enter it in the upper pane of Qpad, save the script, then run it. At the prompt, you can now enter something like fac 100. 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 |
From: ww <wwa...@ea...> - 2004-10-20 12:36:48
|
----- Original Message ----- From: "Larry Gregg" <lg...@ac...> To: <q-l...@li...> Sent: Tuesday, October 19, 2004 10:44 PM Subject: [q-lang-users] Q Question > People: > > I have downloaded Q, and am trying the following, using Qpad, but I get > an error: > > ==> fac N = N*fac (N - 1) if N>0; > ! Syntax error > >>> fac N = N*fac (N - 1) if N>0; > ^ > I copied this from the qdoc.pdf. This occurs using the interpreter, > but I imagine it would be the same with the compiler. > > Thanks, > Larry Gregg Hi Larry, I did a cut-n-paste of the offending line and my Qpad (ver 5.5) session accepted it w/o an error report. To finish the definition you'll need to expand fac to; fac 0 = 1; fac N = N*fac (N - 1) if N>0; Could the problem w/ your session be on the previous line? Regards, Walt |
From: Larry G. <lg...@ac...> - 2004-10-20 02:44:39
|
People: I have downloaded Q, and am trying the following, using Qpad, but I get an error: ==> fac N = N*fac (N - 1) if N>0; ! Syntax error >>> fac N = N*fac (N - 1) if N>0; ^ I copied this from the qdoc.pdf. This occurs using the interpreter, but I imagine it would be the same with the compiler. Thanks, Larry Gregg |
From: Tim H. <q...@st...> - 2004-10-12 09:59:14
|
Dr....@t-... (Albert Graef) writes: > Tim Haynes wrote: >> Oh, *excellent* <rubs hands in glee>. Thanks for that. Refs as well? I have >> much Q to be learning. :) > > Also soon to be unleashed upon the unexpecting world: SWIG support! This > will turn the creation of library interfaces into a no-brainer. But don't > tell anyone just yet, I'm still testing. ;-) C already works very well, I > wish I had that when I wrote the clib module ... As soon as I'm satisfied > with the result of auto-wrapping a huge C++ library like the entire Qt > it's time for a release again. Oh wow. If it's really capable of coping with something that size, it'll be amazing. I'm already wondering about writing a tiny graphical app in Q (an RSS aggregator with a difference) as it is :) >> I've implemented memoization on `prime' and `isprime' functions - works >> first time ;) > > Care to post your final algorithm here? Sure. :) I think this is the best of all worlds so far: #!/usr/bin/env q #! -q #! -cmain ARGS || quit def HASH = ref emptyhdict; public hashed F X; hashed F X = get HASH!(F,X) if member (get HASH) (F,X); = put HASH (update (get HASH) (F,X) Y) || Y where Y = F X otherwise; hashed isprime = hisprime; hisprime N = not (any ((=0).(N mod))) (primes (intsqrt N)) ; hashed primes = hprimes; hprimes N = [2] if N=2; = [2,3] if N=3; = [2,3|filter isprime [5,7..N]] otherwise; def P=val (ARGS!1); dump N = strcat [str N, " is ", (str (isprime N)), "\n"]; main ARGS = dump P; (The reason for `dump' and main being separate is that I was running dump, and therefore isprime, across a list [(P-10)..(P+10)], for benchmarking purposes.. :) You're welcome to use it for docs / consider it GPL'd / whatever's easiest, as you wish. :) ~Tim -- <http://spodzone.org.uk/> |
From: <Dr....@t-...> - 2004-10-12 02:09:28
|
Tim Haynes wrote: > Oh, *excellent* <rubs hands in glee>. Thanks for that. Refs as well? I have > much Q to be learning. :) Also soon to be unleashed upon the unexpecting world: SWIG support! This will turn the creation of library interfaces into a no-brainer. But don't tell anyone just yet, I'm still testing. ;-) C already works very well, I wish I had that when I wrote the clib module ... As soon as I'm satisfied with the result of auto-wrapping a huge C++ library like the entire Qt it's time for a release again. > I've implemented memoization on `prime' and `isprime' functions - works > first time ;) Care to post your final algorithm here? Cheers, 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 |