Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 01 Aug 2014, 00:10
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Vala and Genie programming
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 35 [517 Posts]   Goto page: 1, 2, 3, ..., 33, 34, 35 Next
Author Message
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Thu 12 Mar 2009, 08:41    Post subject:  Vala and Genie programming  

In my desperate and futile attempts to program
I have been exploring the vala/genie programming language
used in Woof

http://live.gnome.org/Genie

I have been able to compile some of Barrys examples
http://puppylinux.com/genie/

now this:

Code:
init
   a:array of string = {"abc", "def", "xyz"}
   for s in a
      print(s)


gives me

Quote:
# valac v5.gs
v5.c: In function '_main':
v5.c:34: error: stray '\' in program
v5.c:34:40: warning: missing terminating " character
v5.c:34: error: missing terminating " character
v5.c:34: error: 'n' undeclared (first use in this function)
v5.c:34: error: (Each undeclared identifier is reported only once
v5.c:34: error: for each function it appears in.)
v5.c:35: error: expected ')' before '_tmp2'
v5.c:37: error: expected ')' before '}' token
v5.c:37: error: expected ';' before '}' token
error: cc exited with status 256
Compilation failed: 1 error(s), 0 warning(s)
#


which is more errors then I can cope with . . . Confused
I am pretty sure it is something to do with the tab
ending the program (python does this too)
but can not solve it.

HELP!

_________________
Puppy WIKI

Last edited by Lobster on Mon 16 Mar 2009, 07:39; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Thu 12 Mar 2009, 11:28    Post subject:  

be sure to use tabs, not spaces in the beginning of the lines.

I just copied your example via copy&paste in Opera to leafpad, and it compiles fine here (newyearspup02 with devx).


Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Thu 12 Mar 2009, 11:31    Post subject:  

you also may compile:
valac -C v5.gs

This just creates v5.c and v5.h.
Pleae copy&paste them here.

Maybe the difference to mine show, what goes wrong for you.

Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Thu 12 Mar 2009, 11:34    Post subject:  

Shocked

tried in leafpad
will have another go
- it is the space thing - yes
I am using 4.2 rc2
and a 64 bit processor
(and I am stupid)

v5.c

Code:
#include "v5.h"




static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);



void _main (char** args, int args_length1) {
   char** _tmp1;
   gint a_size;
   gint a_length1;
   char** _tmp0;
   char** a;
   _tmp1 = NULL;
   _tmp0 = NULL;
   a = (_tmp1 = (_tmp0 = g_new0 (char*, 3 + 1), _tmp0[0] = g_strdup ("abc"), _tmp0[1] = g_strdup ("def"), _tmp0[2] = g_strdup ("xyz"), _tmp0), a_length1 = 3, a_size = a_length1, _tmp1);
   {
      char** s_collection;
      int s_collection_length1;
      int s_it;
      s_collection = a;
      s_collection_length1 = a_length1;
      for (s_it = 0; s_it < a_length1; s_it = s_it + 1) {
         const char* _tmp3;
         char* s;
         _tmp3 = NULL;
         s = (_tmp3 = s_collection[s_it], (_tmp3 == NULL) ? NULL : g_strdup (_tmp3));
         {
            char* _tmp2;
            _tmp2 = NULL;
            g_print (_tmp2 = g_strconcat (s, \n", NULL));
            _tmp2 = (g_free (_tmp2), NULL);
            s = (g_free (s), NULL);
         }
      }
   }
   a = (_vala_array_free (a, a_length1, (GDestroyNotify) g_free), NULL);
}


int main (int argc, char ** argv) {
   g_type_init ();
   _main (argv, argc);
   return 0;
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
   if ((array != NULL) && (destroy_func != NULL)) {
      int i;
      for (i = 0; i < array_length; i = i + 1) {
         if (((gpointer*) array)[i] != NULL) {
            destroy_func (((gpointer*) array)[i]);
         }
      }
   }
   g_free (array);
}


and v5.h

Code:
#ifndef __V5_H__
#define __V5_H__

#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>

G_BEGIN_DECLS



void _main (char** args, int args_length1);


G_END_DECLS

#endif



Thanks Mark Smile

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
MUguest

Joined: 09 Dec 2006
Posts: 73

PostPosted: Fri 13 Mar 2009, 05:53    Post subject:  

Lob,

I get the same error trying to compile it in WinowsXP, using 0.5.7.

At home in Puppy I had used 0.5.1:
http://distro.ibiblio.org/pub/linux/distributions/puppylinux/pet_packages-4/vala-0.5.1-i486.pet

The problem is the generated C code, line 34:


Code:
            g_print (_tmp2 = g_strconcat (s, \n", NULL));
should be:

Code:
            g_print (_tmp2 = g_strconcat (s, "\n", NULL));

So there missed a quotation mark.

Maybe with 0.5.1 you will have success.
Mark
Back to top
View user's profile Send private message 
MUguest

Joined: 09 Dec 2006
Posts: 73

PostPosted: Fri 13 Mar 2009, 06:12    Post subject:  

yes, with 0.5.1 the example compiles fine also in WinXP.
In 0.5.6 it does not.
So this is a bug in newer versions, or the syntax for the "for" loop changed.
Mark
Back to top
View user's profile Send private message 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Fri 13 Mar 2009, 06:46    Post subject:  

Quote:
yes, with 0.5.1 the example compiles



Yep works for me too in 0.5.1
Thanks Mark Smile
Now to program my own masterpiece . . .
Embarassed

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Fri 13 Mar 2009, 07:08    Post subject:  

Confused stuck again

been looking for a list of reserved words
in particular functions . . .

Am trying to find and use a rnd or random function.
Any clues?

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
MUguest

Joined: 09 Dec 2006
Posts: 73

PostPosted: Fri 13 Mar 2009, 09:29    Post subject:  

You can use the random method from GLib.
http://valadoc.org/?pkg=glib-2.0&element=GLib.Random


Example:
Code:
init

   // return a random value from 1 to 9
   a:int
   a = GLib.Random.int_range(1,10)
   print("%d" , a)
   




------------------------------------------
references

http://valadoc.org/?

http://www.vala-project.org/doc/vala/
http://live.gnome.org/Vala
http://live.gnome.org/Vala/Tutorial
http://library.gnome.org/devel/glib/

Mark
Back to top
View user's profile Send private message 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Sat 14 Mar 2009, 05:18    Post subject:  

I attach a pet made from the Archlinux package of the vala-IDE.
http://www.valaide.org/doku.php

It requires Gtksourceview:
http://dotpups.de/puppy3/dotpups/Libraries/Gnome-2.19.2-libs/other-Libs/gtksourceview-2.0.2-i486.pet

I did not try, if it works in Puppy.
I tested it in NYP 02rc7, that has updated Gtk libraries (based on Ultrapup).

The homepage says, it requires vala 0.5.7, but it seems to work fine with 0.5.1.

Mark
valide-0.4-1-i686.pet
Description 
pet

 Download 
Filename  valide-0.4-1-i686.pet 
Filesize  824.58 KB 
Downloaded  1871 Time(s) 
valide1.jpg
 Description   
 Filesize   66.07 KB
 Viewed   8852 Time(s)

valide1.jpg

valide.jpg
 Description   
 Filesize   44.08 KB
 Viewed   8766 Time(s)

valide.jpg


_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Sat 14 Mar 2009, 05:49    Post subject:  

I could not get the random code to work - will try again later
Hey thanks for the IDE Smile that looks useful . . .
only . . .
this is what I got in Deep Thought 4.20 rc3
Code:
# ./valide
./valide: error while loading shared libraries: libgio-2.0.so.0: cannot open shared object file: No such file or directory
#

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
muggins

Joined: 20 Jan 2006
Posts: 6674
Location: lisbon

PostPosted: Sat 14 Mar 2009, 17:39    Post subject:  

libgio-2.0.so.0.pet
libselinux.so.1.pet
Back to top
View user's profile Send private message 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Sat 14 Mar 2009, 23:54    Post subject:  

thanks Muggins Smile
now in rc3 of 4.2
added those pets and now getting . . .

Code:
# ./valide
./valide: symbol lookup error: /usr/lib/libvalide-0.0.so: undefined symbol: g_dgettext
#

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Sun 15 Mar 2009, 13:26    Post subject:  

Hey Mark,

Thanks for the random prog - got that working ok Smile

I am using it to train an infinite number of monkeys on virtual typewriters to write this (to start with)

Code:
while myLine != "in the"   


Soon (a few billion years) they will type out the Bible and the Complete Works of Shakespeare

. . . what am I missing?

Code:
// Infinite Monkey Theorem, Lobster and Shadow, March 2009
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"}
   myLine:string = ""
   myCount:int = 6
   while myLine != "in the"
      for i:int = 1 to myCount
         myLine = myLine.concat(myChars[GLib.Random.int_range(0,myChars.length)])
      print(myLine)


rather than using a string array - is there not some sort of more efficient string pointer?

_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
MU


Joined: 24 Aug 2005
Posts: 13642
Location: Karlsruhe, Germany

PostPosted: Sun 15 Mar 2009, 18:05    Post subject:  

Lobster, sorry no answer, but a request:
please do not edit your messages to add new content.
I just saw your monkey example by accident, when I looked up something in this thread.
That also had happened before, so that I replied very late.

The best is to add a new message, so that I can see it in my "View posts since last visit".

Mark

_________________
my recommended links
Back to top
View user's profile Send private message Visit poster's website 
Display posts from previous:   Sort by:   
Page 1 of 35 [517 Posts]   Goto page: 1, 2, 3, ..., 33, 34, 35 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1039s ][ Queries: 13 (0.0110s) ][ GZIP on ]