archives

Have I Missed Something ?

Hi,

I have been learning Lisp (SBCL 1.0.1 for intel Mac) for a couple of months as time permits. I have installed and tweaked cl-opengl nnd I am now starting a 'project' as a learning experience, a simple Lisp editor using OpenGL. I have a package for it and all is well on the general code creating front.

However, in the course of my fiddlings, I have created a structure called 'editor-env':

(defstruct editor-env
  buf                   ; buffer for the loaded file                                                                                                 
  top                   ; the top-edge [y] coordinate of the window                                                                                  
  left                  ; the left-edge [x] coordinate of the window                                                                                 
  row                   ; cursor row value                                                                                                           
  col                   ; cursor column value                                                                                                        
  row-max               ; maximum height of full columns plus one                                                                                    
  col-max               ; maximum width of full columns plus one                                                                                     
  csr-char              ; character for the cursor position                                                                                          
  paper                 ; background color                                                                                                           
  ink                   ; text foreground color                                                                                                      
  font font-dx font-dy  ; font face and cell size                                                                                                    
)

As my code is growing, I am finding that I am typing things like this:

(defun rowcol->screen (row col)
  (let (x y)
    (setq x (+ (editor-env-left *env*) (* col (editor-env-font-dx *env*))))
    (setq y (+ (editor-env-top *env*) (* row (editor-env-font-dy *env*))))
    (return-from rowcol->screen (values x y))))

(Any suggested style / Lisp idiomatic improvements always welcome.)

I mean of course the (editor-env-FFFF *env*) idiom for setf/getf usage, over and over and over again. Dare I say that I almost miss the ability of the Java/C++ '.' operator (or -> etc). I have used Smalltalk for eight years and that even seems better than the above!

So, my question is this...have I missed something fundamental in the way that I could be acessing fields in my structure. I know that I could declare a macro but

  1. is that the 'Lisp' way (I am still learning remember)
  2. isn't that just creating my own syntactic sugar ?

If it is a case of (1) using macros then I guess I am still climbing the learning curve. After 21 years in software, you still have to climb. Daily.... otherwise you slide back down.

What I really want to know is, how does everybody else do it / deal with a high volume of field access. Is it with multiple-value-bind type things, is there a PASCAL 'with' or something that I have yet to find. The HyperSpec is truly huge and I think that the Hitch-Hikers Guide pales in comparison.

Many thanks,
Sean Charles.

F3: New statically typed scripting language for java

Chris Oliver has been working on F3 ("form follows function"), a new scripting language for the java platform. Here is a detailed description of F3's features.

It is already in heavy development but not yet released, and there are plugins for both Netbeans and Eclipse. Some of its functionality and the examples Chris has shared indicate it could be an alternative to Flash and processing.

Summary of some of its features:

  • It is case-sensitive and uses curly braces, so it is very java-like.
  • It is statically typed with type inference (like boo). It uses "var" for type inferenced declarations (var x = 3;), like in groovy or C# 3.0.
  • It supports a JSON-like declarative syntax for building GUIs (as opposed to XML or YAML).
  • Has a ".." range literal: var result = sum([1,3..100]);
  • Supports SQL notation for querying arrays:
    var squares = select n*n from n in [1..100];
    //another example:
    var titleTracks =
                select indexof track + 1 from album in albums,
                          track in album.tracks
                              where track == album.title; // yields [1,4]
    
  • You can also embed the JSON-like syntax in code (or vice-versa):
            var chris = Person {
                 name: "Chris"
                 children:
                 [Person {
                     name: "Dee"
                 },
                 Person {
                     name: "Candice"
                 }]
           };
    
  • Supports expressions inside strings:
    var answer = true;
    var s = "The answer is {if answer then "Yes" else "No"}"; // s = 'The answer is Yes'
    
  • Supports "do" or "do later" for code that either allows background events to occur or runs in a background thread itself:
            import java.lang.System;
            var saying1 = "Hello World!";
            var saying2 = "Goodbye Cruel World!";
            do later {
                 System.out.println(saying1);
            }
            System.out.println(saying2);
    
  • It may be using a MultiVM technique where different applications run in the same JVM instance, saving memory and improving start-up time.
  • All methods and attributes of a class have to be declared first (like in C and C++, yay), and then the implementations are written outside the class body (like in nice).
  • Instead of constructors and setters, F3 uses "triggers":
             import java.lang.System;
             class X {
                  attribute nums: Number*;
             }
             trigger on new X {
                  insert [3,4] into this.nums;
             }
             var x = new X();
             System.out.println(x.nums == [3,4]); // prints true