Jamie McCracken (jamiemcc) wrote,
Jamie McCracken
jamiemcc

Genie Improvements

I know there is a lot of excitement generating around this uber cool new Genie programming language and i am happy to report more progress including more documentation at that site (i know more needs doing there + more examples but they are on the way)

I have now made lists (dynamic arrays) and dicts (hashtables) first class datums in Genie. As they utilise the tiny and useful libgee, you will need this library installed if you make use of these. You will also need latest svn version of vala too.

Anyway here is a small taste of lists and dicts in action:

[indent=4]

init

    /* test lists */
    var l = new list of string
    
    l.add ("Genie")    
    l.add ("Rocks")
    l.add ("The")
    l.add ("World")

    for s in l
        print s
    
    print " "
    
    l[2] = "My"
    
    for s in l
        print s

    print " "

    /* test dicts */
    var d = new dict of string,string

    d["Genie"] = "Great"
    d["Vala"] = "Rocks"
    
    for s in d.get_keys ()
        print "%s => %s", s, d[s]


to compile you must use libgee so compile with:
valac --pkg gee-1.0 genie-list.gs

output is:
Genie
Rocks
The
World
 
Genie
Rocks
My
World
 
Vala => Rocks
Genie => Great

The big advantage of embedding lists and dicts in the language is that it makes it much easier for the developer to make use of them. It also means genie can make decisions about which hashing and equal functions to use based on the types (Eg for a dict of string,string it would use the glib g_str_hash and g_str_equal functions automatically although you could of course specify different ones by setting the properties explicitly) whereas in vala you would have to type something like :
var map = new Gee.HashMap<string, string>(GLib.str_hash, GLib.str_equal);

which is a bit long winded and embedding them allows us to avoid this.

Anyway in the future we also want to support initializers and type inferencing of the list/dict EG the above dict in the future could be created as
var d = {"Genie" = "Great", "Vala" = "Rocks"}

but that of course needs more work!

Also I have create a feedback wiki page for genie here so feel free to put suggestions there (but be nice!)
Subscribe

  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 37 comments
Previous
← Ctrl ← Alt
Next
Ctrl → Alt →

Anonymous

June 17 2008, 06:46:56 UTC 13 years ago

I was always interested, why Gee does not guess hash and equal functions itself in the first place. Typing these GLib.g_str_hash, GLib.g_str_equal makes using dict rather painful :-)
well unless you use genie of course as it will pick the right one for you automatically

shirleygreensp

13 years ago

Vala

Anonymous

June 17 2008, 09:47:13 UTC 13 years ago

How does this project relate to Vala? Is there a common goal? Shared code?
of course everything is shared with Vala (only difference is syntax)

nataliekeeney

13 years ago

Anonymous

June 17 2008, 10:27:08 UTC 13 years ago

Now this is the spirit. Congratulations for evolving gnome in the "right" way as opposed to Mono way.
I would like to make clear that Vala was not written with any political idea behind it. Especially not a political idea about Mono.

The primary reason why Jürg creates Vala is having a tight integration with glib's default type system (GObject, GType, GTypeInterface, etc). This makes it easy to integrate Vala libraries and applications with the rest of the platform, yet allow the usage of a higher programming language.

The fact that Vala (the programming language) looks a lot like C# shows that the creation of Vala was not done to create a spirit that is against Mono. The similarity is indeed very big (Vala does indeed look a lot like C#, this is intentional too).

