Computer Science Canada

Put and get on the same line...

Author:  aldreneo [ Tue May 02, 2006 6:45 pm ]
Post subject:  Put and get on the same line...

How can I make it do this
code:

var age:string
put "How old are you" + get age

So that they are outputted on the same line?

Author:  Cervantes [ Tue May 02, 2006 6:51 pm ]
Post subject: 

Judging by the title, I got excited and thought someone was asking how to use "get" as a function, rather than a cruddy keyword, so you can do things like
code:
put get

or
code:
name = get


Well, to answer your question, you need to add a .. after the put line:
code:
var age : string
put "How old are you? " ..
get age

Author:  TokenHerbz [ Tue May 02, 2006 6:58 pm ]
Post subject: 

aha, unless me means to use the put and get on the same line in the CODE

which i dont do but...

code:

put "Get text: " .. get text

Author:  TokenHerbz [ Tue May 02, 2006 7:03 pm ]
Post subject: 

you can make lines of code on a line, but i dont reccomend doing this at all, because its sloppy, and confusing:

Bad way:
code:

var text: string put "Get text: " .. get text put text

Better way:
code:

var text: string

put "get text:" ..    %%these two ..'s allow the line to be joined by other things
get text

put text


ex: of joining output to make it one line on screen, like cervantes said..

code:

put "Part 1 " ..
put "Part 2 " ..
put "Part 3"

Author:  Clayton [ Tue May 02, 2006 8:43 pm ]
Post subject: 

out of curiosity Cervantes, what do you mean using get as a function, i didnt think that was possible....

Author:  do_pete [ Tue May 02, 2006 8:56 pm ]
Post subject: 

It's not possible.

Author:  [Gandalf] [ Tue May 02, 2006 9:09 pm ]
Post subject: 

do_pete wrote:
It's not possible.

Why not?
code:
fcn get_s : string
    var str : string
    get str :*
    result str
end get_s

put get_s

Author:  Clayton [ Tue May 02, 2006 9:33 pm ]
Post subject: 

but why would you do that, i mean, what is the purpose of such a fcn?

Author:  do_pete [ Tue May 02, 2006 9:45 pm ]
Post subject: 

[Gandalf] wrote:
do_pete wrote:
It's not possible.

Why not?
code:
fcn get_s : string
    var str : string
    get str :*
    result str
end get_s

put get_s
No, I meant get can't be used like this:
code:
a := get

Author:  [Gandalf] [ Tue May 02, 2006 10:37 pm ]
Post subject: 

do_pete wrote:
No, I meant get can't be used like this:
code:
a := get

code:
fcn get_s : string
    var str : string
    get str :*
    result str
end get_s

var a : string
a := get_s

Confused

Author:  do_pete [ Tue May 02, 2006 10:42 pm ]
Post subject: 

No I mean the get you use in this:
code:
get a
cannot be used like this:
code:
a := get

Author:  [Gandalf] [ Tue May 02, 2006 10:48 pm ]
Post subject: 

Ah, I see. Well, yeah, that's because get is created that way internally. That doesn't stop you from simulating a get() function, as I believe Cervantes was trying to say.

Author:  upthescale [ Wed May 03, 2006 5:11 pm ]
Post subject: 

locate is an option to...


put"What is your name?"

locate(1,20)
get name

Author:  do_pete [ Wed May 03, 2006 5:26 pm ]
Post subject: 

Or you could just do it Cervantes' way since it's much easier.

Author:  Cervantes [ Sat May 06, 2006 1:03 pm ]
Post subject: 

Gandalf's got it. That's what I was geting at

do_pete, you're not seeing the power of using a gets type call as a function.

Say I was doing Martin's Roman_Numeral challege. I made a function to determine if a given string is a valid roman numeral.
code:

function is_valid_roman_numeral (s : string) : boolean
    % Compute!
end is_valid_roman_numeral

Now, how would I call it? Using get as a keyword, I have no choice but to use a temporary variable that really doesn't serve any purpose whatsoever:
code:

var temp : string
get temp
put is_valid_roman_numeral (temp)

However, if I use a get as a function (like Gandalf has done), then I don't have to create a useless variable, and I can shrink the program call to one line:
code:

put is_valid_roman_numeral (get)

Much nicer, yes?

Author:  NikG [ Sun May 07, 2006 8:53 pm ]
Post subject: 

[Gandalf] wrote:
code:
fcn get_s : string
    var str : string
    get str :*
    result str
end get_s

var a : string
a := get_s

Cervantes wrote:
However, if I use a get as a function (like Gandalf has done), then I don't have to create a useless variable, and I can shrink the program call to one line:
code:
put is_valid_roman_numeral (get)

How exactly are you avoiding creating a "useless" variable? Gandalf's function still has to create a temp var (str) to get the input.

Author:  [Gandalf] [ Sun May 07, 2006 9:37 pm ]
Post subject: 

Yes, which is a limitation of you creating the function in a language which doesn't allow for it beforehand.

The difference is that you are not creating the variable in your actual code, but inside the scope of the function. It allows for more flexible and simple code than if you had used the get keyword as is demonstrated by code such as:
code:
put is_valid_roman_numeral (get)


: