lf_araujo
lf_araujo

Reputation: 2063

The equivalent of raw_input() in Genie/vala?

I am trying to create a simple Hello World program using Genie, but I wanted to be able to enter some input on the terminal. My objective is to repeat the following python code in Genie:

#!/usr/bin/env python
print 'Hello. I am a python program.'
name = raw_input("What is your name? ")
print "Hello there, " + name + "!"

So far what I did is;

[indent=4]

uses System

init
    print "Hello. I am a python program."
    var name = Console.ReadLine("What is your name? ")
    print "Hello there, " + name + "!"

But I get some errors, probably because I have no idea about the language, here is the error:

hw.gs:4.5-4.10: error: The namespace name `System' could not be found
    System
    ^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
hw.gs:3.6-3.11: error: The namespace name `System' could not be found
uses System
     ^^^^^^
Compilation failed: 1 error(s), 0 warning(s)

What am I doing wrong?

Thanks.

Upvotes: 3

Views: 117

Answers (2)

Jens Mühlenhoff
Jens Mühlenhoff

Reputation: 14873

You can write your own raw_input function if you like:

[indent=4]

def raw_input (query : string? = null) : string?
    if (query != null)
        stdout.printf ("%s\n", query)
    return stdin.read_line ()

init
    print "Hello. I am a python program."
    var name = raw_input ("What's your name?")
    print "Hello there, " + name + "!"

Upvotes: 2

lf_araujo
lf_araujo

Reputation: 2063

BigOldTree helped me with a suggestion, that actually worked out. Here is how the code looks like in Geanie:

[indent=4]
init
    print "Hello. I am a python program."
    print "What's your name?"
    var name = stdin.read_line()
    print "Hello there, " + name + "!"

I don't know whether it is possible to send arguments to stdin.read_line() like one can with raw_input() in python. It would be nice to know that, also I don't know how to find information about specific functions and how to import them. I come from R and there I can use ?function(), which would give me a little instruction about it. Is there anything similar on Genie/Vala?

Upvotes: 2

Related Questions