Code Comments
Programming Forum and web based access to our favorite programming groups.Just a couple questions about scheme, thanks for all your help in advance. Say for example, you have a file with one line of text in it. How would you go about doing the following: Take the file name as a command line argument Retrieve the first and only line of the file Place the line into a list with each word as separate elements Just to clarify, Say the user wants to access a file in the current working directory with the name "sample.txt" And inside the file is a line of text that looks just like a list such as: (This is a list of elements) How would u parse that text into a list that looks just like it?
Post Follow-up to this messageStart by downloading DrScheme: http://www.plt-scheme.org/software/drscheme/
Post Follow-up to this messageOn Mar 26, 9:35 pm, Griff <gret...@gmail.com> wrote: > Start by downloading DrScheme: > > http://www.plt-scheme.org/software/drscheme/ thanks, i have mzscheme and i've been playing with it. i was looking for more of a practical coding way to go through it.
Post Follow-up to this messageOn 26 mar, 18:13, tem0...@yahoo.com wrote: > Just a couple questions about scheme, thanks for all your help in > advance. > > Say for example, you have a file with one line of text in it. > How would you go about doing the following: > Take the file name as a command line argument > Retrieve the first and only line of the file > Place the line into a list with each word as separate elements > > Just to clarify, > Say the user wants to access a file in the current working directory > with the name "sample.txt" > And inside the file is a line of text that looks just like a list such > as: > (This is a list of elements) > How would u parse that text into a list that looks just like it? I recommend that you try Bigloo. It is more powerful than other brands of Scheme, and much easier to use. If you are using Linux or MacIntosh, then instalation is straightforward: ./configure make make install If you prefer, open Synaptic, search for the package, press Apply; that is all. If you are using Windows, things are slightly more difficult. Happily enough, Junia prepared an installation package, with a nice GUI, and a very complete manual. The address of her page is code.google.com/o/stalingui Now, let us see your problem. You should solve it by parts; this is called incremental programming strategy, or IPS, for short. Let us write a program that reads all lines of a given file, whose name you will provide via command line. Here is the program: (module readfile) (with-input-from-file (cadr (command-line)) (lambda() (print (read-lines)))) That is all. This program reads all the lines of the file, and puts them in a list. Now, let us see how to solve the problem, the way you clarified it. If the first line is the only one you want, and it is in the form of a list, then nothing could be easier than reading it: (module readfile) (with-input-from-file (cadr (command-line)) (lambda() (print (read)))) Now, let us increase the difficulty of the problem just a little bit. Let us suppose that the words are not between parentheses. Then, the solution is: (module readfile) (with-input-from-file (cadr (command-line)) (lambda() (print (string-split (read-line) " "))) ) It seems that we have solved you problem completely. There is only one last thing that we can improve: The program has no error handling capacity. However, this is very easy to fix: (module readfile) (with-handler (lambda(e) (print "Usage: rdfile <filename>") ) (with-input-from-file (cadr (command-line)) (lambda() (print (string-split (read-line) " ")) ); end of lambda ) ) That is your program: Small, simple, and safe. It is easy to compile it in Bigloo: bigloo -static-bigloo -Obench rdfile.scm -o rdfile The option -static-bigloo makes sure that all runtime will go with the executables. In Bigloo, the runtime is very small. If your program is an assignment, it is a good idea to bundle everything in the same file; this prevents failure in the machine of your TA. Of course, if you want to run the program in a machine that has Bigloo installed, then you can drop the -static-bigloo option: bigloo rdfile.scm -o rdfile BTW, I also tried to write the same program in DrScheme. The distribution is three times larger than in the case of static Bigloo, it takes longer to compile, and the code is slower. In any case, here is one of the programs in DrScheme: (module rdfile mzscheme (with-input-from-file (vector-ref (current-command-line-arguments) 0) (lambda() (display (read)))) )
Post Follow-up to this messagephi500ac@yahoo.ca wrote: > I recommend that you try Bigloo. It is more powerful than other > brands of Scheme, and much easier to use. ... Weren't you hyping Stalin as the fastest, most powerful and easiest to use just a couple of ws ago? How did Bigloo rise on top of Stalin in such short time?
Post Follow-up to this messageOn 27 mar, 05:48, Abdulaziz Ghuloum <aghul...@cee.ess.indiana.edu> wrote: > phi50...@yahoo.ca wrote: > > Weren't you hyping Stalin as the fastest, most powerful and easiest > to use just a couple of ws ago? How did Bigloo rise on top of > Stalin in such short time? Hi,... If you take a look at the page of my group, you will see that we use both Stalin, and Bigloo; I favor Bigloo, but my fellow students favor Stalin. I remember that I said that Stalin is the most friendly, but I do not remember of saying that it is the fastest. I really do not know whether it is the fastest. Is it? However, I decided not recommend Stalin in the present case, because 1) Stalin is very slow to compile. It takes 20, 30 seconds to compile even the simplest program. Therefore, my fellow students and I use it only for the final compilation; we also limit the use of Stalin to number crunching problems (Numerical Analysis) because... 2) It has no libraries that I know. Perhaps I am wrong in saying that, but I never came across Stalin libraries to process strings, connect to the Internet, tokenize texts, do syntactical analysis, etc. My group tries every Scheme that we succeed in installing in all machines that are available to us. Then we choose the best one for a given problem. We also try to give an interesting solution to all problems. Our goal is not get rid of the assignment, but learn how to do things well. We want fast programs, small exec files, small distributions, beautiful gui, etc. For instance, tomorrow we will post a new GUI for Bigloo and Stalin. Therefore, do not understand me wrong. I am not a propagantist of Stalin, or Bigloo. I will be happy if I come across another Scheme that is faster than Stalin (or Bigloo), easier to use, generates small distributions, and has good libraries. From these attributes, my group cherishes most speed and the size of compiled stand alone code. These attributes get us better marks in college. Now, let me tell you what I did before answering to tem0's mail. The first thing was to download DrScheme, since Griff has recommended it. Then I tested the following Schemes, to see which one would provide the best solution: 1) DrScheme, 2) Bigloo, 3) Stalin, 4) Gambit, 5) Chicken. I also tried Ikarus, Lacerny, and Chez Scheme. Since Chez Scheme is not free, I ruled it out; I tried to install Ikarus on my Windows platform, under mingw, and I failed; I heard that one can compile it under cygwin, but since the rules of the group require native feeling, and small stand alone distribution in all platforms available to us, I gave up Ikarus. Now, let us see the Schemes that I succeeded in installing. 4) Gambit. Instalation was easy, but I failed in generating a stand alone executable file. The manual does not help very much, since it says that compiling the C files generated by the compiler depends on the platform. 5) Chicken. Small stand alone, but very slow (tipically, from 5 to 10 times slower than Bigloo). Not very friendly, i.e., does not help programmers to catch errors at compile time. Libraries distributed through eggs; since my college blocks external proxies, I was not able to download string libraries. 3) Stalin. It does not provide string processing libraries; at least I am not aware of a repository of Stalin libraries; since you seem to be offended because I gave up Stalin for this particular problem, tell me about good libraries for Stalin, and I will be happy in using it for similar problems. In any case, I solved tem0's problem in Stalin, but the solution was quite large (20 lines) because Stalin lacks libraries to process strings. In any case, it generated the smallest stand alone file. 2) Bigloo. It is from 2 to 3 times slower than Stalin when it comes to number crunching. For other kind of problems, it is about as fast as Stalin. It has good string processing libraries, good GUI (based on GTK, on dotNet, and on JVM), etc. When it comes to string processing, it has regular expressions, Lalr grammars, etc. Distribution is somewhat smaller than 1Mb, that is the limit set by the TA of functional programming for the assignments. 1) DrScheme. It is very unfriendly, and very slow. Let me explain what I mean by very slow. It takes about 15 seconds to enter the IDE. It chooses the language that it thinks that you should speak (in my case, it guessed wrong smile :-). Perhaps because I use a Canadian OS, it guessed French. I suppose that there is a way to switch to English, or to Gr
, but I did not have time or disposition to find out. I typed my program, and selected the Scheme/Build option (I am translating from French). I was not prompted for optimizations. I suppose that there are options for optimizations, but I could not find any help explaining how to use them. I tried the option --help from the command line, to no avail. The result was that the distribution turned out to be huge (5M), and slow. Stalin distribution for the same problem is less than 200K, and Bigloo static distribution is 945K. I tried a few benchmarks pitting mzscheme against Bigloo, and Stalin (binary tree, recusive programs, etc.) and it turned out to be from 6 to 20 times slows. I insist, I was not able to do any optimization in mzscheme. The worse part is that I made two mistakes, and did not receive any warning! In one of the mistakes, I had a wrong close parentheses, in such a way that I got a (display ...) with many arguments; only after running the program many times, I got a runtime error. Stalin and Bigloo refused the buggy program right away. BTW, I asked here for help in compiling programs with Gambit, but I believe that I did not receive any answer. I would be happy in getting help in setting optimization options for mzscheme, and in installing Ikarus for mingw gcc.
Post Follow-up to this messageOn 27 mar, 09:26, Griff <gret...@gmail.com> wrote: > Phi will you do my homework for me, too? :) Hi, Griff. You are most welcome to our group. However, I advise you that the group does not do homework for people who do not want to work hard. What we do is the following: (1) Select the most interesting assignments, and work together to provide elegant and complete solutions; for instance, a TA asks for a pretty print, and gets a fairly complete editor, with pretty print, parentheses checking, etc. This example is real, and we will post it tomorrow. (2) Help beginners to learn Scheme. We have concise tutorials (number maximum of pages: 100), written in LaTeX. You can get a flavor of these tutorials on our page: code.google.com/p/stalingui If a member of the group is not working hard, he is expelled, i.e., he has no right to propose assignments to the members of the group. In any case, you are most welcome. However, I think that you are a good Scheme programmer. I believe that you will help us more, than get help from us (smile :-)
Post Follow-up to this messageOn Mar 27, 9:54 pm, phi50...@yahoo.ca wrote: > 1) DrScheme. It is very unfriendly, Ack! It is not supposed to be! DrScheme is really set up to make it easy for folks to use. I would be interested to know, what were the obstacles for you getting what you need in terms of usability? > Let me explain what I mean by very slow. It takes about 15 seconds to enter the ID E. It sounds like your primary goal is speed and compactness of compiled artifacts. By your criteria, the best folks with whom to speak about performing such optimizations are on the PLT discussion list: http://www.plt-scheme.org/maillist/ My take on PLT is that they provide an "all-around best approach" in terms of interpreter, language, libraries, ide, documentation, and vision. That might not be the right place for your group! But, it is right for some folks! > The result was that the distribution turned out to be huge (5M), and slow. I haven't solved the problem presented by the original poster, but I can tell you that on Windows XP Pro with DrScheme v372, a "Hello, world." application gets compiled down to 240KB. 5M sounds way too big. Here is the code: (module hello-world mzscheme (display "Hello, world.")) put it in a file called "hello-world.ss" and compile it with mzc --exe hello-world hello-world.ss
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.