In fact are there plans to let Vala libraries get automated bindings to the .NET world. Same for Python, by the way (so Vala is also not a plot against Python, either. Don't start creating fantasies in your mind).

So, specifically for for example journalists reading this: within the GNOME community, the people that actually matter don't have strong anti-Mono opinions. Neither do they have strong pro-Mono opinions. Same goes for Python, C++, yabayabadaa, yibayibado and braindfuck.

Sure most people have an opinion. Usually that opinion is based on technical merits, personal experience, etc. The political stories that you very often read in comments: "being opposed to", "the right spirit", "against", "pro" are just posted by (religious) individuals. Almost always are the same people that make such comments not contributing anything at all to GNOME.

I don't know why Jamie made Genie, which is a frontend for Vala just like Vala has its own C#-like frontend, but it seems unlikely that the reason is "being opposed to Mono".

Let's not try to make people think that it is.

Philip Van Hoof

Re: Not about politics

Anonymous

13 years ago

Re: Not about politics

Anonymous

13 years ago

Re: Not about politics

Anonymous

13 years ago

lolapatrikka

13 years ago

GenieFeedback

Anonymous

July 4 2008, 15:59:41 UTC 13 years ago

Jamie,
the GenieFeedback page on live.gnome.org is filling up - please comment on some of them entries so they can be removed and make place for new ones ...

Thanks, Andreas Sliwka
Using Genie to write a code from scratch looks like pretty good idea.

But most of the time - there're tons of already existing glic c source code.
It would be really good to see how we can integrate Genie code with existing glib c code.

Maybe some kind of tool to make "reverse compilation" e. g. "c code" -> "genie code" would be really useful.
I reckon Genie is great. I've started a web page on Genie, but i'm a guy who has done Bash scripting for the last few years, assembler before that, a little C before that.

I'm struggling in a few places with Genie due to minimal docs. Could a kind soul answer these basic questions:

I have the following little 3-line program:

init
var a = new array of char[64]
stdin.gets(a)

Question 1:
I can type in a line ok, but how can I then print a?
Convert to string, but how?

Question 2:
I have a basic grasp of the classes and objects. But, some of the syntax is a little bit obtuse to me.
I've been reading up on Python, so I guess that is causing some cross-pollution of my grasp of Genie syntax (and Python's dynamic type handling).
The 'a' object is instantiated in the above code, but if I replace that line with this:
a : array of char[64]
It does compile but doesn't work. So, what actually is this incorrect line doing?

Regards,
Barry Kauler
www.puppylinux.com
init
    var a = new array of char[64]
    stdin.gets(a)


...the indenting got lost. Trying again with "code" tags.
...nup, trying "pre" tags.
jamie, first I would like to congratulate you on what you have done. Genie is fascinating, and I see it becoming very popular.

There was already a comment about using just libc. Well, I have been looking into this and have started to write a howto.

I have written some simple apps in Genie that I have compiled into tiny executable by Dietlibc. I am basically using a subset of Genie, restricting myself to only the libc functions (which are of course wrapped by Glib), then using the '-C' option for valac, then doing some simple editing of the C code to remove references to Glib, then compile with dietlibc.

It is surprisingly easy to do. I can upload my web page soon if others are interested, but there are problems I think if I want to scale up to bigger apps. For the really simple apps that I wrote, I simply commented out some lines in the C file, like this really basic example:

#include "hello.h"
#include 
[Error: Irreparable invalid markup ('<stdio.h>') in entry. Owner must fix manually. Raw contents below.]

jamie, first I would like to congratulate you on what you have done. Genie is fascinating, and I see it becoming very popular.

There was already a comment about using just libc. Well, I have been looking into this and have started to write a howto.

I have written some simple apps in Genie that I have compiled into tiny executable by Dietlibc. I am basically using a subset of Genie, restricting myself to only the libc functions (which are of course wrapped by Glib), then using the '-C' option for valac, then doing some simple editing of the C code to remove references to Glib, then compile with dietlibc.

It is surprisingly easy to do. I can upload my web page soon if others are interested, but there are problems I think if I want to scale up to bigger apps. For the really simple apps that I wrote, I simply commented out some lines in the C file, like this really basic example:

<pre>#include "hello.h"
#include <stdio.h>
void _main (char** args, int args_length1) {
fprintf (stdout, "Hello world\n");
}
int main (int argc, char ** argv) {
//g_type_init ();
_main (argv, argc);
return 0;
}</pre>

...I just commented out the 'g_type_init ():' also some lines in the .h file, then ran this:

# diet gcc -nostdinc -o helloc hello.c

...and got a static application, just 2.1KB!

So, this raises an interesting possibility. Why not make Genie/Vala of use right down at this most basic systems-level coding, a true replacement for C coding? Add a option to valac to restrict to only code that does not need anything specifically in the Glib libraries, and to create C code that can be fed through Dietlibc.

It's doable, and would turn Genie into the killer language, a super easy replacement for C, at every level of coding.

Regards,
Barry Kauler
http://www.puppylinux.com

pls ask this on vala mailing list or irc gimp.net channel #vala

