Re: [Vala] Genie and extra '\n' in some strings
> Since Genie imitates Python perhaps it does it because Python does it in > most cases. See this page: > http://docs.python.org/reference/simple_stmts.html#print Yes, you're right, Steven. I replaced the 'print' expression with 'stdout.printf' and now C programs are identical. So, it looks like, that the 'print' is treated differently by Genie, more Python-like. ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Genie and extra '\n' in some strings
Since Genie imitates Python perhaps it does it because Python does it in most cases. See this page: http://docs.python.org/reference/simple_stmts.html#print Steven N. Oliver On Fri, Jan 6, 2012 at 8:30 AM, Piotr Borkowski wrote: > Thank you for your reply, Abderrahim. > > > As you can see, in both cases the newline is added to a print'ed string, > > so I guess it is intentional. > > I think this is intentional, but I do not understand why it has been > applied. This seems unnecessary. > > After compiling the functional equivalent of that program in Vala, > such additions do not occur. > > Programs in C are the same except those strange extras in Genie version. > > > // hello.vala > public static void main (string[] args) > { > var caption = "Hello World!\n"; > var hello = new HelloWorld (); > var message = hello.say (caption); > print ("Message: %s\n", message); > } > > class HelloWorld : Object > { > public string say (string greeting) > { > print (greeting); > return "OK"; > } > } > > > // hello.c - vala version > > ... > > void _vala_main (gchar** args, int args_length1) { > gchar* _tmp0_; > gchar* caption; > HelloWorld* _tmp1_; > HelloWorld* hello; > gchar* _tmp2_ = NULL; > gchar* message; > _tmp0_ = g_strdup ("Hello World!\n"); > caption = _tmp0_; > _tmp1_ = hello_world_new (); > hello = _tmp1_; > _tmp2_ = hello_world_say (hello, caption); > message = _tmp2_; >g_print ("Message: %s\n", message); >_g_free0 (message); > _g_object_unref0 (hello); > _g_free0 (caption); > } > > ... > > gchar* hello_world_say (HelloWorld* self, const gchar* greeting) { > gchar* result = NULL; > const gchar* _tmp0_; > gchar* _tmp1_; >g_return_val_if_fail (self != NULL, NULL); > g_return_val_if_fail (greeting != NULL, NULL); > _tmp0_ = greeting; >g_print ("%s", _tmp0_); > _tmp1_ = g_strdup ("OK"); > result = _tmp1_; > return result; > } > > ... > ___ > vala-list mailing list > vala-list@gnome.org > http://mail.gnome.org/mailman/listinfo/vala-list > ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Genie and extra '\n' in some strings
Thank you for your reply, Abderrahim. > As you can see, in both cases the newline is added to a print'ed string, > so I guess it is intentional. I think this is intentional, but I do not understand why it has been applied. This seems unnecessary. After compiling the functional equivalent of that program in Vala, such additions do not occur. Programs in C are the same except those strange extras in Genie version. // hello.vala public static void main (string[] args) { var caption = "Hello World!\n"; var hello = new HelloWorld (); var message = hello.say (caption); print ("Message: %s\n", message); } class HelloWorld : Object { public string say (string greeting) { print (greeting); return "OK"; } } // hello.c - vala version ... void _vala_main (gchar** args, int args_length1) { gchar* _tmp0_; gchar* caption; HelloWorld* _tmp1_; HelloWorld* hello; gchar* _tmp2_ = NULL; gchar* message; _tmp0_ = g_strdup ("Hello World!\n"); caption = _tmp0_; _tmp1_ = hello_world_new (); hello = _tmp1_; _tmp2_ = hello_world_say (hello, caption); message = _tmp2_; g_print ("Message: %s\n", message); _g_free0 (message); _g_object_unref0 (hello); _g_free0 (caption); } ... gchar* hello_world_say (HelloWorld* self, const gchar* greeting) { gchar* result = NULL; const gchar* _tmp0_; gchar* _tmp1_; g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (greeting != NULL, NULL); _tmp0_ = greeting; g_print ("%s", _tmp0_); _tmp1_ = g_strdup ("OK"); result = _tmp1_; return result; } ... ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
Re: [Vala] Genie and extra '\n' in some strings
Hello, في خ، 05-01-2012 عند 18:54 +0100 ، كتب Piotr Borkowski: > Hi. I was playing around with Vala and Genie and I noticed that in the > case of Genie, the compiler adds an extra '\ n' sequence at the end of > some strings. Is that supposed to be? As you can see, in both cases the newline is added to a print'ed string, so I guess it is intentional. btw, print in genie is a statement (like in python 2), see http://live.gnome.org/Genie HTH, Abderrahim ___ vala-list mailing list vala-list@gnome.org http://mail.gnome.org/mailman/listinfo/vala-list
[Vala] Genie and extra '\n' in some strings
Hi. I was playing around with Vala and Genie and I noticed that in the case of Genie, the compiler adds an extra '\ n' sequence at the end of some strings. Is that supposed to be? Test program in Genie // hello.gs init var caption = "Hello World!\n" var hello = new HelloWorld () var message = hello.say (caption) print ("Message: %s\n", message) class HelloWorld : Object def say (greeting : string) : string print (greeting) return "OK" Some fragments of a program in C // hello.c ... void _vala_main (gchar** args, int args_length1) { gchar* _tmp0_; gchar* caption; HelloWorld* _tmp1_; HelloWorld* hello; gchar* _tmp2_ = NULL; gchar* message; _tmp0_ = g_strdup ("Hello World!\n"); caption = _tmp0_; _tmp1_ = hello_world_new (); hello = _tmp1_; _tmp2_ = hello_world_say (hello, caption); message = _tmp2_; g_print ("Message: %s\n\n", message); // <-- an extra '\n' here _g_free0 (message); _g_object_unref0 (hello); _g_free0 (caption); } ... gchar* hello_world_say (HelloWorld* self, const gchar* greeting) { gchar* result = NULL; const gchar* _tmp0_; gchar* _tmp1_; gchar* _tmp2_; gchar* _tmp3_; g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (greeting != NULL, NULL); _tmp0_ = greeting; _tmp1_ = g_strconcat (_tmp0_, "\n", NULL); // <-- an extra '\n' here _tmp2_ = _tmp1_; g_print ("%s", _tmp2_); _g_free0 (_tmp2_); _tmp3_ = g_strdup ("OK"); result = _tmp3_; return result; } ... /* hello.c generated by valac 0.14.0, the Vala compiler * generated from hello.gs, do not modify */ #include #include #include #include #define TYPE_HELLO_WORLD (hello_world_get_type ()) #define HELLO_WORLD(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_HELLO_WORLD, HelloWorld)) #define HELLO_WORLD_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_HELLO_WORLD, HelloWorldClass)) #define IS_HELLO_WORLD(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_HELLO_WORLD)) #define IS_HELLO_WORLD_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_HELLO_WORLD)) #define HELLO_WORLD_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_HELLO_WORLD, HelloWorldClass)) typedef struct _HelloWorld HelloWorld; typedef struct _HelloWorldClass HelloWorldClass; #define _g_free0(var) (var = (g_free (var), NULL)) #define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL))) typedef struct _HelloWorldPrivate HelloWorldPrivate; struct _HelloWorld { GObject parent_instance; HelloWorldPrivate * priv; }; struct _HelloWorldClass { GObjectClass parent_class; }; static gpointer hello_world_parent_class = NULL; void _vala_main (gchar** args, int args_length1); HelloWorld* hello_world_new (void); HelloWorld* hello_world_construct (GType object_type); GType hello_world_get_type (void) G_GNUC_CONST; gchar* hello_world_say (HelloWorld* self, const gchar* greeting); enum { HELLO_WORLD_DUMMY_PROPERTY }; void _vala_main (gchar** args, int args_length1) { gchar* _tmp0_; gchar* caption; HelloWorld* _tmp1_; HelloWorld* hello; gchar* _tmp2_ = NULL; gchar* message; _tmp0_ = g_strdup ("Hello World!\n"); caption = _tmp0_; _tmp1_ = hello_world_new (); hello = _tmp1_; _tmp2_ = hello_world_say (hello, caption); message = _tmp2_; g_print ("Message: %s\n\n", message); _g_free0 (message); _g_object_unref0 (hello); _g_free0 (caption); } int main (int argc, char ** argv) { g_type_init (); _vala_main (argv, argc); return 0; } gchar* hello_world_say (HelloWorld* self, const gchar* greeting) { gchar* result = NULL; const gchar* _tmp0_; gchar* _tmp1_; gchar* _tmp2_; gchar* _tmp3_; g_return_val_if_fail (self != NULL, NULL); g_return_val_if_fail (greeting != NULL, NULL); _tmp0_ = greeting; _tmp1_ = g_strconcat (_tmp0_, "\n", NULL); _tmp2_ = _tmp1_; g_print ("%s", _tmp2_); _g_free0 (_tmp2_); _tmp3_ = g_strdup ("OK"); result = _tmp3_; return result; } HelloWorld* hello_world_construct (GType object_type) { HelloWorld * self = NULL; self = (HelloWorld*) g_object_new (object_type, NULL); return self; } HelloWorld* hello_world_new (void) { return hello_world_construct (TYPE_HELLO_WORLD); } static void hello_world_class_init (HelloWorldClass * klass) { hello_world_parent_class = g_type_class_peek_parent (klass); } static void hello_world_instance_init (HelloWorld * self) { } GType hello_world_get_type (void) { static volatile gsize hello_world_type_id__volatile = 0; if (g_once_init_enter (&hello_world_type_id__volatile)) { static const GTypeInfo g_define_type_info = { sizeof (HelloWorldClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) hello_world_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (HelloWorld), 0, (GInstanceInitFunc) hello_world_instance_init, NULL }; GType he