LtU Forum

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
    

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.

Extracting Queries by Static Analysis of Transparent Persistence

Ben Weidermann and William Cook of UT Austin have put together a paper on translating procedural code into SQL.

From the abstract:

"Transparent persistence promises to integrate programming languages
and databases by allowing procedural programs to access
persistent data with the same ease as non-persistent data. When the
data is stored in a relational database, however, transparent persistence
does not naturally leverage the performance benefits of relational
query optimization.We present a program analysis that combines
the benefits of both approaches by extracting database queries
from programs with transparent access to persistent data."

You can find the paper here.

Great Expectations: Java Virtual Machine

hi everybody,

did you notice that...

Java is now GPL! [tra la la la]

but...

I am not sure what it means for Java to be distributed under GPL. I reckon the first thing is, it can be distributed with Linux distros right away. was that impossible before?

the second question, I hope, is more important. can there be forks of the Java legacy now?

more specifically, *ahem* if now, can we implement a VM that satisfies the JVM specification but allows more? if not, consider the question hypothetical.

so that, Java will run on the VM, but [a narrow example] there will be other bytecode operations...

you know, things like JSR 292... invokedynamic, hotswapping...

what would be, in your opinion, the most significant change you want to see in the current JVM?

[don't mind me, I'm a newbie, I'll just follow the discussion. but even though it is not a language topic, some things, like the closure proposal, I suppose, are relevant.]

Will Rubinius be an Acceptable Lisp

rubinius is a new, experimental VM for Ruby in (mostly) Ruby, based on the Smalltalk-80 blue book. Recently, the developers talked about building a lisp-dialect interpreter on top of the VM, to help shake out bugs and to provide an alternative syntax for write software on (or in) it.

Help with a little geometric hackery...

Hey LtUers,

i discovered a cool way to visualize terms in reflective calculi. At (http://biosimilarity.blogspot.com/) i posted the core calculation. (Apologies for the layout... i don't know why the use of the table tags are causing so much spacing.) i'll recapitulate them here. i'm wondering if someone familiar with the gfx libs of OCaml or F# or Haskell would be interested in helping me implement the algorithm. It's dirt simple, but i'm pretty rusty on my basic geometry, anymore, and really don't know the gfx libs of these languages. Write me at lgreg.meredith@biosimilarity.com if interested.

Best wishes,

--greg

Last night i discovered a geometric interpretation of the reflective versions of the λ- and π-calculi. It's 'simplicial' in nature. For example, take the reflective version of the asynchronous π-calculus.


P,Q ::= 0 // stop, or nil process
x[|P|] // lift
x(y).P // blocking input
P|Q // parallel composition
*x // drop
x,y ::= ^P^ // quote

Assign a dimension to each term constructor. Thus, we have

0-dim
lift-dim
input-dim
par-dim
drop-dim
quote-dim

or 6 dimensions.

We define a recursive function, G[ - ]: L(P) → R6, assigning to each term a shape in 6 dimensions. After doing some calculations, i'm pretty sure that you want to do scaling and offsets, but i've screwed up the accumulated scaling twice; so, i'm eliminating it and just giving the algorithmic scheme to which you can add your flavor or scaling and offset.



G[0] = (0,0,0,0,0,0)
G[x[|P|]] = { (r0,...,r5) |
let cx = barycenter(G[x]) in
let cp = barycenter(G[P]) in
let ct = vertex equidistant to cx, cp and perpendicular to [cx,cp] in lift-direction in
(r0,...,r5) in [cx,cp,ct] }
G[x(y).P] = { (r0,...,r5) |
let cx = barycenter(G[x]) in
let cy = barycenter(G[y]) in
let cp = barycenter(G[P]) in
let ct = vertex equidistant to cx, cy, cp and perpendicular to [cx,cy,cp] in input-direction in
(r0,...,r5) in [cx,cy,cp,ct] }
G[P|Q] = { (r0,...,r5) |
let cp = barycenter(G[P]) in
let cq = barycenter(G[Q]) in
let ct = vertex equidistant to cp, cq and perpendicular to [cp,cq] in the par-direction in
(r0,...,r5) in [cp,cq,ct] }
G[*x] = { (r0,...,r5) |
let cx = barycenter(G[x]) in
let ct = vertex unit length from cx in drop-direction in
(r0,...,r5) in [cx,ct] }
G[^P^] = { (r0,...,r5) |
let cp = barycenter(G[P]) in
let ct = vertex unit length from cp in quote-direction in
(r0,...,r5) in [cp,ct] }

i believe that this will yield interesting visualizations of the terms of this calculus if we assign 3 dims to x,y,z and 3 dims to pitch, roll and yaw. The dynamics of execution will yield animations.

Intellisense for dynamic languages

I've recently been toying with various approaches for supporting some level of intellisense on a dynamically typed language, specifically Lua (a functional scripting language with lexical scoping). I'd like to bounce some ideas around the community and hear some opinions. I should pretext this by stating that I'm not really a "languages guy." I have a CS degree with the standard compilers course but no advanced experience...which is probably why I was naive enough to undertake this in the first place :P But I have a significant amount working.

Since intellisense information is based on type information, there are inherent difficulties in implementing this for dynamic languages. The problem I'm most interested in is the following.

Let's say we have a name n in the scope s which is assigned different types within a conditional statement. For example, assume N and M are valid variables with different types below.

function s()
local n

if x then n = N else n = M end

...
end

We want to be able to resolve the type of n to provide intellisense information for it after the assignment. In order to do so, it seems we must first resolve x. However, this may not be possible outside of runtime (it could be a runtime lib call for instance). A similar problem occurs when a function has multiple return statements.

The solution I'm currently considering is to present all possibilities to the user. For instance, in the example above we know n is either type of N or type of M. In an environment like Visual Studio or Eclipse the intellisense drop down could display both possibilities with a special icon or text that indicates the ambiguity. In some situations, it may be obvious to the author what the correct option is for a given case. In a nutshell, if the parser can't figure it out statically then we ask the author to disambiguate and treat the name as the disambiguated type from that point forward. At least until it's made ambiguous again by a similar sort of assignment.

I can see a somewhat controversial aspect of this being that it can make you think about types while coding in a dynamically typed language. Also, since it's implied that the parser must keep track of every assignment, scalability is a concern.

Comments? Alternatives? Will this be useful?

Cheers,
Trystan

Finding Landin's "The Mechanical Evaluation of Expressions"

I've been continually surprised by both the amount and the quality of comp sci literature that can be obtained from the web. Other than text books, there have been only a few occasions when I've been unable to locate an article. However one such exception has been Landin's "The Mechancial Evaluation of Expressions". At this point it feels that every other article I read cites Landin's paper. I have all of his other major papers, but TMEE is the one that is mentioned as the most central. I've tried and failed numerous times. Most inexplicably the Oxford Journal website appears to have no notion that this paper exists. Can anyone help me.

On Presenting the Semantics of Cat Formally

First I want to say that I owe a debt of gratitude to the LtU community for the generous help I've had in developing the type system for Cat. Two threads last month were particularly helpful for me: http://lambda-the-ultimate.org/node/1879 and http://lambda-the-ultimate.org/node/1899. So thank you very much to everyone who contributed to these threads (and previous ones as well).

I have been working hard on writing an article to present the Cat language formally, but I still lack confidence in my approach to presenting the type system. I felt that it would be useful in a paper which presents the semantics of Cat to demonstrate an implementation of the typed SK calculus. One burning question I have is whether such an endeavour would add value to the paper?

Below is a synopsis of how I am planning on presenting the type system and SK calculus in the paper. For the purposes of this post I only show the type derivation of the K combinator, since the S combinator is much longer.

Types of Common Operations

The r stands for the row variable (rho or ρ).

  pop : (r 'a -> r)
  dup : (r 'a -> r 'a 'a)
  swap : (r 'a 'b -> r 'b 'a)
  dip : (r 'a 'b ('a -> 'c) -> r 'c 'b)
  diip : (r 'a 'b 'c ('a -> 'd) -> r 'd 'b 'c) EDIT
  eval : (r 'A ('A -> 'B) -> r 'B)
Core Typing Rules

These are attributed to Andreas Rossberg.

  -------------------------------------------- (EMPTY)
  T :- empty : (r)->(r)

  T(x) = forall a1..an A1..Am.t
  -------------------------------------------- (VAR)
  T :- x : t[t1/a1]..[tn/an][r1/A1]..[rm/Am]

  -------------------------------------------- (CONST)
  T :- c : (r)->(r prim)

  T :- p : t
  -------------------------------------------- (QUOTE)
  T :- [p] : (r)->(r t)

  T :- p1 : (r1)->(r2)    T :- p2 : (r2)->(r3)
  -------------------------------------------- (COMPOSE)
  T :- p1 p2 : (r1)->(r3)
Supplemental Typing Rules
  T :- p : (r A)->(r B)
  ---------------------------------------- (T-EVAL)
  T :- [p] eval : (r A)->(r B)

  T :- p : (r A)->(r B)
  ---------------------------------------- (T-DIP)
  T :- [p] dip : (r A 'c)->(r B 'c)

  T :- p : (r A)->(r B)
  ---------------------------------------- (T-DIIP)
  T :- [p] diip : (r A 'c 'd)->(r B 'c 'd)
Derivation for the K Combinator

K is implemented as "[pop] dip eval". The derivation is:

    pop : (r0 'a0 -> r0)
  0 ---------------------------------------------------- T-DIP
    [pop] dip : (r1 'a1 'b1 -> r1 'b1),
    eval : (r2 'A2 ('A2 -> 'B2) -> r2 'B2)
  1 ---------------------------------------------------- COMPOSE
    [pop] dip eval : (r1 'a1 'b1 -> r2 'B2)
    , r1 'b1 = r2 'A2 ('A2 -> 'B2)
    ,'b1 = ('A2 -> 'B2)
    , r1 = r2 'A2
  2 ---------------------------------------------------- UNIFY
    [pop] dip eval : (r2 'A2 'a1 ('A2 -> 'B2) -> r2 'B2)
  3 ---------------------------------------------------- SIMPLIFY
    [pop] dip eval : (r 'A 'b ('A -> 'C) -> r 'C)

What I am hoping for are suggestions on how I can better present the semantics of Cat in a way which would be appropriate for a "serious" paper, but also would make sense to relative newcomers to type theory.

Thanks in advance!

Call by push-value

The Call By Push-Value FAQ
So I should give MyLang a miss, and study CBPV instead?
Science is reductionism. Once the fine structure has been exposed, why ignore it?

Paul Blain Levy papers

Call-by-push-value is a programming language paradigm that, surprisingly, breaks down the call-by-value and call-by-name paradigms into simple primitives. This monograph, written for graduate students and researchers, exposes the call-by-push-value structure underlying a remarkable range of semantics, including operational semantics, domains, possible worlds, continuations and games.

This topic is not unknown on LtU but my search did not turn up any thread focused on the subject. l am looking for some help understanding the concepts.

XML feed