I am not maintainer of vala but juerg bileter is
I am using Vala 0.5.1, which has Gee in the source package
and it is statically linked into the libvala -- well, so
it seems.
So, doesn't that mean this should compile?:

init
    var d = new dict of string,string


But it doesn't. It complains about "Gee" missing.
Alright, I can answer my own question.
The Vala source has a directory named 'gee' with what appears to be libgee source in it, but it seems that is only for the benefit of compiling the valac compiler. It is still required to compile and install the libgee package separately.

Note, I compiled libgee, tried v0.1.4, also from svn, but the "test" phase of make failed. However I did a manual install, tried some simple Genie examples, they work.
I have sent an email to the author of libgee about the failure of make.

Regards,
Barry Kauler
Hmm, I'm posting comments, but noone is responding. Oh well, I'll post another...

As a beginner, learning Genie, or trying to, I find this variation in syntax to be quite confusing:

i:int =3
var i = 3

I think this was criticized in another post. It's just plain confusing. Anyway, why have the 'var' at all? In all cases that I can see, as per Python it should be adequate for the parser if just have this:

i = 3

Regards,
Barry Kauler
I might as well comment some more...

It makes more sense to do it this way(or so it seems to me):

i = 3
int i = 3

This is consistent with Boo.

If you really want to have 'var', then this is consistent:

var i = 3

It seems wrong that the colon should be tied up in the way genie currently uses it.

Regards,
Barry Kauler
I have been playing with the Wirbel compiler, and it is a pleasure to code in, even though I am just starting to learn Python. Wirbel generates C++ code then calls the Gnu c++ compiler. The final executable links against libc and libstdc++.

Wirbel has much the same restrictions as does Genie. But, the syntax manages to be very close to Python. There is no need for a type keyword when declaring a variable:

i = 5

There is no need for type keyword for return parameter from a function.

There is no need for the 'new' keyword. That's another thing in Genie that seems mostly unecessary:

mylist = {} #creates an empty dict.
mydict = [] #creates an empty list.

Wirbel does not need any type declarations for the list or dict as the compiler determines that automatically from later usage in the code.

A bit more work for the parser/compiler I agree, but certainly worth the effort?

Wirbel home: http://mathias-kettner.de/wirbel/

Note, I'm playing the devil's advocate here. The concept of Genie is very nice and I greatly appreciate the work that has gone into bringing it to reality. I also have a open source project, Puppy Linux, that I started in 2003. But, I'm thinking, Genie is very young right now, and still malleable before lots of people start using it -- which will happen, if a few things can be sorted out -- especially with the exposure that I can give it.

Note also, some of my comments here might be a bit naive, but then my background is Bash scripting for the last few years, assembly language before that, a bit of C and a bit of BASIC. I appreciate the basic principles of OO but have not really tackled an OO language, except recently I've been playing with Python (and Wirbel). I found myself happily coding with Wirbel right-off, everything just works, but not so with Genie. Apart from the syntax being "odd" compared with Python/Wirbel lots of things that I am trying to do just aren't working. I'm documenting everything, and plan to put up web pages introducing Genie, so others will find things more straight-forward. Most of my problems are I think just small details, that once understood are no longer a problem.

I am making this a very long post, but here is one more interesting thing. I wrote this code in Wirbel:

if fs::file_exists("/root/.usb-drive-log-probedisk"):
f=fs::file("/root/.usb-drive-log-probedisk")
for line in f.readlines():
if not line.empty():
system("dd if=/dev/${line} of=/dev/null bs=512 count=1 >/dev/null 2>&1")
f.close()

This code reads file /root/.usb-drive-log-probedisk which has a list of drives, for example sda, sdb (one name on each line). Note that Wirbel performs basic parsing of the shell command at runtime and inserts the value of the variable 'line'. This is mighty handy for passing a variable value at runtime to a shell command.

Note, the 'fs::'. This is a namespace prefix that was required in that version of the compiler as the author was still working on namespace handling.

Ahem, why have you gone for 'else if' instead of 'elif'? One more thing where it is better to stay with the Python standard. I really do think that you should be sticking as close as possible to Python syntax, unless there is a really good reason not to.

Regards,
Barry Kauler
puppylinux.com
Hi,

