Vala and Genie programming

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#41 Post by MU »

Code: Select all

  stdout.printf("test")
  stdout.printf("test")
  stdout.printf("ok\n")
  stdout.flush()
Without "\n", no linefeed is printed.
stdout is printing to a buffer, so you finally in the end have to print a "\n", and you have to "flush" to be sure, it becomes visible.

The long line you mentioned also can be written like this:

Code: Select all

[indent=2] 

init 

  //-- define the random characters --
  myChars:array of string = {" ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} 


  //-- fill the line with a word --
  var myLine = "testline" 
  
  print ("%s" , myLine) 


  //-- this is like the long line with print statements included 

  //-- calculate the allowed random numbers --
  var thelength = myChars.length 

  //-- create a random number --
  var randomvalue = Random.int_range(0,thelength) 

  //-- get a random character -- 
  var randomcharacter = myChars[randomvalue] 

  print ("%s" , randomcharacter) 

  //-- add the character to the line --
  var alltogether = myLine.concat(randomcharacter) 

  print ("%s" , alltogether)
  
  
Notes:
I simplified the code.
Instead of:

Code: Select all

myLine:string = "testline"
you can use:

Code: Select all

var myLine = "testline"
And "GLib." can be ommited, as this library is always loaded.
So instead of:

Code: Select all

var randomvalue = GLib.Random.int_range(0,thelength)
we can use:

Code: Select all

var randomvalue = Random.int_range(0,thelength)
Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#42 Post by MU »

I am not certain, what your program shall do, maybe this is working:

Code: Select all

[indent=2]

init 
  

  myChars:array of string = {" ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"} 

  var a = 0
  while true
  
    a = Random.int_range(0,27) 
    //print("%d",a) 
    
    if myChars[a] is not "i" do
      if myChars[a] is not "n" do
        stdout.printf("%d%s ",a, myChars[a]) 

    if myChars[a] is "n" do 
      //stdout.printf("%d%s ",a, myChars[a]) 
      break
  
   stdout.printf("\n")
   stdout.flush()
       

      
It will print random characters.
It will never print "i".
It stops, when "n" is the random character (it will not be printed).

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#43 Post by Lobster »

I am not certain, what your program shall do, maybe this is working:
Mark - many thanks for you help
My program is an implementation of the
infinite monkey theorem
http://en.wikipedia.org/wiki/Infinite_monkey_theorem

It randomly creates text and then looks for specific readable text
in this case it is looking for:
in the beginning god created the heaven and earth

A quantum computer would find the whole of the Bible in an instant
What computing power we have presently takes a lot longer . . .
The infinite monkey theorem states that a monkey hitting keys at random on a typewriter keyboard for an infinite amount of time will almost surely type a given text, such as the complete works of William Shakespeare
. . . anyway gonna look at your code now . . .

Incidentally I am editing from Geany with code set as shell script and the colour coding looks OK :)
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

gege2061
Posts: 4
Joined: Sat 21 Mar 2009, 00:59
Location: France
Contact:

#44 Post by gege2061 »

MU wrote:We should inform the developer of the IDE about this thread.
I think it might be pretty motivating to see people using it :)
Mark
Yes :D I have added the support for Genie: http://valaide.blogspot.com/2009/03/genie-support.html

Your feedbacks are welcome!
MU wrote:Start the IDE again, and open your project.
Now right-click main.vala, and choose "add".
There add "main.gs".
And delete "main.vala" with a rightclick.
It still is listed, as you just renamed it, but it still is shown, as the IDE uses a internal filelist, to manage projects.
At this point, the IDE crashes.
It still is somewhat buggy :(
I have fixed this bug in trunk.

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#45 Post by MU »

fantastique, merci beaucoup :!: :D
I will compile and package it this evening, must sleep first.

Just wrote my first "real" Genie program :)
http://www.murga-linux.com/puppy/viewto ... 241#286241

We certainly will request more features in future.
I am certain, that Genie/Vala and ValaIDE will become a very important part in Puppylinux.

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#46 Post by Lobster »

must sleep first.
Maybe just this once . . . :lol:
Will be gardening today
Good news from gege2061
Looking forward to your efforts Mark :)
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#47 Post by MU »

Uploaded the new SVN version of ValaIDE.
Deleted the outdated Pets.

This is really great.
I included the syntaxfile for Genie mentioned in the blog.
This release also fixes crashes I had encountered, e.g. when opening the options dialog.

