This is the mail archive of the guile@cygnus.com mailing list for the guile project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Well, I've refined the logo translator a bit. One question: is there a low-level manner of signalling an error? Specifically, I'd like for the translator to signal errors in the source code the same way the standard repl loop signals errors. Right now, when I call an error it shows the filename and position in the translation code -- now, it's unlikely anyone would be fooled by that as my code has no bugs :P But, still, it would be nice to show the filename and position of the file I'm reading. scm-error doesn't do this. Any ideas? Even a way to exit the program prematurely so I can make my own error function? Well, anyway, I thought I'd also comment on why Logo is nice. By way of example, I'll show some Logo code. This is a simple generalized estimation procedure written in Logo (my dialect): to estimate :low :high [block :test] [:accuracy 0.01] (local :mid :result) make :mid (:low + :high) / 2 make :result (run :test :mid) if :accuracy > abs :result [return :mid] ifelse :result > 0 [(estimate :mid :high :test :accuracy)] [(estimate :low :mid :test :accuracy)] end To estimate the square root of 10 : estimate 0 10 [10 - ? * ?] The :accuracy argument is optional (default value being 0.01). The third argument to estimate will be made into a lambda, specifically: (lambda (?1) (- 10 (* ?1 ?1))) The translator knows it should be translated into a lambda-form because the declaration of estimate marked that argument as a block. This makes up for Logo's lack of closures (or, creates closures where Logo did not have them). You can write such closures with another syntax as well (without ?'s): map [[value] :value * :value] [1 2 3 4] ==> [1 4 9 16] Note that Logo uses [] to make lists -- like '() in Scheme. It's overloaded to make lambdas as well -- in Real Logo lists and blocks (not real closures) are the same thing, a technique something like what Tcl uses (except with lists as the dominant form instead of strings). You only need to put parenthesis around a procedure call only when you want to call it with some number of arguments other than the default (or when the procedure has not yet been defined, so you can't know what the default number of arguments is). For instance: (estimate 0 10 [10 - ? * ?] 0.00001) For a more accurate estimation of the square root of 10. That gives some of the details of how Logo works. Now, some reasons why it's better than Scheme (emphasis on end-user scripting): It needs a lot less parenthesis. Having as many parenthesis as Scheme does can be intimidating and seen as excessive. The parenthesis do have the problem of being horribly monotonous, being used everywhere so that you can't distinguish the areas of particular interest. Lists, with '(), procedure calls, with (), vectors #(), on and on... everything uses parenthesis. Logo doesn't have a whole lot extra, but it does distinguish ()'s and []'s. () used for precedence and non-default number of arguments, []'s used for lists and lambdas. Logo allows comfortable non-local(?) returns. Particularly when writing in an imperative style, it's nice to be able to return from the middle of a procedure. You can do that with call-with-current-continuation (and the translated form does exactly that), but it's much more general and more complicated than it is with a normal "return" (from the perspective of reading and writing the code). Logo has fairly decent forms for lambdas. It doesn't use the word "lambda", for instance, which is a win (IMHO). I think the ? notation can also be nice for making a quick, small closures. It's very clear what's going on with the form. It's also a little more compact. Logo has infix operators with precedence (though the precedence is a little odd, unfortunately). This is obviously easier and more clear. Unfortunately, it does mean that the mix between Logo and Scheme isn't completely happy, but by demanding that all operators be surrounded by spaces most of the problem is avoided. The most recent version of the translator can still be found at: http://www.cs.earlham.edu/~bickiia/logo-scheme.tar.gz <-------------------------------------------------------------------> < Ian Bicking | bickiia@earlham.edu > < drawer #419 Earlham College | http://www.cs.earlham.edu/~bickiia > < Richmond, IN 47374 | (765) 973-2824 > <------------------------------------------------------------------->