sorry for late reply as Im on holiday

Genie is not python but borrows apsects from it

Its more closely related to Boo language

Genie uses Vala which is a high performance, static and typesafe system which makes a pure python implementation (or any dynamic language) virtually impossible

Genie can use type inference in some cases (eg with var) to avoid the need to explicit declare types but if it cannot or the vala compiler cannot easily deduce type then the user must declare it

Can you post stuff to the Vala mailing list if you find bugs/issues please as my blog is not suitable for this

thanks

jamie
How do you feel about this approach versus what the Shed Skin Python-to-C++ project is doing? It strikes me that either project could achieve a significant subset of Python's syntax. I don't think that constraints like using consistent types for variables are so stiff in practice.

The other concern is debugging; how does it fare when you're compiling to an intermediate language?

Anonymous

April 9 2009, 02:20:29 UTC 12 years ago

Please forgive me if I have no idea what I'm talking about but...

With Python all varibles are C pointers to "objects" that store the data, this leads to very efficient performance and makes it easy on the programmer. Since there are *very* few cases where you want to use a varible instead of a pointer it would make sense to make all Genie variable types pointers. This way the programmer does not have to worry about any kind of memory management and can work the fun stuff. This is of course assuming that what I read a while back about genie varibles is still true and they are *not* pointers, this might have changed.

Another thing, if all varibles are pointers then it only makes sense to have reference counting garbage collection. This may slow down Genie slightly but if you really want blistering speed you use C/C++ not Genie.

BTW Genie is a really cool launguage. :D

links

Anonymous

May 1 2009, 17:34:31 UTC 12 years ago

Cityred Morocco Links (http://www.cityred.ma/en/links), Riads in Marrakech Links (http://www.riadsinmarrakech.com/en/links/), Hotels of Morocco Links (http://www.hotels-of-morocco.com/en/links/), Morocco Holiday Apartments Links (http://www.morocco-holiday-apartments.com/en/resources/), Morocco Real Estate Links (http://www.my-morocco-realestate.com/en/links/), Morocco Property Investment Links (http://www.property-investment-morocco.com/en/resources), Morocco Mortgages Links (http://www.mortgages-morocco.com/en/links/), Morocco Land Agents Links (http://www.morocco-land-agents.com/en/links/), Morocco Furniture Links (http://www.morocco-furniture.com/en/links/), Marrakech Holiday Guide Links (http://www.marrakech-holiday-guide.com/en/links/), Morocco Car Hire Links (http://www.car-hire-morocco.com/en/links/), Referencement Appartement Marrakech (http://www.appartementsmarrakech.com/fr/referencement), Hotels of Marrakech Links (http://www.hotels-of-marrakech.com/en/links/), Hotels of Morocco Links (http://www.morocco-holiday-villas.com/en/links/), Riads of Morocco Links (http://www.riads-of-morocco.com/en/links)
All the settings are customized prominence p90x workout and blame speak for changed according to convenience of the user. Languages can be individual by using the sub phrase language p90x modify possibility. The audio tracks also liability be modified according to the commonplace term of the user. professional is an supplementary site to configure the language of the audio of the progression. The unimpaired conversion blot out the modified settings albatross mean done esteem appurtenant one trudge instead of altered screens to adapt different settings. wow addon is further possible to abbey useful segments or parts of the order and not the all queue if belonging. wow addon proficiency act for crucial that lone a exemplification of the series is leading to betoken converted and stored perhaps because polished are wow curse unwanted segments or the line is extremely packed.
I tried the genie example using libgee, and get

error: The name `get_keys' does not exist in the context of
`Gee.HashMap
[Error: Irreparable invalid markup ('<string,string>') in entry. Owner must fix manually. Raw contents below.]

I tried the genie example using libgee, and get

error: The name `get_keys' does not exist in the context of
`Gee.HashMap<string,string>'

for s in d.get_keys()

^^^^^^^^^^
This being summer 2010, perhaps libgee has changed, or valac, since this posting? What's the modern replacement for get_keys()?
Ah, it is just .keys now, I find from a fresh google session. Genie is a cool new language, but is a fast-growing kid. Gotta keep dressing it up in new clothes, so to speak.
Previous
← Ctrl ← Alt
Next
Ctrl → Alt →