I hope I forgot no file (it uses "waf", not "make", so new2dir cannot track the installationprocess, and I must copy the files by hand).

http://dotpups.de/puppy4/dotpups/Programming/Vala/

Oh, there is a bug, when I click on "new project":

Code: Select all

** (valide:5873): DEBUG: Couldn't open this document

Code: Select all

Program received signal SIGSEGV, Segmentation fault.
0xb7d14bd4 in gtk_tree_model_get_iter () from /usr/lib/libgtk-x11-2.0.so.0
Program received signal SIGSEGV, Segmentation fault.
I also get it, when I try to use the old binary, that worked before.
Details from "gdb" - "run" - "backtrace":

0xb7d14bd4 in gtk_tree_model_get_iter () from /usr/lib/libgtk-x11-2.0.so.0

Code: Select all

(gdb) backtrace
#0  0xb7d14bd4 in gtk_tree_model_get_iter () from /usr/lib/libgtk-x11-2.0.so.0
#1  0xb7d14c39 in gtk_tree_row_reference_new_proxy ()
   from /usr/lib/libgtk-x11-2.0.so.0
#2  0xb7d14db4 in gtk_tree_row_reference_new ()
   from /usr/lib/libgtk-x11-2.0.so.0
#3  0xb7c01e62 in gtk_combo_box_set_active_internal ()
   from /usr/lib/libgtk-x11-2.0.so.0
#4  0xb7c02286 in gtk_combo_box_set_active () from /usr/lib/libgtk-x11-2.0.so.0
#5  0xb7806da9 in IA__g_object_set_property (object=0x82e0020, 
    property_name=0x82db890 "active", value=0x82ded14) at gobject.c:938
#6  0xb7d4dd00 in gtk_widget_buildable_set_buildable_property ()
   from /usr/lib/libgtk-x11-2.0.so.0
#7  0xb7be17a5 in _gtk_builder_construct () from /usr/lib/libgtk-x11-2.0.so.0
#8  0xb7be208b in builder_construct () from /usr/lib/libgtk-x11-2.0.so.0
#9  0xb7be34be in start_element () from /usr/lib/libgtk-x11-2.0.so.0
#10 0xb7ecb075 in g_markup_parse_context_parse ()
   from /usr/lib/libglib-2.0.so.0
#11 0xb7be1efb in _gtk_builder_parser_parse_buffer ()
   from /usr/lib/libgtk-x11-2.0.so.0
#12 0xb7be067c in gtk_builder_add_from_string ()
   from /usr/lib/libgtk-x11-2.0.so.0
#13 0xb7fadb73 in ?? () from /usr/lib/libvalide-0.0.so
#14 0x082819b8 in ?? ()
---Type <return> to continue, or q <return> to quit---
#15 0xb7fc9e44 in ?? () from /usr/lib/libvalide-0.0.so
#16 0x00003341 in ?? ()
#17 0xbf8e8ac0 in ?? ()
#18 0x00000000 in ?? ()
Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#48 Post by BarryK »

Genie support is now in Gtksourceview:

http://puppylinux.com/blog/?viewDetailed=00609

My Genie strings page has been expanded slightly:

http://puppylinux.com/blog/?viewDetailed=00608
[url]https://bkhome.org/news/[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#49 Post by Lobster »

Thanks Mark

Just to remind to install the gtksourcefile pet as well as the Valide one
Mark has kindly prepared
http://dotpups.de/puppy4/dotpups/Programming/Vala/

Thanks Barry for the extra string handling info
- normally I stick to string theory which I find easier . . . 8)

Mark seems very enthusiastic about genie and as an amateur programmer I like Genie a lot.

Barry is Genie living up to your expectations so far?
Last edited by Lobster on Sat 21 Mar 2009, 08:35, edited 1 time in total.
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#50 Post by MU »

ok, worked around this bug, uploaded a new version.
Changes:
svn/valide-read-only/libvalide/ui/
abstract-project-dialog.ui
abstract-project-dialog.glade
abstract-project-dialog.vala

In all 3 files I removed 1 occurence of:

Code: Select all

<property name="active">0</property>
It is in the combobox to choose one of the languages Vala or Genie.
So none of the 2 is selected by default.
No more crash.

This might be a bug in our outdated libglade, I think I had similar issues in Gtkbasic. Libglade crashes, if a combo has a defaultvalue in the *.glade file.
There also was similar in the WineColorSetter I just had written.
There I then have set it active after the *.glade was loaded.

Code: Select all

get_combobox(get_widget("combobox1")).set_active(0)
Maybe it can be solved in the IDE, by setting it active somewhere in the vala code, but I found not yet out, where I could insert that.

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#51 Post by Lobster »

Mark noticed the crashing - updated the newer version

Love the choice of language :)
and 'new project' now working

Not much more time for testing until later
A Genie IDE for Puppy - Hooray!
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#52 Post by MU »

current summary

I attach 3 screenshots, they show, how easily you now can create a new Genie project :D

Download the required files here:
http://dotpups.de/puppy4/dotpups/Programming/Vala/

gtksourceview-2.0.2-i486.pet
vala-0.5.7.pet
valide-0.4-1-i686-svn-2009-03-27.pet


Puppy may already have vala-0.5.7 or gtksourceview, so you just need to install them, if the IDE does not start without them.

You can find example code in the former messages of this thread.

My first program can be downloaded here:
http://www.murga-linux.com/puppy/viewtopic.php?t=40193
It has a window created with the grafical designer "Glade", and may be a good start, to create own programs using libglade.

A good introduction is Barrys page:
http://puppylinux.com/genie/

He references this page of the Genie developer, that gives further insight:
http://live.gnome.org/Genie

Both pages are important to read, as they deal with different topics.

A further "must" is:
http://valadoc.org/?
It is the "reference" showing you all commands you can use by using the supported libraries.

Especially Glib is important.
For example the string functions in Genie are the GLib functions:
http://valadoc.org/?pkg=glib-2.0&element=string
A bit difficult to find when you are new, but very essential!

Mark
Attachments
g1.jpg
(65.08 KiB) Downloaded 946 times
g2.jpg
(34.28 KiB) Downloaded 2108 times
g3.jpg
(63.19 KiB) Downloaded 829 times
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#53 Post by Lobster »

Thanks Mark

Val(a)IDE is written in Vala - that's good
Nicolas Joseph has done good :)

Many years ago I helped in the development of an IDE
for the Curl programming language (still largely proprietary)
http://www.curl.com/products/ide/
One of the neat features was an integrated
online central repository and local repository synchronizing of code
that does not seem there at the official site . . .

Even those on dial up could go on line and upload and download and lock/unlock code they were working on at their local machine

Obviously programmers would only have on their local machines code they were interested in.

Might be a useful - might not be a priority/possibility.
However at this early stage, would be a good time . . .

Another great feature was compiling sample code that was in Help
8)
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#54 Post by BarryK »

Lobster wrote:Barry is Genie living up to your expectations so far?
Yes. The main problem has been lack of beginner's documentation. There is documentation out there, but very terse, really written for people who already know how to code in Vala/Genie.

For sometime I have just been blundering along, but yesterday when I wrote a program in Genie to replace a slow Bash script, I suddenly realised that I had crossed a threshold and was happily coding in Genie.

Genie really is inherently easy to code in. It is a matter of adequate introductory documentation. Some of my documentation needs more work, much more work ...and I do intend to keep working on it.
[url]https://bkhome.org/news/[/url]

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#55 Post by big_bass »

BarryK
Yes. The main problem has been lack of beginner's documentation. There is documentation out there, but very terse, really written for people who already know how to code in Vala/Genie.

For sometime I have just been blundering along, but yesterday when I wrote a program in Genie to replace a slow Bash script, I suddenly realised that I had crossed a threshold and was happily coding in Genie.

Genie really is inherently easy to code in
Yes, most developers are quick to impress with complex
coding I guess for status so other programmers take them seriously

forgetting that the real power of any language really just takes advantage of some simple commands with real world practical examples

I suggest any "puppy programs" that use vala are very heavily commented so that even if one does not desire to take up the profession as a programmer they would still be able though to make minor modifications and help also to edit code (just on a much smaller scale)

speaking for myself I can figure out code if I know what the program does and something isn't working correctly in one small part
it takes me awhile to jump in and make any changes
this is where comments are more valuable than gold because
of the time needed to figure out what should happen

most man pages really stink
they give options NOT examples
thus hindering the advancement and usability
but that is still better than no documentation at all


I welcome any new small apps for puppy

please be kind and use many comments and some easy examples for the non gurus too (they would like to learn too)

thanks MU for the examples
thanks BarryK for taking a swing at it with vala
we all will learn from it



big_bass

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#56 Post by Lobster »

Guys

Run Valide from Puppy 4.12 for now

I was using 4.2 rc4 and had renamed the devxx from dev4.12 to dev420
(you need the gcc compiler) and was running into problems. :oops:

Things seem better now - will report back how I get on.
Maybe even some working code samples (that is the plan) :)

A good place to start is with Geany (the editor) to edit
and Barrys excellent help pages.

Barry will be providing Valide in Woof alpha3 (available soon)
The sooner you get involved, the sooner I can learn something useful
- yep my motives are completely mercenary . . . 8)

Big Bass and others please provide any sample code and new discoveries (do not be embarrassed)

We are at programming cutting edge.
How exciting!
Let's stay sharp.
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
BarryK
Puppy Master
Posts: 9392
Joined: Mon 09 May 2005, 09:23
Location: Perth, Western Australia
Contact:

#57 Post by BarryK »

Any editor that uses Gtksourceview has has color syntax highlighting for both Vala and Genie.

That includes TEA, Medit and Gedit.

For Puppy4 uses, MU has posted packages to go with my Gedit package, that works in Newyearspup, probably should work in 4.1.2 and 4.2:

http://puppylinux.com/blog/?viewDetailed=00619

My TEA pet package was compiled in 4.1.2 so will definitely work in it. But see my blog posts about annoyances with TEA.
[url]https://bkhome.org/news/[/url]

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#58 Post by Lobster »

Hi guys here is the imt sample code :)
(Shadow did all the work - I made tea)

once run and compiled
run from the command line
like so

imt "in"
where "in" is the text you want your monkeys to try and type
Please be aware that adding a piece of text like 'in the beg"
may mean the IMT program may have to run for days . . .

Code: Select all

// Infinite Monkey Theorem
// Lobster and Shadow, March 2009 LGPL

// use from command line 
// imt ["search text"]
// generates random characters and searches for a given pattern eg 'in the beginning was the world'
// warning strings longer than "in the" may take minutes or hours to find

// program demonstrates: 
//   basic functions
//   passing parameters in command line
//   random character generation
//   constant

def getRandomNumber(RangeFrom:int, RangeTo:int) : int  /* function to create random number between range */
	return GLib.Random.int_range(RangeFrom,RangeTo)

def getRandomChar() : char                             /* function to generate ascii codes from a-z and space (32) */
	num:int = getRandomNumber(0,27)
	if num == 0
		num = 32
	else num = num + 96
	return (char) num

def addRandomChar(myText:string) : string              /* function add text from command line */
	var retText = new StringBuilder
	retText.append(myText)
	retText.append_c(getRandomChar())
	return retText.str
		
init
	USAGE:string = "Usage:\n\t ./imt \"some text for monkeys to generate\" "
	theText:string = args[1]
	if theText == null
		theText = ""
	theText = theText.down()                            /* change any text input to lower case */   
	myText:string = ""

	if theText != "" 
		do	
			do
				myText = addRandomChar(myText)
			while theText.len() != myText.len()
        		print(myText)
			if theText != myText
				stdout.printf("\n")
				myText = ""
		while theText != myText
		stdout.printf("\n")

	else print(USAGE)                                   /* this appears if program run without text */
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#59 Post by big_bass »

Hey Lobster
The infinite monkey theorem states that a monkey hitting keys at random on a typewriter keyboard for an infinite amount of time will almost surely type a given text, such as the complete works of William Shakespeare
ah ha!! now there is a name for what I've been trying to do for the last couple days tying to build a new iso

mmm uh ... maybe I should go about this the old fashioned way
take a break from the computer and ..........
yes ! tomorrow I'll go out and buy a monkey!!

well, on second thought I'm sure the monkey will figure it out before I do but that still won't help me if he can't explain how he did it :lol:

so here I go again with another try :D

big_bass

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#60 Post by Lobster »

Anybody tried adding time?
Is this the right place to look?

http://valadoc.org/?pkg=glib-2.0&element=GLib.Time

. . . is something like this right?

Code: Select all

def startTimer() : int                                   /* function to create timer */ 
	return GLib.Time.local()

init
	print startTimer()
Is Genie multi-threaded?
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

Post Reply